import { getFormValues, setFormValues } from '../../src'; import * as utils from '../utils' describe('hidden', () => { describe('basic', () => { beforeEach(utils.setup(` Hidden/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 })) .toString(); const after = utils.makeSearchParams(search) .toString(); expect(before) .toEqual(after); }, expectedStaticValue: { hello: 'Hi', }, }); }); }); describe('charset', () => { beforeEach(utils.setup(` Hidden/Charset
`)) it('should have extra value for character set', () => { utils.test({ actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { const before = utils.makeSearchParams(getFormValues(form, { submitter, includeCharset: true, })) .toString(); const after = utils.makeSearchParams(search) .toString(); expect(before) .toEqual(after); }, expectedStaticValue: { _charset_: 'UTF-8', }, }); }); it('should not be able to set extra value for character set', () => { utils.test({ onLoaded: (form: HTMLFormElement) => { setFormValues(form, { _charset_: 'Shift-JIS' }); }, actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { const before = utils.makeSearchParams(getFormValues(form, { submitter, includeCharset: true, })) .toString(); const after = utils.makeSearchParams(search) .toString(); expect(before) .toEqual(after); }, expectedStaticValue: { _charset_: 'UTF-8', }, }); }); }); describe('disabled', () => { beforeEach(utils.setup(` Hidden/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(` Hidden/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: 'Hi', }, }); }); }); describe('programmatic value setting', () => { beforeEach(utils.setup(` Hidden/Programmatic Value Setting
`)); it('should have form values set', () => { utils.test({ actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), onLoaded: (form: HTMLFormElement) => { setFormValues(form, { hello: 'Hi', }) }, 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: 'Hi', }, }); }); }); describe('duplicate', () => { beforeEach(utils.setup(` Hidden/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 })) .toString(); const after = utils.makeSearchParams(search) .toString(); expect(before) .toEqual(after); }, expectedStaticValue: { hello: ['value', 'another value'], }, }); }); it('should set both values', () => { utils.test({ onLoaded: (form: HTMLFormElement) => { setFormValues(form, { hello: ['new value 1', 'another value 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: ['new value 1', 'another value 2'], }, }); }); }); })