Files
summercms/admin/tests/app/runtime.test.ts
Jakub Zych 1c2a66df45 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
2026-09-27 17:53:57 +02:00

42 lines
1.3 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { DEFAULT_BASE, readBase, runtime } from '../../src/app/runtime'
function docWith(content: string | null): Document {
const doc = document.implementation.createHTMLDocument('test')
if (content !== null) {
const meta = doc.createElement('meta')
meta.setAttribute('name', 'summer-admin-base')
meta.setAttribute('content', content)
doc.head.appendChild(meta)
}
return doc
}
describe('runtime base', () => {
it('derives the router base and the API base from the served meta', () => {
expect(runtime.base).toBe('/admin-test')
expect(runtime.api).toBe('/admin-test/api/v1')
})
it('reads a custom prefix and trims trailing slashes and whitespace', () => {
expect(readBase(docWith('/acp'))).toBe('/acp')
expect(readBase(docWith(' /acp/panel// '))).toBe('/acp/panel')
})
it.each([
['a missing meta', null],
['an empty value', ''],
['the unreplaced build token', '__SUMMER_ADMIN_BASE__'],
['a relative path', 'backend'],
['an absolute URL', 'https://evil.example/backend'],
['the root alone', '/'],
['slashes only', '///'],
])('falls back to the default for %s', (_label, content) => {
expect(readBase(docWith(content))).toBe(DEFAULT_BASE)
})
it('uses /backend as the default', () => {
expect(DEFAULT_BASE).toBe('/backend')
})
})