test(10-05): bring every SPA module, composable and component under Vitest
- 41 unit and component suites under admin/tests/{app,state,shell,list,form,relation,views,ui}
covering states and a11y roles; every src module is imported by a test
- typed fixture helper assigns each JSON fixture to its generated OpenAPI type
- fix: iconFor ignores inherited object members such as "constructor"
- fix: field controls import ./control instead of the registry (import cycle
left a renderer unregistered depending on module load order)
- fix: dropdown shows the placeholder for an unknown stored value next to an emptyOption
- fix: list announces a failed schema load even when the rows arrive after it
- tailwind no longer scans admin/tests; boardwalk/dist rebuilt
This commit is contained in:
58
admin/tests/shell/SectionPanel.test.ts
Normal file
58
admin/tests/shell/SectionPanel.test.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
|
||||
import SectionPanel from '../../src/components/shell/SectionPanel.vue'
|
||||
import { SIDEBAR_KEY, setCollapsed, sidebarCollapsed } from '../../src/state/useSidebar'
|
||||
import { clone, navigationFixture } from '../fixtures/typed'
|
||||
import { resetState, routerAt, signIn } from '../helpers'
|
||||
|
||||
beforeEach(() => {
|
||||
resetState()
|
||||
setCollapsed(false)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
setCollapsed(false)
|
||||
document.body.innerHTML = ''
|
||||
})
|
||||
|
||||
enableAutoUnmount(afterEach)
|
||||
|
||||
async function mountPanel(path: string, entry = navigationFixture.data[0]!) {
|
||||
await signIn()
|
||||
const router = await routerAt(path)
|
||||
const wrapper = mount(SectionPanel, { props: { entry }, global: { plugins: [router] }, attachTo: document.body })
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
describe('section panel', () => {
|
||||
it('is a labelled region with the plugin label and its permitted side menu', async () => {
|
||||
const wrapper = await mountPanel('/acme/demo/gadgets/4')
|
||||
expect(wrapper.find('aside').attributes('aria-label')).toBe('Sekcje')
|
||||
expect(wrapper.find('aside span').text()).toBe('Demo')
|
||||
const links = wrapper.findAll('a')
|
||||
expect(links.map((link) => [link.text(), link.attributes('href')])).toEqual([
|
||||
['Widgets', '/acme/demo/widgets'],
|
||||
['Gadgets', '/acme/demo/gadgets'],
|
||||
])
|
||||
expect(links[0]!.attributes('aria-current')).toBeUndefined()
|
||||
expect(links[1]!.attributes('aria-current')).toBe('page')
|
||||
})
|
||||
|
||||
it('skips side-menu items whose controller id is invalid', async () => {
|
||||
const entry = clone(navigationFixture.data[0]!)
|
||||
entry.sideMenu[0]!.controller = 'not a controller'
|
||||
const wrapper = await mountPanel('/acme/demo/gadgets', entry)
|
||||
expect(wrapper.findAll('a').map((link) => link.text())).toEqual(['Gadgets'])
|
||||
})
|
||||
|
||||
it('collapses on "Zwiń menu" and persists the choice', async () => {
|
||||
const wrapper = await mountPanel('/acme/demo/widgets')
|
||||
const button = wrapper.find('[data-sidebar-collapse]')
|
||||
expect(button.attributes('aria-label')).toBe('Zwiń menu')
|
||||
expect(button.attributes('type')).toBe('button')
|
||||
await button.trigger('click')
|
||||
expect(sidebarCollapsed.value).toBe(true)
|
||||
expect(window.localStorage.getItem(SIDEBAR_KEY)).toBe('true')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user