generated from coulomb/repo-seed
add: comprehensive TDD test infrastructure
- Add Vitest + jsdom testing framework - Create unit tests for engine.js and generator.js - Add integration tests for end-to-end workflows - Include test utilities and setup helpers - Document testing approach in TESTING.md - Document all dependencies in DEPENDS.md - Add Makefile with test targets and dev workflow 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
70
test/testHelpers.js
Normal file
70
test/testHelpers.js
Normal file
@@ -0,0 +1,70 @@
|
||||
// Test helpers and utilities
|
||||
|
||||
export const createSampleProject = () => ({
|
||||
name: "Test Project",
|
||||
description: "A test project for unit testing",
|
||||
dataSource: "test.csv",
|
||||
stylesheet: "test.css",
|
||||
svgTemplate: "test.svg",
|
||||
settings: {
|
||||
timelineMonths: 12
|
||||
},
|
||||
fieldMapping: {
|
||||
id: "ID",
|
||||
title: "Title",
|
||||
lane: "Lane",
|
||||
due: ["Due"]
|
||||
}
|
||||
})
|
||||
|
||||
export const createSampleItems = () => [
|
||||
{
|
||||
id: "T-1",
|
||||
title: "First Task",
|
||||
lane: "Development",
|
||||
due: new Date("2025-01-15")
|
||||
},
|
||||
{
|
||||
id: "T-2",
|
||||
title: "Second Task",
|
||||
lane: "Testing",
|
||||
due: new Date("2025-02-20")
|
||||
},
|
||||
{
|
||||
id: "T-3",
|
||||
title: "Third Task",
|
||||
lane: "Development",
|
||||
due: new Date("2025-03-10")
|
||||
}
|
||||
]
|
||||
|
||||
export const createSampleCSV = () => `ID,Title,Lane,Due
|
||||
T-1,First Task,Development,2025-01-15
|
||||
T-2,Second Task,Testing,2025-02-20
|
||||
T-3,Third Task,Development,2025-03-10`
|
||||
|
||||
export const createSampleTemplate = () => `<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
{{MONTHS}}
|
||||
{{LANES}}
|
||||
</svg>`
|
||||
|
||||
export const mockFetch = (data, ok = true) => {
|
||||
global.fetch.mockResolvedValueOnce({
|
||||
ok,
|
||||
json: () => Promise.resolve(data),
|
||||
text: () => Promise.resolve(typeof data === 'string' ? data : JSON.stringify(data))
|
||||
})
|
||||
}
|
||||
|
||||
export const expectElementToHaveText = (selector, text) => {
|
||||
const element = document.querySelector(selector)
|
||||
expect(element).toBeTruthy()
|
||||
expect(element.textContent).toContain(text)
|
||||
}
|
||||
|
||||
export const expectSVGToContain = (selector, expectedContent) => {
|
||||
const svg = document.querySelector(selector)
|
||||
expect(svg).toBeTruthy()
|
||||
expect(svg.outerHTML).toContain(expectedContent)
|
||||
}
|
||||
Reference in New Issue
Block a user