Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"styled-components": "^6.3.12"
},
"devDependencies": {
"@playwright/test": "^1.58.2",
"@playwright/test": "^1.60.0",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.2",
"@testing-library/user-event": "^14.6.1",
Expand All @@ -41,7 +41,7 @@
"@vitejs/plugin-react": "^4.3.4",
"autoprefixer": "^10.4.27",
"cross-env": "^10.1.0",
"jsdom": "^29.0.1",
"jsdom": "^29.1.1",
"postcss": "^8.5.8",
"tailwindcss": "^3.4.19",
"typescript": "5.5.4",
Expand Down
46 changes: 45 additions & 1 deletion frontend/testing/unit/components/ToastContext.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { render, screen, waitFor } from '@testing-library/react'
import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest'
import userEvent from '@testing-library/user-event'
import { ToastProvider, useToast } from '../../../src/components/ToastContext'

function ToastTrigger({ type = 'success' }: { type?: 'success' | 'error' }) {
function ToastTrigger({ type = 'success' }: { type?: 'success' | 'error' | 'info' }) {
const { addToast } = useToast()

return (
Expand All @@ -12,6 +13,15 @@ function ToastTrigger({ type = 'success' }: { type?: 'success' | 'error' }) {
)
}

beforeEach(() => {
vi.useFakeTimers()
})

afterEach(() => {
vi.runOnlyPendingTimers()
vi.useRealTimers()
})

describe('Toast accessibility', () => {
it('announces non-critical notifications as status messages and provides a labelled dismiss control', async () => {
const user = userEvent.setup()
Expand Down Expand Up @@ -46,4 +56,38 @@ describe('Toast accessibility', () => {

expect(await screen.findByRole('alert')).toHaveTextContent(/error message/i)
})
it('announces info notifications as status messages', async () => {
const user = userEvent.setup()

render(
<ToastProvider>
<ToastTrigger type="info" />
</ToastProvider>,
)

await user.click(screen.getByRole('button', { name: /show toast/i }))

expect(await screen.findByRole('status')).toHaveTextContent(/info message/i)
})
it('automatically dismisses toast after timeout', async () => {
const user = userEvent.setup({
advanceTimers: vi.advanceTimersByTime,
})

render(
<ToastProvider>
<ToastTrigger />
</ToastProvider>,
)

await user.click(screen.getByRole('button', { name: /show toast/i }))

expect(await screen.findByText(/success message/i)).toBeInTheDocument()

vi.advanceTimersByTime(5000)

await waitFor(() => {
expect(screen.queryByText(/success message/i)).not.toBeInTheDocument()
})
})
})
Loading