mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-28 03:09:04 +01:00
Some checks failed
dependency freshness / dependencies on newest stable (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint) (push) Has been cancelled
Tests / test (push) Has been cancelled
Tests / web-coverage (push) Has been cancelled
repo-contract / repo contract (push) Has been cancelled
Todo: 9b9342ba
56 lines
2.0 KiB
TypeScript
56 lines
2.0 KiB
TypeScript
import { screen } from '@testing-library/dom'
|
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { apiError, flush, mount, stubApi } from '../../test/harness'
|
|
import { names, show } from '../../test/plannerHelpers'
|
|
|
|
afterEach(() => {
|
|
history.replaceState(null, '', '/')
|
|
})
|
|
|
|
describe('<game-table> loading', () => {
|
|
it('shows loading until the dataset arrives', () => {
|
|
stubApi({ 'GET /api/dataset': () => new Promise(() => undefined) })
|
|
mount('<game-table></game-table>')
|
|
expect(screen.getByText(/Loading your backlog/i)).toBeInTheDocument()
|
|
})
|
|
|
|
it('renders the planner once data loads', async () => {
|
|
await show()
|
|
expect(screen.getByRole('heading', { name: 'Backlog Completion Planner' })).toBeInTheDocument()
|
|
expect(screen.getByText(/CLI default qualifies/i)).toBeInTheDocument()
|
|
})
|
|
|
|
it('shows an error when the API call fails', async () => {
|
|
stubApi({ 'GET /api/dataset': apiError(500, 'boom') })
|
|
mount('<game-table></game-table>')
|
|
await flush()
|
|
expect(screen.getByText('Could not load data: API returned 500 Error')).toBeInTheDocument()
|
|
expect(screen.getByText('./run.sh serve')).toBeInTheDocument()
|
|
})
|
|
|
|
it('handles a non-Error rejection', async () => {
|
|
vi.stubGlobal('fetch', vi.fn().mockRejectedValue('network down'))
|
|
mount('<game-table></game-table>')
|
|
await flush()
|
|
expect(screen.getByText(/network down/i)).toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
describe('<game-table> hash changes', () => {
|
|
it('re-reads a hand-edited hash', async () => {
|
|
await show()
|
|
history.replaceState(null, '', '#f.name=gam')
|
|
window.dispatchEvent(new HashChangeEvent('hashchange'))
|
|
expect(screen.getByRole('searchbox', { name: 'Filter Game' })).toHaveValue('gam')
|
|
expect(names()).toEqual(['Gamma'])
|
|
})
|
|
|
|
it('stops listening for hash changes once removed', async () => {
|
|
const { el } = await show()
|
|
el.remove()
|
|
history.replaceState(null, '', '#f.name=gam')
|
|
window.dispatchEvent(new HashChangeEvent('hashchange'))
|
|
expect(location.hash).toBe('#f.name=gam')
|
|
})
|
|
})
|