CI / quality (push) Failing after 6m22s
Implements Max_Code_Quality_CICD_Production.md: TypeScript strict mode, ESLint flat config with type-checking and security plugin, Prettier, Husky + lint-staged, Vitest with 80%+ coverage (473 tests), Playwright e2e, Electron security hardening (contextIsolation, CSP, IPC validation), electron-builder + electron-updater, Dockerfile, Gitea Actions CI/release workflows, and SonarQube docker-compose setup. Also fixes two real bugs found while writing tests: unawaited clipboard promises and a mermaid container ref timing issue in CoachDrawingView. Fixes lint-staged on Windows/Node 24 by invoking eslint/prettier via `node <bin>.js` instead of their .cmd shims, which Node's child_process now refuses to spawn without shell:true. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
88 lines
2.7 KiB
TypeScript
88 lines
2.7 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { EventEmitter } from 'node:events'
|
|
|
|
vi.mock('@electron-toolkit/utils', () => ({ is: { dev: false } }))
|
|
|
|
class FakeWebContents extends EventEmitter {
|
|
send = vi.fn()
|
|
isLoading = vi.fn(() => false)
|
|
}
|
|
|
|
class FakeBrowserWindow extends EventEmitter {
|
|
webContents = new FakeWebContents()
|
|
show = vi.fn()
|
|
moveTop = vi.fn()
|
|
focus = vi.fn()
|
|
setAlwaysOnTop = vi.fn()
|
|
maximize = vi.fn()
|
|
loadURL = vi.fn()
|
|
loadFile = vi.fn()
|
|
destroyed = false
|
|
isDestroyed(): boolean {
|
|
return this.destroyed
|
|
}
|
|
}
|
|
|
|
let lastWindow: FakeBrowserWindow | null = null
|
|
let nextWindowStartsLoading = false
|
|
function createBrowserWindow(): FakeBrowserWindow {
|
|
const window = new FakeBrowserWindow()
|
|
if (nextWindowStartsLoading) {
|
|
window.webContents.isLoading.mockReturnValue(true)
|
|
nextWindowStartsLoading = false
|
|
}
|
|
lastWindow = window
|
|
return window
|
|
}
|
|
|
|
vi.mock('electron', () => ({ BrowserWindow: vi.fn(createBrowserWindow) }))
|
|
|
|
const { openCoachProgressWindow } = await import('../../src/main/coach/progressWindow')
|
|
|
|
describe('openCoachProgressWindow()', () => {
|
|
beforeEach(() => {
|
|
lastWindow?.emit('closed')
|
|
vi.clearAllMocks()
|
|
lastWindow = null
|
|
})
|
|
|
|
it('should create and maximize a new window', () => {
|
|
openCoachProgressWindow()
|
|
expect(lastWindow?.maximize).toHaveBeenCalled()
|
|
expect(lastWindow?.setAlwaysOnTop).toHaveBeenCalled()
|
|
})
|
|
|
|
it('should reuse and re-show the existing window on a second call', () => {
|
|
openCoachProgressWindow()
|
|
const firstWindow = lastWindow
|
|
openCoachProgressWindow()
|
|
expect(lastWindow).toBe(firstWindow)
|
|
expect(firstWindow?.show).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('should send navigate-to-module immediately when the page is already loaded', () => {
|
|
openCoachProgressWindow({ subject: 'algebre', module: 'Fractions' })
|
|
expect(lastWindow?.webContents.send).toHaveBeenCalledWith('navigate-to-module', {
|
|
subject: 'algebre',
|
|
module: 'Fractions'
|
|
})
|
|
})
|
|
|
|
it('should wait for did-finish-load before navigating when the page is still loading', () => {
|
|
nextWindowStartsLoading = true
|
|
openCoachProgressWindow({ subject: 'algebre', module: 'Fractions' })
|
|
expect(lastWindow?.webContents.send).not.toHaveBeenCalled()
|
|
lastWindow?.webContents.emit('did-finish-load')
|
|
expect(lastWindow?.webContents.send).toHaveBeenCalled()
|
|
})
|
|
|
|
it('should navigate on an already-open window reused for a second target', () => {
|
|
openCoachProgressWindow()
|
|
openCoachProgressWindow({ subject: 'geometrie', module: 'Triangles' })
|
|
expect(lastWindow?.webContents.send).toHaveBeenCalledWith('navigate-to-module', {
|
|
subject: 'geometrie',
|
|
module: 'Triangles'
|
|
})
|
|
})
|
|
})
|