test(admin): mail template locale switcher
- LocaleVariantSwitcher: current flag, option values and locales, the label through the control id, the query kept on navigation, no navigation for the open version, selection restored when a guard throws, props updates - FormView: no switcher with one variant; with unsaved edits switching asks the unsaved-changes confirm, stays on cancel and opens the sibling on confirm - check-phase35.sh requires LocaleVariantSwitcher.test.ts (ADMIN_FILES)
This commit is contained in:
@@ -125,6 +125,57 @@ describe('FormView mail footer actions and meta.deletable', () => {
|
||||
|
||||
const none = await mountApp('/summercms/cabana/mailtemplates/7', routes())
|
||||
expect(none.wrapper.find('[data-locale-variant]').exists()).toBe(false)
|
||||
|
||||
const one = await mountApp(
|
||||
'/summercms/cabana/mailtemplates/7',
|
||||
routes({
|
||||
[`GET ${RECORD}`]: mailRecord({
|
||||
localeVariants: [{ id: 7, locale: '', label: 'Default', states: [], current: true }],
|
||||
}),
|
||||
}),
|
||||
)
|
||||
expect(one.wrapper.find('[data-locale-variant]').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('asks the unsaved-changes confirm before switching locale and stays on cancel', async () => {
|
||||
const localeVariants = [
|
||||
{ id: 7, locale: '', label: 'Default', states: [], current: true },
|
||||
{ id: 9, locale: 'de', label: 'de', states: [], current: false },
|
||||
]
|
||||
const sibling = clone(recordFixture)
|
||||
sibling.data = { id: 9, subject: 'Hallo', body: 'Body' }
|
||||
sibling.meta = {
|
||||
...sibling.meta,
|
||||
actions: [],
|
||||
deletable: false,
|
||||
localeVariants: localeVariants.map((variant) => ({ ...variant, current: variant.id === 9 })),
|
||||
}
|
||||
const { wrapper, router, calls } = await mountApp(
|
||||
'/summercms/cabana/mailtemplates/7',
|
||||
routes({
|
||||
[`GET ${RECORD}`]: mailRecord({ actions: [], localeVariants }),
|
||||
[`GET ${BASE}/9`]: { body: sibling },
|
||||
}),
|
||||
)
|
||||
await wrapper.find('#field-subject').setValue('Changed')
|
||||
const select = wrapper.find<HTMLSelectElement>('header select[data-locale-variant]')
|
||||
await select.setValue('9')
|
||||
await flushPromises()
|
||||
const dialog = document.body.querySelector<HTMLElement>('[data-confirm-dialog]')
|
||||
expect(dialog?.textContent).toContain(langFixture.data['backend::lang.form.unsaved_confirm']!.other)
|
||||
dialog!.querySelector<HTMLButtonElement>('[data-action="cancel"]')!.click()
|
||||
await flushPromises()
|
||||
expect(router.currentRoute.value.fullPath).toBe('/summercms/cabana/mailtemplates/7')
|
||||
expect(select.element.value).toBe('7')
|
||||
expect((wrapper.find('#field-subject').element as HTMLInputElement).value).toBe('Changed')
|
||||
expect(calls.some((request) => request.method === 'GET' && request.url.endsWith('/mailtemplates/9'))).toBe(false)
|
||||
|
||||
await select.setValue('9')
|
||||
await flushPromises()
|
||||
document.body.querySelector<HTMLButtonElement>('[data-confirm-dialog] [data-action="confirm"]')!.click()
|
||||
await flushPromises()
|
||||
expect(router.currentRoute.value.fullPath).toBe('/summercms/cabana/mailtemplates/9')
|
||||
expect(calls.some((request) => request.method === 'GET' && request.url.endsWith('/mailtemplates/9'))).toBe(true)
|
||||
})
|
||||
|
||||
it('toasts 403 and 409 paths from record actions', async () => {
|
||||
|
||||
Reference in New Issue
Block a user