fix(10.1): WR-02 disable plugin stylesheets on screens that are not controller views
The router now drives stylesheet activation after every confirmed navigation: the list, create and record routes enable their controller's links, and settings, login, not-found and a controller whose schema has not arrived yet enable none. Rebuilt the embedded admin dist.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { beforeEach, describe, expect, it } from 'vitest'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createMemoryHistory } from 'vue-router'
|
||||
import { createAdminRouter, safeRedirect } from '../../src/app/router'
|
||||
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'
|
||||
@@ -93,3 +94,58 @@ describe('route guard', () => {
|
||||
expect((await routerAt('/acme/demo/widgets/12')).currentRoute.value.params.id).toBe('12')
|
||||
})
|
||||
})
|
||||
|
||||
describe('plugin stylesheets follow the route (D-16, T-10.1-16)', () => {
|
||||
let links: HTMLLinkElement[]
|
||||
|
||||
beforeEach(() => {
|
||||
links = []
|
||||
const head = document.head
|
||||
const append = head.appendChild.bind(head)
|
||||
vi.spyOn(head, 'appendChild').mockImplementation(<T extends Node>(node: T): T => {
|
||||
if (node instanceof HTMLLinkElement) {
|
||||
links.push(node)
|
||||
return node
|
||||
}
|
||||
return append(node)
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
activateStyles('')
|
||||
})
|
||||
|
||||
const enabled = () => links.filter((link) => !link.disabled).map((link) => link.getAttribute('data-summer-controller'))
|
||||
|
||||
it('names the controller of list, create and record routes only', async () => {
|
||||
await signIn()
|
||||
expect(routeControllerId((await routerAt('/acme/demo/widgets')).currentRoute.value)).toBe('acme.demo.widgets')
|
||||
expect(routeControllerId((await routerAt('/acme/demo/widgets/create')).currentRoute.value)).toBe('acme.demo.widgets')
|
||||
expect(routeControllerId((await routerAt('/acme/demo/widgets/12')).currentRoute.value)).toBe('acme.demo.widgets')
|
||||
for (const path of ['/settings', '/settings/mail', '/nowhere', '/acme/demo/widgets/abc']) {
|
||||
expect(routeControllerId((await routerAt(path)).currentRoute.value), path).toBe('')
|
||||
}
|
||||
expect(routeControllerId((await routerAt('/login')).currentRoute.value)).toBe('')
|
||||
})
|
||||
|
||||
it('disables every plugin stylesheet on screens that are not controller views', async () => {
|
||||
await signIn()
|
||||
loadStyles('acme.demo.widgets', ['/admin-test/assets/acme/demo/css/route-widgets.css'])
|
||||
loadStyles('acme.demo.gadgets', ['/admin-test/assets/acme/demo/css/route-gadgets.css'])
|
||||
const router = await routerAt('/acme/demo/widgets')
|
||||
expect(enabled()).toEqual(['acme.demo.widgets'])
|
||||
|
||||
for (const path of ['/settings', '/settings/mail', '/nowhere']) {
|
||||
await router.push(path)
|
||||
expect(enabled(), path).toEqual([])
|
||||
}
|
||||
|
||||
await router.push('/acme/demo/gadgets/create')
|
||||
expect(enabled()).toEqual(['acme.demo.gadgets'])
|
||||
// Opening another controller whose schema has not arrived yet already
|
||||
// hides the previous controller's stylesheets.
|
||||
await router.push('/acme/demo/sprockets')
|
||||
expect(enabled()).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user