feat: add CI/CD, code quality, testing and security hardening
CI / quality (push) Failing after 6m22s
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>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
1959ddb41a
commit
e9690a49f9
@@ -0,0 +1,134 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { buildCircleSector } from '../../src/main/coach/presets/circleSector'
|
||||
import { buildCoordinateAxes } from '../../src/main/coach/presets/coordinateAxes'
|
||||
import { buildRegularPolygon } from '../../src/main/coach/presets/regularPolygon'
|
||||
import { buildRightTriangle } from '../../src/main/coach/presets/rightTriangle'
|
||||
import { buildTriangle } from '../../src/main/coach/presets/triangle'
|
||||
import { buildVennDiagram } from '../../src/main/coach/presets/vennDiagram'
|
||||
|
||||
describe('buildCircleSector()', () => {
|
||||
it('should return one arc shape per slice, with angles summing to 360 degrees', () => {
|
||||
const shapes = buildCircleSector({
|
||||
slices: [
|
||||
{ value: 50, label: 'A' },
|
||||
{ value: 50, label: 'B' }
|
||||
]
|
||||
})
|
||||
expect(shapes).toHaveLength(2)
|
||||
expect(shapes[0]?.startAngle).toBe(-90)
|
||||
expect(shapes[1]?.endAngle).toBe(270)
|
||||
})
|
||||
|
||||
it('should ignore slices with a zero or negative value', () => {
|
||||
const shapes = buildCircleSector({ slices: [{ value: 0 }, { value: -5 }, { value: 10 }] })
|
||||
expect(shapes).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('should return an empty array when there are no valid slices', () => {
|
||||
expect(buildCircleSector({ slices: [] })).toEqual([])
|
||||
expect(buildCircleSector({})).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildCoordinateAxes()', () => {
|
||||
it('should always return the two perpendicular axis arrows plus axis labels', () => {
|
||||
const shapes = buildCoordinateAxes({})
|
||||
const arrows = shapes.filter((s) => s.type === 'arrow')
|
||||
expect(arrows).toHaveLength(2)
|
||||
expect(arrows[0]?.y).toBe(arrows[0]?.y2)
|
||||
expect(arrows[1]?.x).toBe(arrows[1]?.x2)
|
||||
})
|
||||
|
||||
it('should add a circle for each valid point provided', () => {
|
||||
const shapes = buildCoordinateAxes({
|
||||
points: [
|
||||
{ x: 1, y: 2, label: 'P' },
|
||||
{ x: 3, y: 4 }
|
||||
]
|
||||
})
|
||||
const circles = shapes.filter((s) => s.type === 'circle')
|
||||
expect(circles).toHaveLength(2)
|
||||
expect(circles[0]?.label).toBe('P')
|
||||
})
|
||||
|
||||
it('should ignore non-object entries in the points array', () => {
|
||||
const shapes = buildCoordinateAxes({ points: [null, 'invalid', { x: 1, y: 1 }] })
|
||||
expect(shapes.filter((s) => s.type === 'circle')).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildRegularPolygon()', () => {
|
||||
it('should return exactly as many line segments as sides requested', () => {
|
||||
const shapes = buildRegularPolygon({ sides: 5 })
|
||||
expect(shapes).toHaveLength(5)
|
||||
expect(shapes.every((s) => s.type === 'line')).toBe(true)
|
||||
})
|
||||
|
||||
it('should clamp the number of sides between 3 and 12', () => {
|
||||
expect(buildRegularPolygon({ sides: 1 })).toHaveLength(3)
|
||||
expect(buildRegularPolygon({ sides: 100 })).toHaveLength(12)
|
||||
})
|
||||
|
||||
it('should attach the provided labels/captions by index', () => {
|
||||
const shapes = buildRegularPolygon({ sides: 3, labels: ['a', 'b', 'c'] })
|
||||
expect(shapes.map((s) => s.label)).toEqual(['a', 'b', 'c'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildRightTriangle()', () => {
|
||||
it('should return the three sides, the right-angle marker and the angle arc', () => {
|
||||
const shapes = buildRightTriangle({})
|
||||
expect(shapes.filter((s) => s.type === 'line')).toHaveLength(3)
|
||||
expect(shapes.some((s) => s.type === 'rect')).toBe(true)
|
||||
expect(shapes.some((s) => s.type === 'arc')).toBe(true)
|
||||
})
|
||||
|
||||
it('should use the default labels when none are provided', () => {
|
||||
const shapes = buildRightTriangle({})
|
||||
const labels = shapes.map((s) => s.label)
|
||||
expect(labels).toContain('Adjacent')
|
||||
expect(labels).toContain('Opposé')
|
||||
expect(labels).toContain('Hypoténuse')
|
||||
})
|
||||
|
||||
it('should use custom labels when provided', () => {
|
||||
const shapes = buildRightTriangle({ adjacentLabel: 'Cote A' })
|
||||
expect(shapes.some((s) => s.label === 'Cote A')).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildTriangle()', () => {
|
||||
it('should return the three sides of the triangle', () => {
|
||||
const shapes = buildTriangle({})
|
||||
expect(shapes.filter((s) => s.type === 'line')).toHaveLength(3)
|
||||
})
|
||||
|
||||
it('should include an apex text label when apexLabel is provided', () => {
|
||||
const shapes = buildTriangle({ apexLabel: 'A' })
|
||||
expect(shapes.some((s) => s.type === 'text' && s.content === 'A')).toBe(true)
|
||||
})
|
||||
|
||||
it('should omit the apex text shape when no apexLabel is provided', () => {
|
||||
const shapes = buildTriangle({})
|
||||
expect(shapes.some((s) => s.type === 'text')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildVennDiagram()', () => {
|
||||
it('should return 2 circles by default', () => {
|
||||
const shapes = buildVennDiagram({})
|
||||
expect(shapes).toHaveLength(2)
|
||||
expect(shapes.every((s) => s.type === 'circle')).toBe(true)
|
||||
})
|
||||
|
||||
it('should return 3 circles when 3 labels are given', () => {
|
||||
const shapes = buildVennDiagram({ labels: ['A', 'B', 'C'] })
|
||||
expect(shapes).toHaveLength(3)
|
||||
expect(shapes.map((s) => s.label)).toEqual(['A', 'B', 'C'])
|
||||
})
|
||||
|
||||
it('should clamp to at most 3 circles even with more labels', () => {
|
||||
const shapes = buildVennDiagram({ labels: ['A', 'B', 'C', 'D', 'E'] })
|
||||
expect(shapes).toHaveLength(3)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user