import { getFormValues, setFormValues } from '../../src'; import * as utils from '../utils' describe('time', () => { describe('basic', () => { beforeEach(utils.setup(` Time/Basic
`)) it('should have single form value', () => { utils.test({ querySubmitter: (cy: any) => cy.get('[type="submit"]'), onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { const before = utils.makeSearchParams(getFormValues(form, { submitter })) .toString(); const after = utils.makeSearchParams(search) .toString(); expect(before) .toEqual(after); }, expectedStaticValue: { hello: '13:37', }, }); }); }) describe('disabled', () => { beforeEach(utils.setup(` Time/Disabled
`)) it('should have blank form value', () => { utils.test({ querySubmitter: (cy: any) => cy.get('[type="submit"]'), onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { const before = utils.makeSearchParams(getFormValues(form, { submitter })) .toString(); const after = utils.makeSearchParams(search) .toString(); expect(before) .toEqual(after); }, expectedStaticValue: {}, }); }); }) describe('outside', () => { beforeEach(utils.setup(` Time/Outside
`)) it('should have single form value', () => { utils.test({ querySubmitter: (cy: any) => cy.get('[type="submit"]'), onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { const before = utils.makeSearchParams(getFormValues(form, { submitter })) .toString(); const after = utils.makeSearchParams(search) .toString(); expect(before) .toEqual(after); }, expectedStaticValue: { hello: '13:37', }, }); }); }); describe('readonly', () => { beforeEach(utils.setup(` Time/Readonly
`)) it('should have single form value', () => { utils.test({ querySubmitter: (cy: any) => cy.get('[type="submit"]'), onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { const before = utils.makeSearchParams(getFormValues(form, { submitter })) .toString(); const after = utils.makeSearchParams(search) .toString(); expect(before) .toEqual(after); }, expectedStaticValue: { hello: '13:37', }, }); }); }); describe('programmatic value setting', () => { beforeEach(utils.setup(` Time/Programmatic Value Setting
`)); it('should have form values set', () => { utils.test({ querySubmitter: (cy: any) => cy.get('[type="submit"]'), onLoaded: (form: HTMLFormElement) => { setFormValues(form, { hello: '13:37', }) }, onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { const before = utils.makeSearchParams(getFormValues(form, { submitter })) .toString(); const after = utils.makeSearchParams(search) .toString(); expect(before) .toEqual(after); }, expectedStaticValue: { hello: '13:37', }, }); }); }); describe('duplicate', () => { beforeEach(utils.setup(` Time/Duplicate
`)); it('should get both values', () => { utils.test({ querySubmitter: (cy: any) => cy.get('[type="submit"]'), onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { const before = utils.makeSearchParams(getFormValues(form, { submitter })) .toString(); const after = utils.makeSearchParams(search) .toString(); expect(before) .toEqual(after); }, expectedStaticValue: { hello: ['13:37', '06:09'], }, }); }); it('should set both values', () => { utils.test({ onLoaded: (form: HTMLFormElement) => { setFormValues(form, { hello: ['04:20', '05:30'], }) }, querySubmitter: (cy: any) => cy.get('[type="submit"]'), onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { const before = utils.makeSearchParams(getFormValues(form, { submitter })) .toString(); const after = utils.makeSearchParams(search) .toString(); expect(before) .toEqual(after); }, expectedStaticValue: { hello: ['04:20', '05:30'], }, }); }); }); })