fix(app): unreadable permissions show a retry, never the form (V1-2.5 L1)
Owner checkpoint 2026-11-02: creation page checks loading, server refusal, failed read, then the editor rule; Administration home shows the same notice. reloadAccess re-reads roles and grants without wiping held state; refreshAccount (no caller) removed. Zone panel live region always mounted. Unit and e2e for reviewer-only and editor.
This commit is contained in:
1 parent
14ff890761
commit
4111efa1d1
15 files changed
+856
-56
No files matched your search
@@ -148,8 +148,9 @@ function mount(
|
||||
path: string,
|
||||
grants: OwnCatalogGrant[],
|
||||
roles: PlatformRole[] = [],
|
||||
status: 'loading' | 'ready' | 'failed' = 'ready',
|
||||
) {
|
||||
useAuthStore.setState({ catalogGrants: grants, catalogGrantsStatus: 'ready', roles })
|
||||
useAuthStore.setState({ catalogGrants: grants, catalogGrantsStatus: status, roles })
|
||||
return render(
|
||||
<MemoryRouter initialEntries={[path]}>
|
||||
<Routes>
|
||||
@@ -171,6 +172,7 @@ function mount(
|
||||
beforeAll(async () => {
|
||||
setCoreRuntime(await testCoreRuntime())
|
||||
})
|
||||
const realReloadAccess = useAuthStore.getState().reloadAccess
|
||||
beforeEach(() => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
fake = createFakeSupabase()
|
||||
@@ -180,7 +182,39 @@ beforeEach(() => {
|
||||
fake.rpcResults.list_catalog_species = { data: SPECIES }
|
||||
mocks.fake = fake
|
||||
})
|
||||
afterEach(() => cleanup())
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
useAuthStore.setState({ reloadAccess: realReloadAccess })
|
||||
})
|
||||
|
||||
describe('Administration page: own grants states', () => {
|
||||
it('loading: the waiting status, not « aucune »', () => {
|
||||
mount('/app/admin', [], [], 'loading')
|
||||
expect(screen.getByText(fr['shell.loading_session'])).toHaveAttribute('role', 'status')
|
||||
expect(screen.queryByText(/aucune/)).toBeNull()
|
||||
})
|
||||
|
||||
it('failed: the unavailable notice as a section, Retry, focus kept on the wrapper', async () => {
|
||||
const user = userEvent.setup()
|
||||
const reloadAccess = vi.fn(async () =>
|
||||
useAuthStore.setState({ catalogGrants: [grant('sheet_editor')], catalogGrantsStatus: 'ready' }),
|
||||
)
|
||||
mount('/app/admin', [], [], 'failed')
|
||||
useAuthStore.setState({ reloadAccess })
|
||||
expect(screen.getAllByRole('heading', { level: 1 })).toHaveLength(1)
|
||||
expect(
|
||||
screen.getByRole('heading', { level: 2, name: fr['permissions_unavailable.title'] }),
|
||||
).toBeInTheDocument()
|
||||
expect(screen.queryByText(/aucune/)).toBeNull()
|
||||
await user.click(screen.getByRole('button', { name: 'Réessayer' }))
|
||||
expect(reloadAccess).toHaveBeenCalledTimes(1)
|
||||
await waitFor(() =>
|
||||
expect(screen.getByText(/Vos habilitations : éditeur de fiches/)).toBeInTheDocument(),
|
||||
)
|
||||
const wrapper = screen.getByText(/Vos habilitations/).parentElement
|
||||
expect(wrapper).toHaveFocus()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Administration page (board 10)', () => {
|
||||
it('editor and publisher: permissions line, sheets with badges, the working copy action disabled with its reason', async () => {
|
||||
@@ -655,13 +689,82 @@ describe('Sheet creation (A1)', () => {
|
||||
expect(rpcArgs('create_official_sheet')).toEqual([])
|
||||
})
|
||||
|
||||
it('decides nothing while the own grants load, and leaves a failed read to the server', async () => {
|
||||
mount('/app/admin/sheets/new', [])
|
||||
useAuthStore.setState({ catalogGrantsStatus: 'loading' })
|
||||
expect(await screen.findByRole('status')).toHaveTextContent(fr['shell.loading_session'])
|
||||
expect(screen.queryByRole('heading', { name: fr['access_denied.title'] })).toBeNull()
|
||||
useAuthStore.setState({ catalogGrantsStatus: 'failed' })
|
||||
expect(await screen.findByLabelText('Espèce')).toBeInTheDocument()
|
||||
describe.each([
|
||||
['a reviewer-only account', [grant('sheet_reviewer')], false],
|
||||
['an editor account', [grant('sheet_editor')], true],
|
||||
] as const)('permission states for %s', (_, grants, canCreate) => {
|
||||
const denied = () =>
|
||||
screen.queryByRole('heading', { name: fr['access_denied.title'] })
|
||||
const unavailable = () =>
|
||||
screen.queryByRole('heading', {
|
||||
name: fr['permissions_unavailable.title'],
|
||||
})
|
||||
|
||||
it('ready: the form for the editor, « Accès non autorisé » otherwise', async () => {
|
||||
mount('/app/admin/sheets/new', [...grants])
|
||||
if (canCreate) {
|
||||
expect(await screen.findByLabelText('Espèce')).toBeInTheDocument()
|
||||
expect(denied()).toBeNull()
|
||||
} else {
|
||||
expect(await screen.findByRole('heading', { name: fr['access_denied.title'] })).toBeInTheDocument()
|
||||
expect(screen.queryByLabelText('Espèce')).toBeNull()
|
||||
}
|
||||
expect(unavailable()).toBeNull()
|
||||
})
|
||||
|
||||
it('failed: the unavailable state, no form, no refusal deduced', async () => {
|
||||
mount('/app/admin/sheets/new', [...grants], [], 'failed')
|
||||
expect(await screen.findByRole('heading', { name: fr['permissions_unavailable.title'] })).toBeInTheDocument()
|
||||
expect(screen.getByText(fr['permissions_unavailable.body'])).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Réessayer' })).toBeInTheDocument()
|
||||
expect(document.querySelector('input, select')).toBeNull()
|
||||
expect(denied()).toBeNull()
|
||||
})
|
||||
|
||||
it('loading: waits, decides nothing', async () => {
|
||||
mount('/app/admin/sheets/new', [...grants], [], 'loading')
|
||||
expect(await screen.findByRole('status')).toHaveTextContent(fr['shell.loading_session'])
|
||||
expect(denied()).toBeNull()
|
||||
expect(unavailable()).toBeNull()
|
||||
expect(document.querySelector('input, select')).toBeNull()
|
||||
})
|
||||
|
||||
it('Retry lands on what the new answer gives', async () => {
|
||||
const user = userEvent.setup()
|
||||
const reloadAccess = vi.fn(async () =>
|
||||
useAuthStore.setState({ catalogGrants: [...grants], catalogGrantsStatus: 'ready' }),
|
||||
)
|
||||
mount('/app/admin/sheets/new', [], [], 'failed')
|
||||
useAuthStore.setState({ reloadAccess })
|
||||
await user.click(await screen.findByRole('button', { name: 'Réessayer' }))
|
||||
expect(reloadAccess).toHaveBeenCalledTimes(1)
|
||||
if (canCreate) expect(await screen.findByLabelText('Espèce')).toBeInTheDocument()
|
||||
else expect(await screen.findByRole('heading', { name: fr['access_denied.title'] })).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('Retry also reads a failed species list again', async () => {
|
||||
const user = userEvent.setup()
|
||||
let calls = 0
|
||||
fake.rpcResults.list_catalog_species = () =>
|
||||
++calls === 1 ? { error: new TypeError('fetch failed') } : { data: SPECIES }
|
||||
mount('/app/admin/sheets/new', [], [], 'failed')
|
||||
useAuthStore.setState({
|
||||
reloadAccess: vi.fn(async () =>
|
||||
useAuthStore.setState({ catalogGrants: [grant('sheet_editor')], catalogGrantsStatus: 'ready' }),
|
||||
),
|
||||
})
|
||||
await user.click(await screen.findByRole('button', { name: 'Réessayer' }))
|
||||
const species = await screen.findByLabelText('Espèce')
|
||||
await waitFor(() => expect(within(species).getAllByRole('option')).toHaveLength(3))
|
||||
expect(calls).toBe(2)
|
||||
})
|
||||
|
||||
it('a server rights refusal wins over a failed grants read', async () => {
|
||||
fake.rpcResults.list_catalog_species = refusal('rights.capability')
|
||||
mount('/app/admin/sheets/new', [], [], 'failed')
|
||||
expect(await screen.findByRole('heading', { name: fr['access_denied.title'] })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('heading', { name: fr['permissions_unavailable.title'] })).toBeNull()
|
||||
})
|
||||
|
||||
it('proposes a slug from the French name', () => {
|
||||
|
||||
Reference in new issue
Block a user