test(12.1-05): unit tests for the list, form, preview and routing behaviours of Phase 12.1 in the SPA
- list: the bulk menu in the toolbar and on the list view with its three failure rows, row states and invisible columns in the table - form: the forbidden banner, password and preset on the form view, locked relation options, the save body of password and permission fields - preview view: context fields, hidden tabs, the status hint, the footer with zero, one and several actions, load failures - routing: the preview route and mapWinterUrl - backstops: focus returns to the bulk menu trigger; preview URL mapping and the route replacement; locked relation options - the slug preset runs on the table the user plugin's slug test uses
This commit is contained in:
@@ -4,7 +4,7 @@ import { activateStyles, loadStyles } from '../../src/app/pluginAssets'
|
||||
import { createAdminRouter, routeControllerId, safeRedirect } from '../../src/app/router'
|
||||
import { setNavigation } from '../../src/state/useNavigation'
|
||||
import { navigationFixture } from '../fixtures/typed'
|
||||
import { resetState, routerAt, signIn } from '../helpers'
|
||||
import { mockApi, resetState, routerAt, signIn } from '../helpers'
|
||||
|
||||
beforeEach(() => {
|
||||
resetState()
|
||||
@@ -149,3 +149,37 @@ describe('plugin stylesheets follow the route (D-16, T-10.1-16)', () => {
|
||||
expect(enabled()).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('preview route (UI-SPEC S3, D-11)', () => {
|
||||
it('names the preview route for a numeric id only and keeps it inside the shell', async () => {
|
||||
await signIn()
|
||||
const preview = await routerAt('/acme/demo/widgets/12/preview')
|
||||
expect(preview.currentRoute.value.name).toBe('preview')
|
||||
expect(preview.currentRoute.value.params).toMatchObject({ vendor: 'acme', plugin: 'demo', controller: 'widgets', id: '12' })
|
||||
expect(preview.currentRoute.value.meta.shell).toBe(true)
|
||||
for (const path of ['/acme/demo/widgets/abc/preview', '/acme/demo/widgets/1e3/preview', '/acme/demo/widgets/12/preview/extra', '/acme/demo/widgets/-1/preview']) {
|
||||
expect((await routerAt(path)).currentRoute.value.name, path).toBe('not-found')
|
||||
}
|
||||
})
|
||||
|
||||
it('counts preview among the controller routes, so plugin assets follow it', async () => {
|
||||
await signIn()
|
||||
// CONTROLLER_ROUTES holds list, create, record and preview: each of them
|
||||
// answers its controller id, and no other route does.
|
||||
for (const path of ['/acme/demo/widgets', '/acme/demo/widgets/create', '/acme/demo/widgets/12', '/acme/demo/widgets/12/preview']) {
|
||||
expect(routeControllerId((await routerAt(path)).currentRoute.value), path).toBe('acme.demo.widgets')
|
||||
}
|
||||
for (const path of ['/settings', '/settings/mail', '/nowhere', '/acme/demo/widgets/abc/preview']) {
|
||||
expect(routeControllerId((await routerAt(path)).currentRoute.value), path).toBeFalsy()
|
||||
}
|
||||
})
|
||||
|
||||
it('requires a signed-in admin for the preview route and returns to it after login', async () => {
|
||||
mockApi({})
|
||||
const router = createAdminRouter(createMemoryHistory())
|
||||
await router.push('/acme/demo/widgets/12/preview')
|
||||
expect(router.currentRoute.value.name).toBe('login')
|
||||
expect(router.currentRoute.value.query.redirect).toBe('/acme/demo/widgets/12/preview')
|
||||
expect(safeRedirect(router.currentRoute.value.query.redirect)).toBe('/acme/demo/widgets/12/preview')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user