import { getFormValues, setFormValues } from '../../src'; import * as utils from '../utils' describe('number', () => { describe('basic', () => { beforeEach(utils.setup(` Number/Basic
`)) it('should have single form value', () => { utils.test({ actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { const before = utils.makeSearchParams(getFormValues(form, { submitter, forceNumberValues: true, })) .toString(); const after = utils.makeSearchParams(search) .toString(); expect(before) .toEqual(after); }, expectedStaticValue: { hello: '5', }, }); }); }) describe('disabled', () => { beforeEach(utils.setup(` Number/Disabled
`)) it('should have blank form value', () => { utils.test({ actionBeforeSubmit: (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(` Number/Outside
`)) it('should have single form value', () => { utils.test({ actionBeforeSubmit: (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: '5', }, }); }); }); describe('readonly', () => { beforeEach(utils.setup(` Number/Readonly
`)) it('should have single form value', () => { utils.test({ actionBeforeSubmit: (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: '5', }, }); }); }); describe('programmatic value setting', () => { beforeEach(utils.setup(` Number/Programmatic Value Setting
`)); it('should have form values set', () => { utils.test({ actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), onLoaded: (form: HTMLFormElement) => { setFormValues(form, { hello: 5, }) }, onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { const before = utils.makeSearchParams(getFormValues(form, { submitter, forceNumberValues: true, })) .toString(); const after = utils.makeSearchParams(search) .toString(); expect(before) .toEqual(after); }, expectedStaticValue: { hello: '5', }, }); }); }); describe('duplicate', () => { beforeEach(utils.setup(` Number/Duplicate
`)); it('should get both values', () => { utils.test({ actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { const before = utils.makeSearchParams(getFormValues(form, { submitter, forceNumberValues: true, })) .toString(); const after = utils.makeSearchParams(search) .toString(); expect(before) .toEqual(after); }, expectedStaticValue: { hello: ['5', '7'], }, }); }); it('should set both values', () => { utils.test({ onLoaded: (form: HTMLFormElement) => { setFormValues(form, { hello: [4, 2], }) }, actionBeforeSubmit: (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: ['4', '2'], }, }); }); }); })