/* eslint-disable @typescript-eslint/no-explicit-any */ import assert from 'assert'; import { renderForm } from '../../test-utils/renderForm'; const known = { key: 'sectionKnown', type: 'radio', input: true, label: 'Known?', clearOnHide: true, persistent: true, values: [{ label: 'Yes', value: 'yes' }, { label: 'No', value: 'no' }], }; const section = { key: 'section', type: 'container', input: true, tree: true, label: 'Section', clearOnHide: true, customConditional: 'show = (row.sectionKnown === "yes") ? true : false', components: [{ key: 'name', type: 'textfield', input: true, label: 'Name', clearOnHide: true, persistent: true }], }; const other = { key: 'other', type: 'textfield', input: true, label: 'Other', clearOnHide: true, persistent: true }; const schema = { display: 'form', components: [{ key: 'tabs', type: 'tabs', input: false, components: [ { key: 'tab0', label: 'Tab 0', components: [known, section] }, { key: 'tab1', label: 'Tab 1', components: [other] }, ], }], }; const settle = (): Promise => new Promise((resolve) => setTimeout(resolve, 300)); describe('real form: container revealed by the user keeps its data across tab switches', () => { it('attaches the container data when revealed, and keeps typed values after switching tabs', async function () { this.timeout(20000); const { form, destroy } = await renderForm(schema); try { form.getComponent('sectionKnown').setValue('yes'); await settle(); form.getComponent('name').setValue('Example'); await settle(); assert.deepStrictEqual(form.data.section, { name: 'Example' }, 'typed value missing from form data'); const tabs = form.getComponent('tabs'); for (let i = 0; i < 2; i++) { tabs.setTab(1); await settle(); tabs.setTab(0); await settle(); assert.deepStrictEqual( form.data.section, { name: 'Example' }, `section data lost or altered on tab switch ${i + 1}`, ); } } finally { destroy(); } }); });