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)
|
||||
|
||||
Reference in New Issue
Block a user