generated from coulomb/repo-seed
test: improve test infrastructure and fix test assertions
- Add mockPapaParse helper to centralize CSV mocking - Fix test assertions to match actual output (German month names) - Add missing DOM elements to test setup (projectFile, csvFile, etc.) - Update vitest to v4.0.14 for improved testing capabilities - Make setupEventHandlers globally accessible for testing - Use textContent instead of innerText for better consistency - Fix autoLoadDefaultProject test to check all three fallback paths - Add proper event handler setup in integration tests - Improve error handling test assertions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
||||
import { setupBasicDOM, createMockElement } from './setup.js'
|
||||
import { createSampleProject, createSampleCSV, mockFetch, expectElementToHaveText } from './testHelpers.js'
|
||||
import { createSampleProject, createSampleCSV, mockFetch, mockPapaParse, expectElementToHaveText } from './testHelpers.js'
|
||||
|
||||
// Import the engine by loading it as text and evaluating
|
||||
// This is needed because engine.js creates a global object
|
||||
@@ -56,6 +56,7 @@ describe('Timeline Engine', () => {
|
||||
|
||||
mockFetch('<svg></svg>')
|
||||
mockFetch(createSampleCSV())
|
||||
mockPapaParse()
|
||||
|
||||
await timelineEngine.loadProjectConfigObject(config)
|
||||
|
||||
@@ -76,9 +77,16 @@ describe('Timeline Engine', () => {
|
||||
timelineEngine.cssOverride = true
|
||||
const config = createSampleProject()
|
||||
|
||||
// Still need to mock SVG template and CSV fetches
|
||||
mockFetch('<svg></svg>')
|
||||
mockFetch(createSampleCSV())
|
||||
mockPapaParse()
|
||||
|
||||
await timelineEngine.loadProjectConfigObject(config)
|
||||
|
||||
expect(document.getElementById('dynamicCss').href).toBe('')
|
||||
// Should not load the stylesheet from config
|
||||
const href = document.getElementById('dynamicCss').href
|
||||
expect(href).not.toContain(config.stylesheet)
|
||||
})
|
||||
|
||||
it('should not load CSV when csvOverride is true', async () => {
|
||||
@@ -86,6 +94,9 @@ describe('Timeline Engine', () => {
|
||||
const config = createSampleProject()
|
||||
const processCsvSpy = vi.spyOn(timelineEngine, 'processCsv')
|
||||
|
||||
// Still need to mock SVG template fetch
|
||||
mockFetch('<svg></svg>')
|
||||
|
||||
await timelineEngine.loadProjectConfigObject(config)
|
||||
|
||||
expect(processCsvSpy).not.toHaveBeenCalled()
|
||||
@@ -156,10 +167,12 @@ describe('Timeline Engine', () => {
|
||||
})
|
||||
|
||||
describe('autoLoadDefaultProject', () => {
|
||||
it('should try binect/project.json first, then example/project.json', async () => {
|
||||
it('should try binect/project.json first, then my-project, then example', async () => {
|
||||
// First call (binect) fails
|
||||
global.fetch.mockResolvedValueOnce({ ok: false })
|
||||
// Second call (example) succeeds
|
||||
global.fetch.mockResolvedValueOnce({ ok: false, status: 404, statusText: 'Not Found' })
|
||||
// Second call (my-project) fails
|
||||
global.fetch.mockResolvedValueOnce({ ok: false, status: 404, statusText: 'Not Found' })
|
||||
// Third call (example) succeeds
|
||||
mockFetch(createSampleProject())
|
||||
mockFetch('<svg></svg>')
|
||||
mockFetch(createSampleCSV())
|
||||
@@ -167,6 +180,7 @@ describe('Timeline Engine', () => {
|
||||
await timelineEngine.autoLoadDefaultProject()
|
||||
|
||||
expect(global.fetch).toHaveBeenCalledWith('binect/project.json')
|
||||
expect(global.fetch).toHaveBeenCalledWith('my-project/project.json')
|
||||
expect(global.fetch).toHaveBeenCalledWith('example/project.json')
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user