import { getFormValues, setFormValues } from '../../src';
import * as utils from '../utils'
describe('search', () => {
describe('basic', () => {
beforeEach(utils.setup(`
Search/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: 'Hi',
},
});
});
});
describe('dirname', () => {
beforeEach(utils.setup(`
Search/Dirname
`))
it('should have extra value for directionality', () => {
utils.test({
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter, includeDirectionality: true, }))
.toString();
const after = utils.makeSearchParams(search)
.toString();
expect(before)
.toEqual(after);
},
expectedStaticValue: {
hello: 'Hi',
'hello.dir': 'ltr',
},
});
});
it('should support other directionality', () => {
utils.test({
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
document.getElementsByTagName('input')[0].style.direction = 'rtl';
const before = utils.makeSearchParams(getFormValues(form, { submitter, includeDirectionality: true, }))
.toString();
const after = utils.makeSearchParams(search)
.toString();
expect(before)
.toEqual(after);
},
expectedStaticValue: {
hello: 'Hi',
'hello.dir': 'rtl',
},
});
});
});
describe('disabled', () => {
beforeEach(utils.setup(`
Search/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(`
Search/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: 'Hi',
},
});
});
});
describe('readonly', () => {
beforeEach(utils.setup(`
Search/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: 'Hi',
},
});
});
});
describe('programmatic value setting', () => {
beforeEach(utils.setup(`
Search/Programmatic Value Setting
`));
it('should have form values set', () => {
utils.test({
querySubmitter: (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(`
Search/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: ['value', 'another value'],
},
});
});
it('should set both values', () => {
utils.test({
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, {
hello: ['new value 1', 'another value 2'],
})
},
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: ['new value 1', 'another value 2'],
},
});
});
});
})