test(36-02): update test fixtures for granular scopes and rebuild embedded admin dist
This commit is contained in:
@@ -23,6 +23,8 @@ const createdToken = {
|
||||
description: 'View everything',
|
||||
read_only: true,
|
||||
known: true,
|
||||
plugin_id: '',
|
||||
group: '',
|
||||
},
|
||||
],
|
||||
created_at: '2026-01-10T12:00:00Z',
|
||||
@@ -40,6 +42,8 @@ const scopes = [
|
||||
description: 'Everything',
|
||||
read_only: false,
|
||||
known: true,
|
||||
plugin_id: '',
|
||||
group: '',
|
||||
},
|
||||
{
|
||||
name: 'admin:read',
|
||||
@@ -47,6 +51,8 @@ const scopes = [
|
||||
description: 'View everything',
|
||||
read_only: true,
|
||||
known: true,
|
||||
plugin_id: '',
|
||||
group: '',
|
||||
},
|
||||
]
|
||||
|
||||
@@ -102,17 +108,9 @@ async function fillName(value: string): Promise<void> {
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
async function pickAdminRead(): Promise<void> {
|
||||
const scope = dialog()!.querySelector<HTMLInputElement>('[data-scope="admin:read"] input')!
|
||||
scope.checked = true
|
||||
scope.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
async function openCreateAtStep2(routes: Record<string, Route> = {}): Promise<void> {
|
||||
await openCreate(routes)
|
||||
await fillName('Agent')
|
||||
await pickAdminRead()
|
||||
await click('[data-action="create-token-submit"]', dialog()!)
|
||||
expect(dialog()!.querySelector<HTMLInputElement>('[data-token-plaintext]')!.value).toBe(PLAIN)
|
||||
}
|
||||
@@ -207,16 +205,15 @@ describe('ApiTokenCreateDialog step 1', () => {
|
||||
expect(document.activeElement).toBe(dialog()!.querySelector('#api-token-name'))
|
||||
})
|
||||
|
||||
it('shows scopes skeleton and disables submit while pending', async () => {
|
||||
it('shows scopes skeleton and disables submit while pending, then defaults to Read-only (D-08)', async () => {
|
||||
const pending = deferred()
|
||||
await openCreate({ [`GET ${SCOPES}`]: pending.route })
|
||||
expect(dialog()!.querySelector('[data-scope-picker]')!.querySelectorAll('[aria-hidden="true"]').length).toBe(3)
|
||||
expect(dialog()!.querySelector('[data-scope-loading]')).toBeTruthy()
|
||||
expect(dialog()!.querySelector<HTMLButtonElement>('[data-action="create-token-submit"]')!.disabled).toBe(true)
|
||||
pending.release(envelope(scopes))
|
||||
await flushPromises()
|
||||
expect(dialog()!.querySelector('[data-scope="admin:read"]')).toBeTruthy()
|
||||
// No scope selected yet — submit stays disabled (WR-02).
|
||||
expect(dialog()!.querySelector<HTMLButtonElement>('[data-action="create-token-submit"]')!.disabled).toBe(true)
|
||||
expect(dialog()!.querySelector('[data-access-tier="read_only"]')!.getAttribute('data-state')).toBe('checked')
|
||||
expect(dialog()!.querySelector<HTMLButtonElement>('[data-action="create-token-submit"]')!.disabled).toBe(false)
|
||||
})
|
||||
|
||||
it('shows scopes failure alert when the scopes request fails', async () => {
|
||||
@@ -233,26 +230,15 @@ describe('ApiTokenCreateDialog step 1', () => {
|
||||
expect(dialog()!.querySelector<HTMLButtonElement>('[data-action="create-token-submit"]')!.disabled).toBe(true)
|
||||
})
|
||||
|
||||
it('star checked disables others; unchecking restores without picks; no preselection', async () => {
|
||||
it('defaults to Read-only and switches cleanly to Full (*) with scope_all_includes note', async () => {
|
||||
await openCreate()
|
||||
const star = dialog()!.querySelector<HTMLInputElement>('[data-scope="*"] input')!
|
||||
const admin = dialog()!.querySelector<HTMLInputElement>('[data-scope="admin:read"] input')!
|
||||
expect(star.checked).toBe(false)
|
||||
expect(admin.checked).toBe(false)
|
||||
admin.checked = true
|
||||
admin.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
await flushPromises()
|
||||
star.checked = true
|
||||
star.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
await flushPromises()
|
||||
expect(admin.disabled).toBe(true)
|
||||
expect(admin.checked).toBe(false)
|
||||
expect(dialog()!.querySelector('[data-access-tier="read_only"]')!.getAttribute('data-state')).toBe('checked')
|
||||
expect(dialog()!.querySelector('[data-scope-all-note]')).toBeNull()
|
||||
await click('[data-access-tier="full"]', dialog()!)
|
||||
expect(dialog()!.querySelector('[data-access-tier="full"]')!.getAttribute('data-state')).toBe('checked')
|
||||
expect(dialog()!.textContent).toContain('Pełny dostęp obejmuje wszystkie pozostałe zakresy.')
|
||||
star.checked = false
|
||||
star.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
await flushPromises()
|
||||
expect(admin.disabled).toBe(false)
|
||||
expect(admin.checked).toBe(false)
|
||||
await click('[data-access-tier="read_only"]', dialog()!)
|
||||
expect(dialog()!.querySelector('[data-scope-all-note]')).toBeNull()
|
||||
})
|
||||
|
||||
it('preselects 90d and previews 30, 90, 365 and never', async () => {
|
||||
@@ -292,7 +278,6 @@ describe('ApiTokenCreateDialog step 1', () => {
|
||||
},
|
||||
},
|
||||
})
|
||||
await pickAdminRead()
|
||||
await click('[data-action="create-token-submit"]', dialog()!)
|
||||
expect(dialog()!.textContent).toContain('Podaj nazwę tokenu.')
|
||||
expect(dialog()!.querySelector('#api-token-name')!.getAttribute('aria-invalid')).toBe('true')
|
||||
@@ -309,7 +294,6 @@ describe('ApiTokenCreateDialog step 1', () => {
|
||||
},
|
||||
})
|
||||
await fillName('Busy')
|
||||
await pickAdminRead()
|
||||
const submit = dialog()!.querySelector<HTMLButtonElement>('[data-action="create-token-submit"]')!
|
||||
submit.click()
|
||||
await flushPromises()
|
||||
@@ -341,7 +325,6 @@ describe('ApiTokenCreateDialog step 1', () => {
|
||||
},
|
||||
})
|
||||
await fillName('Keep me')
|
||||
await pickAdminRead()
|
||||
await click('[data-action="create-token-submit"]', dialog()!)
|
||||
expect(toasts.value[0]).toMatchObject({
|
||||
text: 'Nie udało się utworzyć tokenu. Spróbuj ponownie.',
|
||||
@@ -358,7 +341,6 @@ describe('ApiTokenCreateDialog step 1', () => {
|
||||
it('posts selected scopes and never leaves plaintext after Done', async () => {
|
||||
const { calls } = await openCreate()
|
||||
await fillName('CI')
|
||||
await pickAdminRead()
|
||||
await click('[data-action="create-token-submit"]', dialog()!)
|
||||
const [post] = requestsTo(calls, 'POST', TOKENS)
|
||||
expect(await post!.clone().json()).toEqual({
|
||||
@@ -468,18 +450,17 @@ describe('ApiTokenCreateDialog mounted directly', () => {
|
||||
return { wrapper, calls }
|
||||
}
|
||||
|
||||
it('opens with the scopes from one GET', async () => {
|
||||
it('opens with the scopes from one GET and selects Read-only by default', async () => {
|
||||
const { calls } = await openDialog()
|
||||
expect(dialog()).toBeTruthy()
|
||||
expect(requestsTo(calls, 'GET', SCOPES)).toHaveLength(1)
|
||||
expect(dialog()!.querySelector('[data-scope="*"]')).toBeTruthy()
|
||||
expect(dialog()!.querySelector('[data-scope="admin:read"]')).toBeTruthy()
|
||||
expect(dialog()!.querySelector('[data-access-tier="full"]')).toBeTruthy()
|
||||
expect(dialog()!.querySelector('[data-access-tier="read_only"]')!.getAttribute('data-state')).toBe('checked')
|
||||
})
|
||||
|
||||
it('creates a token with one POST, shows the plaintext and emits created', async () => {
|
||||
const { wrapper, calls } = await openDialog()
|
||||
await fillName('CI runner')
|
||||
await pickAdminRead()
|
||||
await click('[data-action="create-token-submit"]', dialog()!)
|
||||
|
||||
const posts = requestsTo(calls, 'POST', TOKENS)
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user