- config_form.yaml preview block (optional headerPartial), reported in the form schema as preview
- fields with context: preview show only on the preview screen and are never written
- form messages preview and edit; recordActions without a preview block stops boot
- SPA route {id}/preview, PreviewView and PreviewField, record actions in the footer
- mapWinterUrl maps preview/:id; the update form returns to the preview
- summer-callout partial style classes for status hints
- README, docs, OpenAPI document, TS types and the embedded build updated
62 lines
3.0 KiB
TypeScript
62 lines
3.0 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { mapWinterUrl } from '../../src/app/winterUrl'
|
|
|
|
const ID = 'acme.demo.widgets'
|
|
const LIST = '/acme/demo/widgets'
|
|
|
|
describe('mapWinterUrl', () => {
|
|
it('maps an empty, null or missing URL to the list', () => {
|
|
expect(mapWinterUrl('', ID)).toBe(LIST)
|
|
expect(mapWinterUrl(null, ID)).toBe(LIST)
|
|
expect(mapWinterUrl(undefined, ID)).toBe(LIST)
|
|
expect(mapWinterUrl(' ', ID)).toBe(LIST)
|
|
})
|
|
|
|
it('maps the controller root and create', () => {
|
|
expect(mapWinterUrl('acme/demo/widgets', ID)).toBe(LIST)
|
|
expect(mapWinterUrl('/acme/demo/widgets/', ID)).toBe(LIST)
|
|
expect(mapWinterUrl('acme/demo/widgets/create', ID)).toBe(`${LIST}/create`)
|
|
})
|
|
|
|
it('substitutes :id in update/:id and accepts a literal numeric id', () => {
|
|
expect(mapWinterUrl('acme/demo/widgets/update/:id', ID, 42)).toBe(`${LIST}/42`)
|
|
expect(mapWinterUrl('acme/demo/widgets/update/:id', ID, '7')).toBe(`${LIST}/7`)
|
|
expect(mapWinterUrl('acme/demo/widgets/update/9', ID)).toBe(`${LIST}/9`)
|
|
})
|
|
|
|
it('substitutes :id in preview/:id and falls back to the list without a usable id (D-11)', () => {
|
|
expect(mapWinterUrl('acme/demo/widgets/preview/:id', ID, 42)).toBe(`${LIST}/42/preview`)
|
|
expect(mapWinterUrl('acme/demo/widgets/preview/9', ID)).toBe(`${LIST}/9/preview`)
|
|
expect(mapWinterUrl('acme/demo/widgets/preview/:id', ID)).toBe(LIST)
|
|
expect(mapWinterUrl('acme/demo/widgets/preview/abc', ID)).toBe(LIST)
|
|
expect(mapWinterUrl('acme/demo/gadgets/preview/:id', ID, 1)).toBe(LIST)
|
|
})
|
|
|
|
it('falls back to the list when update has no usable id', () => {
|
|
expect(mapWinterUrl('acme/demo/widgets/update/:id', ID)).toBe(LIST)
|
|
expect(mapWinterUrl('acme/demo/widgets/update/:id', ID, null)).toBe(LIST)
|
|
expect(mapWinterUrl('acme/demo/widgets/update/:id', ID, 'abc')).toBe(LIST)
|
|
expect(mapWinterUrl('acme/demo/widgets/update/1e3', ID)).toBe(LIST)
|
|
})
|
|
|
|
it('never leaves the current controller for a foreign or absolute URL (T-10-20)', () => {
|
|
expect(mapWinterUrl('acme/demo/gadgets/update/:id', ID, 1)).toBe(LIST)
|
|
expect(mapWinterUrl('https://evil.example/acme/demo/widgets/create', ID)).toBe(LIST)
|
|
expect(mapWinterUrl('//evil.example/x', ID)).toBe(LIST)
|
|
expect(mapWinterUrl('javascript:alert(1)', ID)).toBe(LIST)
|
|
})
|
|
|
|
it('ignores the query and hash, matches the owner case-insensitively and rejects unknown actions', () => {
|
|
expect(mapWinterUrl('acme/demo/widgets/create?x=1#top', ID)).toBe(`${LIST}/create`)
|
|
expect(mapWinterUrl('Acme/Demo/Widgets/update/:id', ID, 3)).toBe(`${LIST}/3`)
|
|
expect(mapWinterUrl('acme/demo/widgets/history/3', ID)).toBe(LIST)
|
|
expect(mapWinterUrl('acme/demo/widgets/update/3/extra', ID)).toBe(LIST)
|
|
expect(mapWinterUrl('acme/demo/widgets/CREATE', ID)).toBe(LIST)
|
|
})
|
|
|
|
it('answers the root for a malformed controller id', () => {
|
|
expect(mapWinterUrl('acme/demo/widgets', 'acme.demo')).toBe('/')
|
|
expect(mapWinterUrl('acme/demo/widgets', 'acme.demo.wid gets')).toBe('/')
|
|
})
|
|
})
|