diff --git a/cypress/integration/checkbox.test.ts b/cypress/integration/checkbox.test.ts
index ca291ac..a360caa 100644
--- a/cypress/integration/checkbox.test.ts
+++ b/cypress/integration/checkbox.test.ts
@@ -55,7 +55,7 @@ describe('checkbox', () => {
}
});
});
- })
+ });
describe('checked', () => {
beforeEach(utils.setup(`
@@ -93,7 +93,6 @@ describe('checkbox', () => {
});
});
-
describe('duplicate', () => {
beforeEach(utils.setup(`
@@ -165,4 +164,221 @@ describe('checkbox', () => {
});
});
});
+
+ describe('setting values', () => {
+ beforeEach(utils.setup(`
+
+
+
+
+ Checkbox/Setting Values
+
+
+
+
+
+ `))
+
+ it('should check for boolean "true"', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { enabled: true, })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const values = getFormValues(form, { submitter })
+ expect(values['enabled']).toBe('on');
+ },
+ expectedStaticValue: 'enabled=on',
+ });
+ });
+
+ it('should check for string "true"', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { enabled: 'true', })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const values = getFormValues(form, { submitter })
+ expect(values['enabled']).toBe('on');
+ },
+ expectedStaticValue: 'enabled=on',
+ });
+ });
+
+ it('should check for string "yes"', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { enabled: 'yes', })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const values = getFormValues(form, { submitter })
+ expect(values['enabled']).toBe('on');
+ },
+ expectedStaticValue: 'enabled=on',
+ });
+ });
+
+ it('should check for string "on"', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { enabled: 'on', })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const values = getFormValues(form, { submitter })
+ expect(values['enabled']).toBe('on');
+ },
+ expectedStaticValue: 'enabled=on',
+ });
+ });
+
+ it('should uncheck for boolean "false"', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { enabled: false, })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const values = getFormValues(form, { submitter })
+ expect(values['enabled']).not.toBe('on');
+ },
+ expectedStaticValue: '',
+ });
+ });
+
+ it('should uncheck for string "false"', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { enabled: 'false', })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const values = getFormValues(form, { submitter })
+ expect(values['enabled']).not.toBe('on');
+ },
+ expectedStaticValue: '',
+ });
+ });
+
+ it('should uncheck for string "no"', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { enabled: 'no', })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const values = getFormValues(form, { submitter })
+ expect(values['enabled']).not.toBe('on');
+ },
+ expectedStaticValue: '',
+ });
+ });
+
+ it('should uncheck for string "off"', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { enabled: 'off', })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const values = getFormValues(form, { submitter })
+ expect(values['enabled']).not.toBe('on');
+ },
+ expectedStaticValue: '',
+ });
+ });
+
+ it('should check for number "1"', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { enabled: 1, })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const values = getFormValues(form, { submitter })
+ expect(values['enabled']).toBe('on');
+ },
+ expectedStaticValue: 'enabled=on',
+ });
+ });
+
+ it('should check for string "1"', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { enabled: '1', })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const values = getFormValues(form, { submitter })
+ expect(values['enabled']).toBe('on');
+ },
+ expectedStaticValue: 'enabled=on',
+ });
+ });
+
+ it('should uncheck for number "0"', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { enabled: 0, })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const values = getFormValues(form, { submitter })
+ expect(values['enabled']).not.toBe('on');
+ },
+ expectedStaticValue: '',
+ });
+ });
+
+ it('should uncheck for string "0"', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { enabled: '0', })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const values = getFormValues(form, { submitter })
+ expect(values['enabled']).not.toBe('on');
+ },
+ expectedStaticValue: '',
+ });
+ });
+
+ it('should uncheck for object "null"', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { enabled: null, })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const values = getFormValues(form, { submitter })
+ expect(values['enabled']).not.toBe('on');
+ },
+ expectedStaticValue: '',
+ });
+ });
+
+ it('should uncheck for string "null"', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { enabled: 'null', })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const values = getFormValues(form, { submitter })
+ expect(values['enabled']).not.toBe('on');
+ },
+ expectedStaticValue: '',
+ });
+ });
+ });
});
diff --git a/cypress/integration/date.test.ts b/cypress/integration/date.test.ts
index 43b91d4..54d1c66 100644
--- a/cypress/integration/date.test.ts
+++ b/cypress/integration/date.test.ts
@@ -38,6 +38,19 @@ describe('date', () => {
},
});
});
+
+ it('should enable Date representation', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const values = getFormValues(form, { submitter, forceDateValues: true });
+ // somehow, checking instanceof Date fails here, because we're using an artificial date
+ // object?
+ const testDate = new Date(values.hello as Date);
+ expect((values.hello as Date).getTime()).toBe(testDate.getTime());
+ },
+ });
+ });
})
describe('disabled', () => {
diff --git a/cypress/integration/datetime-local.test.ts b/cypress/integration/datetime-local.test.ts
index c920605..6642731 100644
--- a/cypress/integration/datetime-local.test.ts
+++ b/cypress/integration/datetime-local.test.ts
@@ -38,6 +38,19 @@ describe('date', () => {
},
});
});
+
+ it('should enable Date representation', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const values = getFormValues(form, { submitter, forceDateValues: true });
+ // somehow, checking instanceof Date fails here, because we're using an artificial date
+ // object?
+ const testDate = new Date(values.hello as Date);
+ expect((values.hello as Date).getTime()).toBe(testDate.getTime());
+ },
+ });
+ });
})
describe('disabled', () => {
diff --git a/cypress/integration/misc.test.ts b/cypress/integration/misc.test.ts
index 24f969f..e13ac04 100644
--- a/cypress/integration/misc.test.ts
+++ b/cypress/integration/misc.test.ts
@@ -1,4 +1,10 @@
-import getFormValuesDeprecated, { getFormValues, setFormValues } from '../../src';
+import getFormValuesDeprecated, {
+ getFormValues,
+ setFormValues,
+ isFieldElement,
+ isElementValueIncludedInFormSubmit,
+ getValue,
+} from '../../src';
import * as utils from '../utils'
describe('misc', () => {
@@ -177,7 +183,213 @@ describe('misc', () => {
},
});
});
- })
+ });
+
+ describe('utilities', () => {
+ beforeEach(utils.setup(`
+
+
+
+
+ Misc/Utilities
+
+
+
+
+
+ `));
+
+ it('should check for valid field elements value', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const meter = document.getElementById('meter');
+ expect(getValue(meter)).toBe(5);
+ },
+ });
+ });
+
+ it('should check for invalid field elements value', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ expect(getValue(document.body)).toBe(null);
+ },
+ });
+ });
+
+ it('should check for elements as included fields', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const input = document.getElementById('input');
+ expect(isElementValueIncludedInFormSubmit(input)).toBe(true);
+ },
+ });
+ });
+
+ it('should check for elements as excluded fields', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const notField = document.getElementById('notField');
+ expect(isElementValueIncludedInFormSubmit(notField)).toBe(false);
+ const disabled = document.getElementById('disabled');
+ expect(isElementValueIncludedInFormSubmit(disabled)).toBe(false);
+ const meter = document.getElementById('meter');
+ expect(isElementValueIncludedInFormSubmit(meter)).toBe(false);
+ },
+ });
+ });
+
+ it('should check for elements as valid for fields', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const input = document.getElementById('input');
+ expect(isFieldElement(input)).toBe(true);
+ const disabled = document.getElementById('disabled');
+ expect(isFieldElement(disabled)).toBe(true);
+ },
+ });
+ });
+
+ it('should check for elements as invalid for fields', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const meter = document.getElementById('meter');
+ expect(isFieldElement(meter)).toBe(false);
+ const notField = document.getElementById('notField');
+ expect(isFieldElement(notField)).toBe(false);
+ },
+ });
+ });
+ });
+
+ describe('setting values', () => {
+ beforeEach(utils.setup(`
+
+
+
+
+ Misc/Blank
+
+
+
+
+
+ `))
+
+ it('should parse string values for setFormValues', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ let isThrown = false;
+ try {
+ setFormValues(form, 'foobar=baz');
+ } catch (e) {
+ isThrown = true;
+ }
+
+ expect(isThrown).toBe(false);
+ expect(getFormValues(form)).toEqual({ foobar: 'baz', });
+ },
+ })
+ });
+
+ it('should parse entries values for setFormValues', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ let isThrown = false;
+ try {
+ setFormValues(form, [['foobar', 'baz']]);
+ } catch (e) {
+ isThrown = true;
+ }
+
+ expect(isThrown).toBe(false);
+ expect(getFormValues(form)).toEqual({ foobar: 'baz', });
+ },
+ })
+ });
+
+ it('should parse URLSearchParams values for setFormValues', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ let isThrown = false;
+ try {
+ setFormValues(form, new URLSearchParams('foobar=baz'));
+ } catch (e) {
+ isThrown = true;
+ }
+
+ expect(isThrown).toBe(false);
+ expect(getFormValues(form)).toEqual({ foobar: 'baz', });
+ },
+ })
+ });
+
+ it('should parse object values for setFormValues', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ let isThrown = false;
+ try {
+ setFormValues(form, { foobar: 'baz', });
+ } catch (e) {
+ isThrown = true;
+ }
+
+ expect(isThrown).toBe(false);
+ expect(getFormValues(form)).toEqual({ foobar: 'baz', });
+ },
+ })
+ });
+ });
+
+ describe('duplicates', () => {
+ beforeEach(utils.setup(`
+
+
+
+
+ Misc/Blank
+
+
+
+
+
+ `));
+
+ it('should parse duplicates correctly', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { foobar: ['foo', 'bar', 'baz']})
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ expect(getFormValues(form)).toEqual({ foobar: ['foo', 'bar', 'baz'], });
+ },
+ })
+ });
+ });
describe('blank', () => {
beforeEach(utils.setup(`
diff --git a/cypress/integration/month.test.ts b/cypress/integration/month.test.ts
index 765cfea..1a5096a 100644
--- a/cypress/integration/month.test.ts
+++ b/cypress/integration/month.test.ts
@@ -38,6 +38,19 @@ describe('month', () => {
},
});
});
+
+ it('should enable Date representation', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (form: HTMLFormElement, submitter: any, search: any) => {
+ const values = getFormValues(form, { submitter, forceDateValues: true });
+ // somehow, checking instanceof Date fails here, because we're using an artificial date
+ // object?
+ const testDate = new Date(values.hello as Date);
+ expect((values.hello as Date).getTime()).toBe(testDate.getTime());
+ },
+ });
+ });
})
describe('disabled', () => {
diff --git a/cypress/integration/select.test.ts b/cypress/integration/select.test.ts
index 1c893ec..453cce4 100644
--- a/cypress/integration/select.test.ts
+++ b/cypress/integration/select.test.ts
@@ -1,4 +1,4 @@
-import { getFormValues } from '../../src'
+import { getFormValues, setFormValues } from '../../src';
import * as utils from '../utils'
describe('select', () => {
@@ -41,6 +41,107 @@ describe('select', () => {
expectedStaticValue: 'hello=Bar&hello=Quux'
});
});
+
+ it('should set values correctly', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { hello: ['Foo', 'Baz'] });
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (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=Foo&hello=Baz'
+ });
+ });
+ })
+
+ describe('multiple duplicate', () => {
+ beforeEach(utils.setup(`
+
+
+
+
+ Select/Multiple Duplicate
+
+
+
+
+
+ `))
+
+ it('should have multiple form values on a single field', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (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=Bar&hello=Quux&hello=Mango&hello=Ube'
+ });
+ });
+
+ it('should set multiple form values across all selects', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { hello: ['Foo', 'Baz', 'Chocolate', 'Vanilla'] })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (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=Foo&hello=Baz&hello=Chocolate&hello=Vanilla'
+ });
+ });
+
+ it('should set multiple form values on each corresponding select element', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { hello: [['Foo', 'Baz', 'Chocolate'], ['Vanilla']] })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (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=Foo&hello=Baz&hello=Vanilla'
+ });
+ });
})
describe('single', () => {
@@ -84,4 +185,88 @@ describe('select', () => {
});
});
})
+
+ describe('single duplicate', () => {
+ beforeEach(utils.setup(`
+
+
+
+
+ Select/Single Duplicate
+
+
+
+
+
+ `))
+
+ it('should have multiple form values on a single field', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (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=Bar&hello=Ube'
+ });
+ });
+
+ it('should set multiple form values across all selects', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { hello: ['Foo', 'Chocolate'] })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (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=Foo&hello=Chocolate'
+ });
+ });
+
+ it('should set multiple form values on each corresponding select element', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { hello: ['Foo', 'Ube'] })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (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=Foo&hello=Ube'
+ });
+ });
+ })
})
diff --git a/cypress/integration/time.test.ts b/cypress/integration/time.test.ts
new file mode 100644
index 0000000..2eeb884
--- /dev/null
+++ b/cypress/integration/time.test.ts
@@ -0,0 +1,265 @@
+import { getFormValues, setFormValues } from '../../src';
+import * as utils from '../utils'
+
+describe('time', () => {
+ describe('basic', () => {
+ beforeEach(utils.setup(`
+
+
+
+
+ Time/Basic
+
+
+
+
+
+ `))
+
+ it('should have single form value', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (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: '13:37',
+ },
+ });
+ });
+ })
+
+ describe('disabled', () => {
+ beforeEach(utils.setup(`
+
+
+
+
+ Time/Disabled
+
+
+
+
+
+ `))
+
+ it('should have blank form value', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (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(`
+
+
+
+
+ Time/Outside
+
+
+
+
+
+
+ `))
+
+ it('should have single form value', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (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: '13:37',
+ },
+ });
+ });
+ });
+
+ describe('readonly', () => {
+ beforeEach(utils.setup(`
+
+
+
+
+ Time/Readonly
+
+
+
+
+
+ `))
+
+ it('should have single form value', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (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: '13:37',
+ },
+ });
+ });
+ });
+
+ describe('programmatic value setting', () => {
+ beforeEach(utils.setup(`
+
+
+
+
+ Time/Programmatic Value Setting
+
+
+
+
+
+ `));
+
+ it('should have form values set', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, { hello: '13:37', })
+ },
+ test: (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: '13:37',
+ },
+ });
+ });
+ });
+
+ describe('duplicate', () => {
+ beforeEach(utils.setup(`
+
+
+
+
+ Time/Duplicate
+
+
+
+
+
+ `));
+
+ it('should get both values', () => {
+ utils.test({
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (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: ['13:37', '06:09'],
+ },
+ });
+ });
+
+ it('should set both values', () => {
+ utils.test({
+ preAction: (form: HTMLFormElement) => {
+ setFormValues(form, {
+ hello: ['04:20', '05:30'],
+ })
+ },
+ action: (cy: any) => cy.get('[type="submit"]'),
+ test: (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: ['04:20', '05:30'],
+ },
+ });
+ });
+ });
+})
diff --git a/src/index.ts b/src/index.ts
index a4c9d23..0376d76 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -44,8 +44,9 @@ const FORM_FIELD_INPUT_EXCLUDED_TYPES = ['submit', 'reset'] as const;
/**
* Checks if an element can hold a custom (user-inputted) field value.
* @param el - The element.
+ * @returns Value determining if an element can hold a custom (user-inputted) field value.
*/
-export const isFormFieldElement = (el: HTMLElement) => {
+export const isFieldElement = (el: HTMLElement) => {
const { tagName } = el;
if (FORM_FIELD_ELEMENT_TAG_NAMES.includes(tagName as typeof FORM_FIELD_ELEMENT_TAG_NAMES[0])) {
return true;
@@ -92,15 +93,15 @@ const getTextAreaFieldValue = (
* @param textareaEl - The element.
* @param value - Value of the textarea element.
* @param nthOfName - What order is this field in with respect to fields of the same name?
- * @param totalOfName - How many fields with the same name are in the form?
+ * @param elementsOfSameName - How many fields with the same name are in the form?
*/
const setTextAreaFieldValue = (
textareaEl: HTMLTextAreaElement,
value: unknown,
nthOfName: number,
- totalOfName: number,
+ elementsOfSameName: HTMLTextAreaElement[],
) => {
- if (Array.isArray(value) && totalOfName > 1) {
+ if (Array.isArray(value) && elementsOfSameName.length > 1) {
// eslint-disable-next-line no-param-reassign
textareaEl.value = value[nthOfName];
return;
@@ -128,19 +129,54 @@ const getSelectFieldValue = (
* Sets the value of a `