import { getFormValues, setFormValues } from '../../src';
import * as utils from '../utils'
describe('email', () => {
describe('basic', () => {
beforeEach(utils.setup(`
Email/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: 'email@example.com',
},
});
});
});
describe('disabled', () => {
beforeEach(utils.setup(`
Email/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(`
Email/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: 'email@example.com',
},
});
});
});
describe('readonly', () => {
beforeEach(utils.setup(`
Email/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: 'email@example.com',
},
});
});
});
describe('programmatic value setting', () => {
beforeEach(utils.setup(`
Email/Programmatic Value Setting
`));
it('should have form values set', () => {
utils.test({
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: 'email@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: 'email@example.com',
},
});
});
});
describe('duplicate', () => {
beforeEach(utils.setup(`
Email/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: ['email@example.com', 'peppy@example.com'],
},
});
});
it('should set both values', () => {
utils.test({
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, {
hello: ['poppy@example.com', 'pumpkin@example.com'],
})
},
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: ['poppy@example.com', 'pumpkin@example.com'],
},
});
});
});
})