import { describe, it, expect, vi, beforeEach } from 'vitest' const execFileMock = vi.fn( ( _cmd: string, _args: string[], _opts: unknown, cb?: (err: Error | null, result: unknown) => void ) => { const callback = typeof _opts === 'function' ? (_opts as typeof cb) : cb callback?.(null, { stdout: '{}', stderr: '' }) } ) vi.mock('child_process', () => ({ execFile: execFileMock })) const { systemStatus } = await import('../../src/main/skills/windows/systemStatus') const { systemStorage } = await import('../../src/main/skills/windows/systemStorage') const { checkInternet } = await import('../../src/main/skills/windows/checkInternet') function mockStdout(json: unknown): void { execFileMock.mockImplementation( ( _cmd: string, _args: string[], optsOrCb: unknown, cb?: (err: Error | null, result: unknown) => void ) => { const callback = typeof optsOrCb === 'function' ? (optsOrCb as typeof cb) : cb callback?.(null, { stdout: JSON.stringify(json), stderr: '' }) } ) } beforeEach(() => { vi.clearAllMocks() }) describe('check_battery_and_cpu', () => { it('should report no battery for a desktop computer', async () => { mockStdout({ BatteryPercent: null, Charging: null, CpuPercent: 42 }) const result = await systemStatus.execute({}) expect(result).toMatch(/Pas de batterie detectee/) expect(result).toMatch(/42%/) }) it('should report battery level and charging state for a laptop', async () => { mockStdout({ BatteryPercent: 80, Charging: true, CpuPercent: 10 }) const result = await systemStatus.execute({}) expect(result).toMatch(/Batterie a 80%/) expect(result).toMatch(/en charge/) }) }) describe('check_storage', () => { it('should report usage for a single drive', async () => { mockStdout({ DriveLetter: 'C', SizeGB: 500, FreeGB: 100 }) const result = await systemStorage.execute({}) expect(result).toMatch(/Disque C : 400\.0 Go utilises sur 500 Go \(100 Go libres\)/) }) it('should report usage for multiple drives', async () => { mockStdout([ { DriveLetter: 'C', SizeGB: 500, FreeGB: 100 }, { DriveLetter: 'D', SizeGB: 1000, FreeGB: 900 } ]) const result = await systemStorage.execute({}) expect(result).toMatch(/Disque C/) expect(result).toMatch(/Disque D/) }) }) describe('check_internet_connection', () => { it('should report a working connection with its local IP', async () => { mockStdout({ Connected: true, Ip: '192.168.1.10' }) const result = await checkInternet.execute({}) expect(result).toMatch(/Internet fonctionne/) expect(result).toMatch(/192\.168\.1\.10/) }) it('should report no connection', async () => { mockStdout({ Connected: false, Ip: null }) const result = await checkInternet.execute({}) expect(result).toMatch(/Pas de connexion internet/) }) })