test(36-02): update test fixtures for granular scopes and rebuild embedded admin dist

This commit is contained in:
Jakub Zych
2026-11-24 19:49:38 +01:00
parent 336664684b
commit 3781c9792d
12 changed files with 404 additions and 186 deletions

View File

@@ -22,6 +22,8 @@ const existingToken = {
description: 'View everything',
read_only: true,
known: true,
plugin_id: '',
group: '',
},
],
created_at: '2026-01-10T12:00:00Z',
@@ -43,6 +45,8 @@ const starToken = {
description: 'Everything',
read_only: false,
known: true,
plugin_id: '',
group: '',
},
],
last_used_at: '2026-02-01T08:30:00Z',
@@ -61,6 +65,8 @@ const unknownScopeToken = {
description: '',
read_only: false,
known: false,
plugin_id: '',
group: '',
},
],
expired: true,
@@ -90,6 +96,8 @@ const scopes = [
description: 'Everything',
read_only: false,
known: true,
plugin_id: '',
group: '',
},
{
name: 'admin:read',
@@ -97,6 +105,20 @@ const scopes = [
description: 'View everything',
read_only: true,
known: true,
plugin_id: '',
group: '',
},
]
const pluginOnlyScopes = [
{
name: 'acme',
label: 'Acme',
description: 'Manage Acme items.',
read_only: false,
known: true,
plugin_id: 'acme.blog',
group: 'Acme',
},
]
@@ -162,11 +184,6 @@ describe('ApiTokensPanel', () => {
nameInput.dispatchEvent(new Event('input', { bubbles: true }))
await flushPromises()
const scope = dialog()!.querySelector<HTMLInputElement>('[data-scope="admin:read"] input')!
scope.checked = true
scope.dispatchEvent(new Event('change', { bubbles: true }))
await flushPromises()
const getsBeforeCreate = requestsTo(calls, 'GET', TOKENS).length
await click('[data-action="create-token-submit"]', dialog()!)
const [post] = requestsTo(calls, 'POST', TOKENS)
@@ -370,36 +387,34 @@ describe('ApiTokensPanel', () => {
await flushPromises()
}
it('disables other scopes when * is checked and posts only ["*"]', async () => {
it('switches to Full (*) tier, shows scope_all_includes note, and posts only ["*"]', async () => {
const { calls } = await openCreateDialog()
await fillName('Full')
const star = dialog()!.querySelector<HTMLInputElement>('[data-scope="*"] input')!
star.checked = true
star.dispatchEvent(new Event('change', { bubbles: true }))
await flushPromises()
expect(dialog()!.querySelector<HTMLInputElement>('[data-scope="admin:read"] input')!.disabled).toBe(true)
await click('[data-access-tier="full"]', dialog()!)
expect(dialog()!.textContent).toContain('Pełny dostęp obejmuje wszystkie pozostałe zakresy.')
await click('[data-action="create-token-submit"]', dialog()!)
const [post] = requestsTo(calls, 'POST', TOKENS)
expect(await post!.clone().json()).toEqual({ name: 'Full', expires: '90d', scopes: ['*'] })
})
it('keeps submit disabled until a scope is selected', async () => {
await openCreateDialog()
await fillName('No scope')
it('keeps submit disabled when Custom starts empty until a scope is applied', async () => {
await openCreateDialog({ [`GET ${SCOPES}`]: envelope(pluginOnlyScopes) })
await fillName('Scoped')
expect(dialog()!.querySelector<HTMLButtonElement>('[data-action="create-token-submit"]')!.disabled).toBe(
true,
)
const scope = dialog()!.querySelector<HTMLInputElement>('[data-scope="admin:read"] input')!
await click('[data-action="customize-scopes"]', dialog()!)
const scope = dialog()!.querySelector<HTMLInputElement>('[data-scope="acme"] input')!
scope.checked = true
scope.dispatchEvent(new Event('change', { bubbles: true }))
await flushPromises()
await click('[data-action="scope-picker-apply"]', dialog()!)
expect(dialog()!.querySelector<HTMLButtonElement>('[data-action="create-token-submit"]')!.disabled).toBe(
false,
)
})
it('renders a 422 on scopes and focuses the first scope checkbox', async () => {
it('renders a 422 on scopes and focuses the scope access control', async () => {
await openCreateDialog({
[`POST ${TOKENS}`]: {
status: 422,
@@ -413,13 +428,10 @@ describe('ApiTokensPanel', () => {
},
})
await fillName('Scoped')
const scope = dialog()!.querySelector<HTMLInputElement>('[data-scope="admin:read"] input')!
scope.checked = true
scope.dispatchEvent(new Event('change', { bubbles: true }))
await flushPromises()
await click('[data-action="create-token-submit"]', dialog()!)
expect(dialog()!.textContent).toContain('Wybierz co najmniej jeden zakres.')
expect(document.activeElement).toBe(dialog()!.querySelector('[data-scope="*"] input'))
expect(dialog()!.querySelector('[data-scope-summary]')!.getAttribute('aria-invalid')).toBe('true')
expect(document.activeElement).toBe(dialog()!.querySelector('[data-access-tier="read_only"]'))
})
it('shows Copied on clipboard success and copy_failed on rejection', async () => {
@@ -430,10 +442,6 @@ describe('ApiTokensPanel', () => {
})
await openCreateDialog()
await fillName('Copy me')
const scope = dialog()!.querySelector<HTMLInputElement>('[data-scope="admin:read"] input')!
scope.checked = true
scope.dispatchEvent(new Event('change', { bubbles: true }))
await flushPromises()
await click('[data-action="create-token-submit"]', dialog()!)
await click('[data-action="copy-token"]', dialog()!)
expect(writeText).toHaveBeenCalledWith(createdToken.token)
@@ -453,10 +461,6 @@ describe('ApiTokensPanel', () => {
it('asks before closing step 2 without a copy and keeps the step on cancel', async () => {
await openCreateDialog()
await fillName('Guard')
const scope = dialog()!.querySelector<HTMLInputElement>('[data-scope="admin:read"] input')!
scope.checked = true
scope.dispatchEvent(new Event('change', { bubbles: true }))
await flushPromises()
await click('[data-action="create-token-submit"]', dialog()!)
expect(dialog()!.querySelector('[data-token-plaintext]')).toBeTruthy()
keydown(dialog()!, 'Escape')