import { getFormValues, setFormValues } from '../../src'; import * as utils from '../utils' describe('url', () => { describe('basic', () => { beforeEach(utils.setup(` URL/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: 'https://www.example.com', }, }); }); }); describe('disabled', () => { beforeEach(utils.setup(` URL/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(` URL/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: 'https://www.example.com', }, }); }); }); describe('readonly', () => { beforeEach(utils.setup(` URL/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: 'https://www.example.com', }, }); }); }); describe('programmatic value setting', () => { beforeEach(utils.setup(` URL/Programmatic Value Setting
`)); it('should have form values set', () => { utils.test({ actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), onLoaded: (form: HTMLFormElement) => { setFormValues(form, { hello: 'https://www.example.com', }) }, 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: 'https://www.example.com', }, }); }); }); describe('duplicate', () => { beforeEach(utils.setup(` URL/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: ['https://www.example.com', 'https://acme.example.com'], }, }); }); it('should set both values', () => { utils.test({ onLoaded: (form: HTMLFormElement) => { setFormValues(form, { hello: ['https://foo.example.com', 'https://bar.example.com/context'], }) }, 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: ['https://foo.example.com', 'https://bar.example.com/context'], }, }); }); }); })