test(admin): import the untested SPA modules directly for check-phase10 hygiene
- mlLocale: type predicates, localeRecord, the ML_LOCALE_CHANGE broadcast - MLField: locale switch, whole-map emit, broadcast follow, content-locale - FileCaptionModal: prefill, save via FileRoutes.update, 422 stays, danger toast - ApiTokensPanel and ApiTokenCreateDialog mounted directly next to the app tests
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { enableAutoUnmount, flushPromises } from '@vue/test-utils'
|
||||
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
|
||||
import ApiTokensPanel from '../../src/components/account/ApiTokensPanel.vue'
|
||||
import { useConfirm } from '../../src/components/ui/confirm'
|
||||
import { toasts } from '../../src/state/useToasts'
|
||||
import { API, keydown, mountApp, queryOf, requestsTo, resetState, type Reply, type Route } from '../helpers'
|
||||
import { API, keydown, mockApi, mountApp, queryOf, requestsTo, resetState, type Reply, type Route } from '../helpers'
|
||||
|
||||
const TOKENS = `${API}/account/tokens`
|
||||
const SCOPES = `${API}/account/tokens/scopes`
|
||||
@@ -471,3 +473,38 @@ describe('ApiTokensPanel', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('ApiTokensPanel mounted directly', () => {
|
||||
async function mountPanel(list: Route) {
|
||||
const calls = mockApi({ [`GET ${TOKENS}`]: list, [`GET ${SCOPES}`]: envelope(scopes) })
|
||||
const wrapper = mount(ApiTokensPanel, { props: { confirm: useConfirm() }, attachTo: document.body })
|
||||
await flushPromises()
|
||||
return { wrapper, calls }
|
||||
}
|
||||
|
||||
it('lists the tokens from one GET', async () => {
|
||||
const { wrapper, calls } = await mountPanel(envelope([existingToken]))
|
||||
const row = wrapper.find('[data-token-row="11"]')
|
||||
expect(row.exists()).toBe(true)
|
||||
expect(row.text()).toContain('Blog agent')
|
||||
expect(wrapper.find('[data-tokens-empty]').exists()).toBe(false)
|
||||
expect(requestsTo(calls, 'GET', TOKENS)).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('shows the empty block for an empty list', async () => {
|
||||
const { wrapper, calls } = await mountPanel(envelope([]))
|
||||
expect(wrapper.find('[data-tokens-empty]').exists()).toBe(true)
|
||||
expect(wrapper.find('[data-token-row]').exists()).toBe(false)
|
||||
expect(requestsTo(calls, 'GET', TOKENS)).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('shows the error block when the list fails', async () => {
|
||||
const { wrapper, calls } = await mountPanel({
|
||||
status: 500,
|
||||
body: { error: { code: 'internal', message: 'fail', details: {} } },
|
||||
})
|
||||
expect(wrapper.find('[data-tokens-error]').exists()).toBe(true)
|
||||
expect(wrapper.find('[data-token-row]').exists()).toBe(false)
|
||||
expect(requestsTo(calls, 'GET', TOKENS)).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user