feat(admin): build tooling, Docker stage and docs; close test gaps
- Add Makefile (admin, build, test) and a node stage in the Dockerfile - Add .dockerignore so host node_modules and builds stay out of the image - Document the admin UI in the README - Cover mutation survivors: token cleanup on non-401 failures, cache dropped on 401 and sign out, member filter by name, archive invalidated after approval, page offset
This commit is contained in:
parent
b3a85a55ea
commit
a0a083273c
5 changed files with 103 additions and 2 deletions
|
|
@ -4,6 +4,36 @@ import { aList, installFakeApi, newState } from '@/test/fakeApi'
|
|||
import { renderApp } from '@/test/render'
|
||||
|
||||
describe('authentication', () => {
|
||||
it('does not keep the token when the check fails for another reason than 401', async () => {
|
||||
installFakeApi(newState({ fail: { 'GET /lists': { status: 500, error: 'database is locked' } } }))
|
||||
const { user } = renderApp('/login')
|
||||
await user.type(await screen.findByLabelText(/api token/i), 'good')
|
||||
await user.click(screen.getByRole('button', { name: /sign in/i }))
|
||||
expect(await screen.findByText('database is locked')).toBeInTheDocument()
|
||||
expect(sessionStorage.getItem('parsimony.token')).toBeNull()
|
||||
})
|
||||
|
||||
it('drops cached data when the session ends', async () => {
|
||||
const state = installFakeApi(newState({ lists: [aList()] }))
|
||||
const { client } = renderApp('/', { token: 'good', keepCache: true })
|
||||
await screen.findByText('dev@example.org')
|
||||
expect(client.getQueryData(['lists'])).toBeDefined()
|
||||
state.token = 'rotated'
|
||||
const { api } = await import('@/lib/api')
|
||||
await api.lists.list().catch(() => undefined)
|
||||
await screen.findByRole('heading', { name: /sign in/i })
|
||||
expect(client.getQueryData(['lists'])).toBeUndefined()
|
||||
})
|
||||
|
||||
it('drops cached data on sign out', async () => {
|
||||
installFakeApi(newState({ lists: [aList()] }))
|
||||
const { user, client } = renderApp('/', { token: 'good', keepCache: true })
|
||||
await screen.findByText('dev@example.org')
|
||||
await user.click(screen.getByRole('button', { name: /sign out/i }))
|
||||
await screen.findByRole('heading', { name: /sign in/i })
|
||||
expect(client.getQueryData(['lists'])).toBeUndefined()
|
||||
})
|
||||
|
||||
it('sends anonymous visitors to the login page', async () => {
|
||||
installFakeApi(newState())
|
||||
renderApp('/')
|
||||
|
|
|
|||
|
|
@ -90,6 +90,9 @@ describe('archive tab', () => {
|
|||
|
||||
await user.click(screen.getByRole('button', { name: /next/i }))
|
||||
expect(await screen.findByText('26–50 of 60')).toBeInTheDocument()
|
||||
// The rows really are the second page, not just the label.
|
||||
expect(await screen.findByRole('button', { name: 'Subject 26' })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'Subject 1' })).not.toBeInTheDocument()
|
||||
expect(state.calls).toContain('GET /lists/1/archive')
|
||||
await user.click(screen.getByRole('button', { name: /next/i }))
|
||||
expect(await screen.findByText('51–60 of 60')).toBeInTheDocument()
|
||||
|
|
|
|||
|
|
@ -106,6 +106,15 @@ describe('held tab', () => {
|
|||
})
|
||||
})
|
||||
|
||||
it('marks the archive stale after an approval, because the message is archived on delivery', async () => {
|
||||
const state = installFakeApi(newState({ lists: [aList({ id: 1, post_policy: 'moderated' })], held: { 1: [held(1)] } }))
|
||||
const { user, client } = renderApp('/lists/1/held', { token: 'good', keepCache: true })
|
||||
client.setQueryData(['archive', 1, '', 0], { total: 0, messages: [] })
|
||||
await user.click(within((await screen.findByText('Subject 1')).closest('tr')!).getByRole('button', { name: /approve/i }))
|
||||
await waitFor(() => expect(state.held[1]).toHaveLength(0))
|
||||
await waitFor(() => expect(client.getQueryState(['archive', 1, '', 0])?.isInvalidated).toBe(true))
|
||||
})
|
||||
|
||||
it('updates the badge on the tab when the queue changes', async () => {
|
||||
const { user } = await setup([held(1), held(2)])
|
||||
expect(await screen.findByRole('tab', { name: /^held\s*2$/i })).toBeInTheDocument()
|
||||
|
|
|
|||
|
|
@ -54,6 +54,14 @@ describe('members tab', () => {
|
|||
expect(await screen.findByText(/no members match/i)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('filters by display name too', async () => {
|
||||
const { user } = await setup([member('x@example.com', { display_name: 'Zoe Quinn' }), member('y@example.com')])
|
||||
await screen.findByText('y@example.com')
|
||||
await user.type(screen.getByRole('searchbox', { name: /filter members/i }), 'zoe')
|
||||
expect(screen.getByText('x@example.com')).toBeInTheDocument()
|
||||
expect(screen.queryByText('y@example.com')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('adds a member and clears the form', async () => {
|
||||
const { user, state } = await setup([member('alice@example.com')])
|
||||
await user.type(screen.getByLabelText(/email address/i), 'Dave@Example.com')
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ import { AuthProvider } from '@/lib/auth'
|
|||
import { session } from '@/lib/api'
|
||||
|
||||
/** Renders the whole app at `path`. Pass `token` to start logged in. */
|
||||
export function renderApp(path = '/', opts: { token?: string } = {}) {
|
||||
export function renderApp(path = '/', opts: { token?: string; keepCache?: boolean } = {}) {
|
||||
if (opts.token) session.set(opts.token)
|
||||
const client = new QueryClient({ defaultOptions: { queries: { retry: false, gcTime: 0 }, mutations: { retry: false } } })
|
||||
const client = new QueryClient({ defaultOptions: { queries: { retry: false, gcTime: opts.keepCache ? Infinity : 0 }, mutations: { retry: false } } })
|
||||
const user = userEvent.setup()
|
||||
const utils = render(
|
||||
<QueryClientProvider client={client}>
|
||||
|
|
|
|||
Loading…
Reference in a new issue