- Vitest unit tests: smart paste parsing (37), cost calculations (21),
oil translation (16), dialog system (12), with production data fixtures
- Cypress E2E tests: API CRUD (27), auth flow (8), recipe detail (10),
search (12), oil reference (4), favorites (6), inventory (6),
recipe management (10), diary (11), bug tracker (8), user management (13),
cost parity (6), data integrity (8), responsive (9), performance (6),
navigation (8), admin flow (5)
- Test coverage doc with prioritized gap analysis
- Found backend bug: POST /api/bug-reports/{id}/comment deletes the bug
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
119 lines
3.4 KiB
JavaScript
119 lines
3.4 KiB
JavaScript
import { describe, it, expect, beforeEach } from 'vitest'
|
|
import { dialogState, showAlert, showConfirm, showPrompt, closeDialog } from '../composables/useDialog'
|
|
|
|
// Reset dialog state before each test
|
|
beforeEach(() => {
|
|
dialogState.visible = false
|
|
dialogState.type = 'alert'
|
|
dialogState.message = ''
|
|
dialogState.defaultValue = ''
|
|
dialogState.resolve = null
|
|
})
|
|
|
|
describe('Dialog System', () => {
|
|
it('starts hidden', () => {
|
|
expect(dialogState.visible).toBe(false)
|
|
})
|
|
|
|
it('showAlert opens alert dialog', async () => {
|
|
const promise = showAlert('test message')
|
|
expect(dialogState.visible).toBe(true)
|
|
expect(dialogState.type).toBe('alert')
|
|
expect(dialogState.message).toBe('test message')
|
|
closeDialog()
|
|
await promise
|
|
expect(dialogState.visible).toBe(false)
|
|
})
|
|
|
|
it('showAlert resolves when closed', async () => {
|
|
const promise = showAlert('hello')
|
|
closeDialog()
|
|
const result = await promise
|
|
expect(result).toBeUndefined()
|
|
})
|
|
|
|
it('showConfirm returns true on ok', async () => {
|
|
const promise = showConfirm('are you sure?')
|
|
expect(dialogState.type).toBe('confirm')
|
|
expect(dialogState.message).toBe('are you sure?')
|
|
closeDialog(true)
|
|
const result = await promise
|
|
expect(result).toBe(true)
|
|
})
|
|
|
|
it('showConfirm returns false on cancel', async () => {
|
|
const promise = showConfirm('are you sure?')
|
|
closeDialog(false)
|
|
const result = await promise
|
|
expect(result).toBe(false)
|
|
})
|
|
|
|
it('showPrompt opens prompt dialog with default value', async () => {
|
|
const promise = showPrompt('enter name', 'default')
|
|
expect(dialogState.visible).toBe(true)
|
|
expect(dialogState.type).toBe('prompt')
|
|
expect(dialogState.message).toBe('enter name')
|
|
expect(dialogState.defaultValue).toBe('default')
|
|
closeDialog('hello')
|
|
await promise
|
|
})
|
|
|
|
it('showPrompt returns input value', async () => {
|
|
const promise = showPrompt('enter name', 'default')
|
|
closeDialog('hello')
|
|
const result = await promise
|
|
expect(result).toBe('hello')
|
|
})
|
|
|
|
it('showPrompt returns null on cancel', async () => {
|
|
const promise = showPrompt('enter name')
|
|
closeDialog(null)
|
|
const result = await promise
|
|
expect(result).toBeNull()
|
|
})
|
|
|
|
it('showPrompt defaults defaultValue to empty string', async () => {
|
|
const promise = showPrompt('enter name')
|
|
expect(dialogState.defaultValue).toBe('')
|
|
closeDialog('test')
|
|
await promise
|
|
})
|
|
|
|
it('closeDialog sets visible to false', async () => {
|
|
showAlert('msg')
|
|
expect(dialogState.visible).toBe(true)
|
|
closeDialog()
|
|
expect(dialogState.visible).toBe(false)
|
|
})
|
|
|
|
it('closeDialog clears resolve after calling it', async () => {
|
|
const promise = showAlert('msg')
|
|
closeDialog()
|
|
await promise
|
|
expect(dialogState.resolve).toBeNull()
|
|
})
|
|
|
|
it('multiple sequential dialogs work correctly', async () => {
|
|
// First dialog
|
|
const p1 = showAlert('first')
|
|
expect(dialogState.message).toBe('first')
|
|
closeDialog()
|
|
await p1
|
|
|
|
// Second dialog
|
|
const p2 = showConfirm('second')
|
|
expect(dialogState.message).toBe('second')
|
|
expect(dialogState.type).toBe('confirm')
|
|
closeDialog(true)
|
|
const r2 = await p2
|
|
expect(r2).toBe(true)
|
|
|
|
// Third dialog
|
|
const p3 = showPrompt('third', 'val')
|
|
expect(dialogState.type).toBe('prompt')
|
|
closeDialog('answer')
|
|
const r3 = await p3
|
|
expect(r3).toBe('answer')
|
|
})
|
|
})
|