test(32-01): FormView renders compiled extension order
- an extension field between two owner fields renders in the order cabana sends (UI-SPEC C1) - a tab-less form with an extension tab renders the default tab, then the new one; admin/src is unchanged
This commit is contained in:
@@ -960,3 +960,35 @@ describe('picked relation labels across tab remount', () => {
|
||||
expect((maker().element as HTMLInputElement).value).not.toBe('1')
|
||||
})
|
||||
})
|
||||
|
||||
describe('form extensions in compiled order (UI-SPEC C1, D-91)', () => {
|
||||
/** The untabbed schema with an extension field cloned from name and placed by the server. */
|
||||
function extendedSchema(place: (fields: ReturnType<typeof flatSchema>['body']['data']['fields'], field: (typeof formSchemaFixture)['data']['fields'][number]) => void) {
|
||||
const schema = flatSchema()
|
||||
const source = schema.body.data.fields.find((field) => field.name === 'name')!
|
||||
const extension = { ...clone(source), name: 'subtitle', label: 'Subtitle' }
|
||||
place(schema.body.data.fields, extension)
|
||||
return schema
|
||||
}
|
||||
|
||||
it('renders an extension field between two owner fields in compiled order', async () => {
|
||||
// cabana compiled "subtitle after name": the SPA keeps the order it receives.
|
||||
const schema = extendedSchema((fields, extension) => fields.splice(1, 0, extension))
|
||||
const { wrapper } = await mountApp('/acme/demo/widgets/1', routes({ [`GET ${BASE}/schema/form`]: schema }))
|
||||
expect(wrapper.findAll('[data-field]').map((field) => field.attributes('data-field'))).toEqual(['name', 'subtitle', 'code', 'weight'])
|
||||
expect(wrapper.find('[role="tablist"]').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('a tab-less form with an extension tab renders Basic, then the new tab', async () => {
|
||||
const schema = extendedSchema((fields, extension) => fields.push({ ...extension, tab: 'Publishing' }))
|
||||
const { wrapper } = await mountApp('/acme/demo/widgets/1', routes({ [`GET ${BASE}/schema/form`]: schema }))
|
||||
const tabs = wrapper.findAll('[role="tab"]')
|
||||
expect(tabs.map((tab) => tab.attributes('data-tab'))).toEqual(['default', 'tab:Publishing'])
|
||||
expect(tabs[0]!.text()).toContain('Podstawowe')
|
||||
expect(tabs[1]!.text()).toContain('Publishing')
|
||||
expect(wrapper.findAll('[data-field]').map((field) => field.attributes('data-field'))).toEqual(['name', 'code', 'weight'])
|
||||
await tabs[1]!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.findAll('[data-field]').map((field) => field.attributes('data-field'))).toEqual(['subtitle'])
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user