Переглянути джерело

Implement clearFormValues, improve test syntax

The clearFormValues method is implemented to be able to clear form
values for selected fields.

Tests are now separated from pre-submit to querying the submitter.
master
TheoryOfNekomata 1 рік тому
джерело
коміт
e465109d74
28 змінених файлів з 402 додано та 310 видалено
  1. +5
    -1
      .eslintrc
  2. +5
    -2
      README.md
  3. +19
    -19
      cypress/integration/checkbox.test.ts
  4. +7
    -7
      cypress/integration/color.test.ts
  5. +88
    -23
      cypress/integration/core.test.ts
  6. +8
    -8
      cypress/integration/date.test.ts
  7. +8
    -8
      cypress/integration/datetime-local.test.ts
  8. +7
    -7
      cypress/integration/email.test.ts
  9. +11
    -15
      cypress/integration/file.test.ts
  10. +8
    -8
      cypress/integration/hidden.test.ts
  11. +5
    -4
      cypress/integration/misc.test.ts
  12. +8
    -8
      cypress/integration/month.test.ts
  13. +7
    -7
      cypress/integration/number.test.ts
  14. +7
    -7
      cypress/integration/password.test.ts
  15. +21
    -21
      cypress/integration/radio.test.ts
  16. +7
    -7
      cypress/integration/range.test.ts
  17. +9
    -9
      cypress/integration/search.test.ts
  18. +9
    -9
      cypress/integration/select.test.ts
  19. +3
    -3
      cypress/integration/submitter.test.ts
  20. +7
    -7
      cypress/integration/tel.test.ts
  21. +9
    -9
      cypress/integration/text.test.ts
  22. +10
    -10
      cypress/integration/textarea.test.ts
  23. +7
    -7
      cypress/integration/time.test.ts
  24. +7
    -7
      cypress/integration/url.test.ts
  25. +7
    -7
      cypress/integration/week.test.ts
  26. +20
    -21
      cypress/utils/index.ts
  27. +1
    -1
      package.json
  28. +92
    -68
      src/index.ts

+ 5
- 1
.eslintrc Переглянути файл

@@ -8,7 +8,11 @@
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-call": "off"
"@typescript-eslint/no-unsafe-call": "off",
"no-param-reassign": ["error", {
"props": true,
"ignorePropertyModificationsForRegex": ["[Ee]l$"]
}]
},
"parserOptions": {
"project": "./tsconfig.eslint.json"


+ 5
- 2
README.md Переглянути файл

@@ -147,6 +147,7 @@ These are all the exported methods in the library:
import {
getFormValues,
setFormValues,
clearFormValues,
getValue,
isElementValueIncludedInFormSubmit,
isFieldElement,
@@ -165,8 +166,10 @@ See the [documentation folder](https://code.modal.sh/TheoryOfNekomata/formxtra/s
on this library.

You may need the [event-submitter-polyfill package](https://github.com/idea2app/event-submitter-polyfill) for browsers
that do not support the submitter property on submit events (such as Safari). The submitter element is needed for
that do not support the submitter property on submit events. The submitter element is needed for
tracking which button triggered a form submission, and it may contain `name` and `value` attributes which are used to
add values to the form (such as specifying which action to take for the rest of the form values).
add values to the form (such as specifying which action to take for the rest of the form values). Refer to the
[usability table for `SubmitEvent.submitter`](https://caniuse.com/mdn-api_submitevent_submitter) to check if your target
browser is supported.

The sources are under the [MIT license](https://code.modal.sh/TheoryOfNekomata/formxtra/raw/branch/master/LICENSE).

+ 19
- 19
cypress/integration/checkbox.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('checkbox', () => {

it('should have no form values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
const before = utils.makeSearchParams(values)
@@ -42,7 +42,7 @@ describe('checkbox', () => {

it('should have false checked value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form,
{
@@ -79,7 +79,7 @@ describe('checkbox', () => {

it('should have single form value on a single field', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -127,7 +127,7 @@ describe('checkbox', () => {

it('should get both values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -149,7 +149,7 @@ describe('checkbox', () => {
enabled: ['hello 3', 'hello 4'],
})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -190,7 +190,7 @@ describe('checkbox', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: true, })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBe('on');
@@ -204,7 +204,7 @@ describe('checkbox', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: 'true', })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBe('on');
@@ -218,7 +218,7 @@ describe('checkbox', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: 'yes', })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBe('on');
@@ -232,7 +232,7 @@ describe('checkbox', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: 'on', })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBe('on');
@@ -246,7 +246,7 @@ describe('checkbox', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: false, })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBeUndefined()
@@ -260,7 +260,7 @@ describe('checkbox', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: 'false', })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBeUndefined()
@@ -274,7 +274,7 @@ describe('checkbox', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: 'no', })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBeUndefined()
@@ -288,7 +288,7 @@ describe('checkbox', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: 'off', })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBeUndefined()
@@ -302,7 +302,7 @@ describe('checkbox', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: 1, })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBe('on');
@@ -316,7 +316,7 @@ describe('checkbox', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: '1', })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBe('on');
@@ -330,7 +330,7 @@ describe('checkbox', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: 0, })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBeUndefined()
@@ -344,7 +344,7 @@ describe('checkbox', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: '0', })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBeUndefined()
@@ -358,7 +358,7 @@ describe('checkbox', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: null, })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBeUndefined()
@@ -372,7 +372,7 @@ describe('checkbox', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: 'null', })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBeUndefined()


+ 7
- 7
cypress/integration/color.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('color', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -65,7 +65,7 @@ describe('color', () => {

it('should have blank form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -101,7 +101,7 @@ describe('color', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -142,7 +142,7 @@ describe('color', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -180,7 +180,7 @@ describe('color', () => {

it('should have form values set', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: '#c0ffee', })
},
@@ -225,7 +225,7 @@ describe('color', () => {

it('should get both values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -248,7 +248,7 @@ describe('color', () => {
hello: ['#333333', '#aaccee'],
})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 88
- 23
cypress/integration/core.test.ts Переглянути файл

@@ -3,7 +3,7 @@ import getFormValuesDeprecated, {
setFormValues,
isFieldElement,
isElementValueIncludedInFormSubmit,
getValue,
getValue, clearFormValues,
} from '../../src';
import * as utils from '../utils'

@@ -26,7 +26,7 @@ describe('misc', () => {

it('should call console.warn for deprecated default import usage', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
let consoleWarnCalled = false
const defaultConsoleWarn = console.warn
@@ -40,9 +40,28 @@ describe('misc', () => {
});
});

it('should call noop for deprecated default import usage when console is not found', () => {
utils.test({
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
let consoleWarnCalled = false
const defaultConsoleWarn = console.warn
console.warn = (...args: unknown[]) => {
consoleWarnCalled = true
};
const globalConsole = global.console;
global.console = undefined;
getFormValuesDeprecated(form, { submitter });
expect(consoleWarnCalled).toBe(false);
global.console = globalConsole;
console.warn = defaultConsoleWarn;
},
});
});

it('should throw an error when providing invalid argument type as form to getFormValues', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
let isThrown = false;
try {
@@ -58,7 +77,7 @@ describe('misc', () => {

it('should throw an error when providing null as form to getFormValues', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
let isThrown = false;
try {
@@ -74,7 +93,7 @@ describe('misc', () => {

it('should throw an error when providing a different element type as form to getFormValues', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
let isThrown = false;
try {
@@ -90,7 +109,7 @@ describe('misc', () => {

it('should throw an error when providing invalid argument type as form to setFormValues', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
let isThrown = false;
try {
@@ -106,7 +125,7 @@ describe('misc', () => {

it('should throw an error when providing null as form to setFormValues', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
let isThrown = false;
try {
@@ -122,7 +141,7 @@ describe('misc', () => {

it('should throw an error when providing a different element type as form to setFormValues', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
let isThrown = false;
try {
@@ -138,7 +157,7 @@ describe('misc', () => {

it('should throw an error when providing invalid argument type as values to setFormValues', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
let isThrown = false;
try {
@@ -154,7 +173,7 @@ describe('misc', () => {

it('should not throw an error when providing null as form to setFormValues', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
let isThrown = false;
try {
@@ -170,7 +189,7 @@ describe('misc', () => {

it('should throw an error when providing undefined as form to setFormValues', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
let isThrown = false;
try {
@@ -204,7 +223,7 @@ describe('misc', () => {

it('should have blank form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -240,7 +259,7 @@ describe('misc', () => {

it('should check for valid field elements value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const meter = document.getElementById('meter');
expect(getValue(meter)).toBe(5);
@@ -250,7 +269,7 @@ describe('misc', () => {

it('should check for invalid field elements value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
expect(getValue(document.body)).toBe(null);
},
@@ -259,7 +278,7 @@ describe('misc', () => {

it('should check for elements as included fields', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const input = document.getElementById('input');
expect(isElementValueIncludedInFormSubmit(input)).toBe(true);
@@ -269,7 +288,7 @@ describe('misc', () => {

it('should check for elements as excluded fields', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const notField = document.getElementById('notField');
expect(isElementValueIncludedInFormSubmit(notField)).toBe(false);
@@ -283,7 +302,7 @@ describe('misc', () => {

it('should check for elements as valid for fields', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const input = document.getElementById('input');
expect(isFieldElement(input)).toBe(true);
@@ -295,7 +314,7 @@ describe('misc', () => {

it('should check for elements as invalid for fields', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const meter = document.getElementById('meter');
expect(isFieldElement(meter)).toBe(false);
@@ -325,7 +344,7 @@ describe('misc', () => {

it('should parse string values for setFormValues', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
let isThrown = false;
try {
@@ -342,7 +361,7 @@ describe('misc', () => {

it('should parse entries values for setFormValues', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
let isThrown = false;
try {
@@ -359,7 +378,7 @@ describe('misc', () => {

it('should parse URLSearchParams values for setFormValues', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
let isThrown = false;
try {
@@ -376,7 +395,7 @@ describe('misc', () => {

it('should parse object values for setFormValues', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
let isThrown = false;
try {
@@ -392,6 +411,52 @@ describe('misc', () => {
});
});


describe('clearing values', () => {
beforeEach(utils.setup(`
<!DOCTYPE html>
<html lang="en-PH">
<head>
<meta charset="UTF-8">
<title>Misc/Blank</title>
</head>
<body>
<form>
<input type="text" name="foobar" value="value1" />
<input type="text" name="foobar" value="value2" />
<input type="text" name="baz" value="value3" />
<input type="text" name="bar" value="value1" />
<input type="text" name="bar" value="value2" />
<input type="radio" name="foo" value="value1" checked />
<input type="radio" name="foo" value="value2" />
<input type="radio" name="foo" value="value3" />
<button type="submit">Submit</button>
</form>
</body>
</html>
`));

it('should clear all values given a single key', () => {
utils.test({
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
clearFormValues(form, 'foobar');
expect(getFormValues(form)).toEqual({ foobar: ['', ''], baz: 'value3', bar: ['value1', 'value2'], foo: 'value1', });
},
});
});

it('should clear all values given multiple keys', () => {
utils.test({
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
clearFormValues(form, ['foobar', 'bar', 'foo']);
expect(getFormValues(form)).toEqual({ foobar: ['', ''], baz: 'value3', bar: ['', ''], });
},
});
});
});

describe('duplicates', () => {
beforeEach(utils.setup(`
<!DOCTYPE html>
@@ -416,7 +481,7 @@ describe('misc', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { foobar: ['foo', 'bar', 'baz']})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
expect(getFormValues(form)).toEqual({ foobar: ['foo', 'bar', 'baz'], });
},


+ 8
- 8
cypress/integration/date.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('date', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -41,7 +41,7 @@ describe('date', () => {

it('should enable Date representation', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (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
@@ -78,7 +78,7 @@ describe('date', () => {

it('should have blank form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -114,7 +114,7 @@ describe('date', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -155,7 +155,7 @@ describe('date', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -193,7 +193,7 @@ describe('date', () => {

it('should have form values set', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: new Date('2000-01-01'), })
},
@@ -238,7 +238,7 @@ describe('date', () => {

it('should get both values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -260,7 +260,7 @@ describe('date', () => {
hello: ['2006-06-06', '2005-05-05'],
})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 8
- 8
cypress/integration/datetime-local.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('date', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -41,7 +41,7 @@ describe('date', () => {

it('should enable Date representation', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (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
@@ -78,7 +78,7 @@ describe('date', () => {

it('should have blank form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -114,7 +114,7 @@ describe('date', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -155,7 +155,7 @@ describe('date', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -193,7 +193,7 @@ describe('date', () => {

it('should have form values set', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: new Date('2000-01-01T13:37'), })
},
@@ -238,7 +238,7 @@ describe('date', () => {

it('should get both values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -260,7 +260,7 @@ describe('date', () => {
hello: ['2006-06-06T13:37', '2005-05-05T13:37'],
})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 7
- 7
cypress/integration/email.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('email', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -65,7 +65,7 @@ describe('email', () => {

it('should have blank form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -101,7 +101,7 @@ describe('email', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -142,7 +142,7 @@ describe('email', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -180,7 +180,7 @@ describe('email', () => {

it('should have form values set', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: 'email@example.com', })
},
@@ -225,7 +225,7 @@ describe('email', () => {

it('should get both values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -247,7 +247,7 @@ describe('email', () => {
hello: ['poppy@example.com', 'pumpkin@example.com'],
})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 11
- 15
cypress/integration/file.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('file', () => {

it('should have no form values when no file is selected', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -41,13 +41,12 @@ describe('file', () => {

it('should have single form value when a file is selected', () => {
utils.test({
actionBeforeSubmit: (cy: any) => {
onBeforeSubmit: (cy) => {
cy
.get('[name="hello"]')
.attachFile('uploads/data.json')

return cy.get('[type="submit"]')
},
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -64,13 +63,12 @@ describe('file', () => {

it('should retrieve the file list upon setting appropriate option', () => {
utils.test({
actionBeforeSubmit: (cy: any) => {
onBeforeSubmit: (cy: any) => {
cy
.get('[name="hello"]')
.attachFile('uploads/data.json')

return cy.get('[type="submit"]')
},
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any) => {
const formValues = getFormValues(form,
{
@@ -89,7 +87,7 @@ describe('file', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: 'data.json' });
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any) => {
const formValues = getFormValues(
form,
@@ -127,7 +125,7 @@ describe('file', () => {

it('should have no form values when no file is selected', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -144,13 +142,12 @@ describe('file', () => {

it('should have single form value when a file is selected', () => {
utils.test({
actionBeforeSubmit: (cy: any) => {
onBeforeSubmit: (cy: any) => {
cy
.get('[name="hello"]')
.attachFile(['uploads/data.json', 'uploads/data2.json'])

return cy.get('[type="submit"]')
},
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -165,13 +162,12 @@ describe('file', () => {

it('should retrieve the file list upon setting appropriate option', () => {
utils.test({
actionBeforeSubmit: (cy: any) => {
onBeforeSubmit: (cy: any) => {
cy
.get('[name="hello"]')
.attachFile(['uploads/data.json', 'uploads/data2.json'])

return cy.get('[type="submit"]')
},
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any) => {
const formValues = getFormValues(form,
{


+ 8
- 8
cypress/integration/hidden.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('hidden', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -62,7 +62,7 @@ describe('hidden', () => {

it('should have extra value for character set', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter, includeCharset: true, }))
.toString();
@@ -82,7 +82,7 @@ describe('hidden', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { _charset_: 'Shift-JIS' });
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter, includeCharset: true, }))
.toString();
@@ -123,7 +123,7 @@ describe('hidden', () => {

it('should have blank form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -159,7 +159,7 @@ describe('hidden', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -197,7 +197,7 @@ describe('hidden', () => {

it('should have form values set', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: 'Hi', })
},
@@ -242,7 +242,7 @@ describe('hidden', () => {

it('should get both values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -264,7 +264,7 @@ describe('hidden', () => {
hello: ['new value 1', 'another value 2'],
})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 5
- 4
cypress/integration/misc.test.ts Переглянути файл

@@ -20,7 +20,7 @@ describe('misc', () => {

it('should have blank form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -180,7 +180,7 @@ describe('misc', () => {

it('should have correct form values', () => {
utils.test({
actionBeforeSubmit: (cy) => {
onBeforeSubmit: (cy) => {
cy.get('[name="first_name"]')
.type('John')
cy.get('[name="middle_name"]')
@@ -228,8 +228,8 @@ describe('misc', () => {
.trigger('change')
cy.get('[name="notes"]')
.type('Test content\n\nNew line\n\nAnother line')
return cy.get('[name="submit"][value="Hi"]')
},
querySubmitter: (cy) => cy.get('[name="submit"][value="Hi"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -245,7 +245,8 @@ describe('misc', () => {

it('should have filled form values', () => {
utils.test({
actionBeforeSubmit: (cy) => cy.wait(3000).get('[name="submit"][value="Hi"]'),
onBeforeSubmit: (cy: any) => cy.wait(3000),
querySubmitter: (cy) => cy.get('[name="submit"][value="Hi"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 8
- 8
cypress/integration/month.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('month', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -41,7 +41,7 @@ describe('month', () => {

it('should enable Date representation', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (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
@@ -78,7 +78,7 @@ describe('month', () => {

it('should have blank form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -114,7 +114,7 @@ describe('month', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -155,7 +155,7 @@ describe('month', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -193,7 +193,7 @@ describe('month', () => {

it('should have form values set', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: '2003-05', })
},
@@ -238,7 +238,7 @@ describe('month', () => {

it('should get both values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -260,7 +260,7 @@ describe('month', () => {
hello: ['2003-04', '2003-02'],
})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 7
- 7
cypress/integration/number.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('number', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter, forceNumberValues: true, }))
.toString();
@@ -65,7 +65,7 @@ describe('number', () => {

it('should have blank form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -101,7 +101,7 @@ describe('number', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -142,7 +142,7 @@ describe('number', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -180,7 +180,7 @@ describe('number', () => {

it('should have form values set', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: 5, })
},
@@ -225,7 +225,7 @@ describe('number', () => {

it('should get both values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter, forceNumberValues: true, }))
.toString();
@@ -247,7 +247,7 @@ describe('number', () => {
hello: [4, 2],
})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 7
- 7
cypress/integration/password.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('password', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -65,7 +65,7 @@ describe('password', () => {

it('should have blank form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -101,7 +101,7 @@ describe('password', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -142,7 +142,7 @@ describe('password', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -180,7 +180,7 @@ describe('password', () => {

it('should have form values set', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: 'Hi', })
},
@@ -225,7 +225,7 @@ describe('password', () => {

it('should get both values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -247,7 +247,7 @@ describe('password', () => {
hello: ['new value 1', 'another value 2'],
})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 21
- 21
cypress/integration/radio.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('radio', () => {

it('should have no form values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
const before = utils.makeSearchParams(values)
@@ -63,7 +63,7 @@ describe('radio', () => {

it('should have single form value on a single field', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -111,7 +111,7 @@ describe('radio', () => {

it('should get last value as checked', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -133,7 +133,7 @@ describe('radio', () => {
enabled: ['hello 3', 'hello 4'],
})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -183,7 +183,7 @@ describe('radio', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: true, })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBeUndefined()
@@ -197,7 +197,7 @@ describe('radio', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: 'true', })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBe('true');
@@ -211,7 +211,7 @@ describe('radio', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: 'yes', })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBe('yes');
@@ -225,7 +225,7 @@ describe('radio', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: 'on', })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBe('on');
@@ -239,7 +239,7 @@ describe('radio', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: false, })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBeUndefined()
@@ -253,7 +253,7 @@ describe('radio', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: 'false', })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBe('false');
@@ -267,7 +267,7 @@ describe('radio', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: 'no', })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBe('no')
@@ -281,7 +281,7 @@ describe('radio', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: 'off', })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBe('off');
@@ -295,7 +295,7 @@ describe('radio', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: 1, })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBeUndefined();
@@ -309,7 +309,7 @@ describe('radio', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: '1', })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBe('1');
@@ -323,7 +323,7 @@ describe('radio', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: 0, })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBeUndefined()
@@ -337,7 +337,7 @@ describe('radio', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: '0', })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBe('0')
@@ -351,7 +351,7 @@ describe('radio', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: null, })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBeUndefined()
@@ -365,7 +365,7 @@ describe('radio', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: 'null', })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBe('null');
@@ -379,7 +379,7 @@ describe('radio', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: true, })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBeUndefined()
@@ -393,7 +393,7 @@ describe('radio', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: ['foo', 'bar', 'baz', 'on'], })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBe('on')
@@ -407,7 +407,7 @@ describe('radio', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { enabled: ['foo', 'bar', 'baz', 'on', 'default', 'true'], })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const values = getFormValues(form, { submitter })
expect(values['enabled']).toBe('true')


+ 7
- 7
cypress/integration/range.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('range', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter, forceNumberValues: true, }))
.toString();
@@ -65,7 +65,7 @@ describe('range', () => {

it('should have blank form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -101,7 +101,7 @@ describe('range', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -142,7 +142,7 @@ describe('range', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -180,7 +180,7 @@ describe('range', () => {

it('should have form values set', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: 5, })
},
@@ -225,7 +225,7 @@ describe('range', () => {

it('should get both values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter, forceNumberValues: true, }))
.toString();
@@ -247,7 +247,7 @@ describe('range', () => {
hello: [4, 2],
})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 9
- 9
cypress/integration/search.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('search', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -62,7 +62,7 @@ describe('search', () => {

it('should have extra value for directionality', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter, includeDirectionality: true, }))
.toString();
@@ -80,7 +80,7 @@ describe('search', () => {

it('should support other directionality', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
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, }))
@@ -123,7 +123,7 @@ describe('search', () => {

it('should have blank form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -159,7 +159,7 @@ describe('search', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -200,7 +200,7 @@ describe('search', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -238,7 +238,7 @@ describe('search', () => {

it('should have form values set', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: 'Hi', })
},
@@ -283,7 +283,7 @@ describe('search', () => {

it('should get both values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -305,7 +305,7 @@ describe('search', () => {
hello: ['new value 1', 'another value 2'],
})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 9
- 9
cypress/integration/select.test.ts Переглянути файл

@@ -29,7 +29,7 @@ describe('select', () => {

it('should have multiple form values on a single field', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -47,7 +47,7 @@ describe('select', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: ['Foo', 'Baz'] });
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -94,7 +94,7 @@ describe('select', () => {

it('should have multiple form values on a single field', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -112,7 +112,7 @@ describe('select', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: ['Foo', 'Baz', 'Chocolate', 'Vanilla'] })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -130,7 +130,7 @@ describe('select', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: [['Foo', 'Baz', 'Chocolate'], ['Vanilla']] })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -170,7 +170,7 @@ describe('select', () => {

it('should have single form value on a single field', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -220,7 +220,7 @@ describe('select', () => {

it('should have multiple form values on a single field', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -238,7 +238,7 @@ describe('select', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: ['Foo', 'Chocolate'] })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -256,7 +256,7 @@ describe('select', () => {
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: ['Foo', 'Ube'] })
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 3
- 3
cypress/integration/submitter.test.ts Переглянути файл

@@ -25,7 +25,7 @@ describe('submitter', () => {

it('should have double form values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[name="action"][value="Foo"]'),
querySubmitter: (cy: any) => cy.get('[name="action"][value="Foo"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -65,7 +65,7 @@ describe('submitter', () => {

it('should have double form values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[name="action"][value="Bar"]'),
querySubmitter: (cy: any) => cy.get('[name="action"][value="Bar"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -103,7 +103,7 @@ describe('submitter', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 7
- 7
cypress/integration/tel.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('tel', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -65,7 +65,7 @@ describe('tel', () => {

it('should have blank form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -101,7 +101,7 @@ describe('tel', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -142,7 +142,7 @@ describe('tel', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -180,7 +180,7 @@ describe('tel', () => {

it('should have form values set', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: 'Hi', })
},
@@ -225,7 +225,7 @@ describe('tel', () => {

it('should get both values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -247,7 +247,7 @@ describe('tel', () => {
hello: ['new value 1', 'another value 2'],
})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 9
- 9
cypress/integration/text.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('text', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -62,7 +62,7 @@ describe('text', () => {

it('should have extra value for directionality', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter, includeDirectionality: true, }))
.toString();
@@ -80,7 +80,7 @@ describe('text', () => {

it('should support other directionality', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
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, }))
@@ -123,7 +123,7 @@ describe('text', () => {

it('should have blank form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -159,7 +159,7 @@ describe('text', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -200,7 +200,7 @@ describe('text', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -238,7 +238,7 @@ describe('text', () => {

it('should have form values set', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: 'Hi', })
},
@@ -283,7 +283,7 @@ describe('text', () => {

it('should get both values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -305,7 +305,7 @@ describe('text', () => {
hello: ['new value 1', 'another value 2'],
})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 10
- 10
cypress/integration/textarea.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('textarea', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -65,7 +65,7 @@ describe('textarea', () => {

it('should have blank form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -101,7 +101,7 @@ describe('textarea', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -142,7 +142,7 @@ describe('textarea', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -180,7 +180,7 @@ describe('textarea', () => {

it('should have form values set', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: 'Hi', })
},
@@ -221,7 +221,7 @@ describe('textarea', () => {

it('should read LF line breaks', () => {
utils.test({
actionBeforeSubmit: (cy: any) => {
querySubmitter: (cy: any) => {
cy.get('[name="hello"]')
.type('Hi\nHello', { parseSpecialCharSequences: false })
return cy.get('[type="submit"]')
@@ -242,7 +242,7 @@ describe('textarea', () => {

it('should read CR line breaks', () => {
utils.test({
actionBeforeSubmit: (cy: any) => {
querySubmitter: (cy: any) => {
cy.get('[name="hello"]')
.type('Hi\rHello', { parseSpecialCharSequences: false })
return cy.get('[type="submit"]')
@@ -263,7 +263,7 @@ describe('textarea', () => {

it('should read CRLF line breaks', () => {
utils.test({
actionBeforeSubmit: (cy: any) => {
querySubmitter: (cy: any) => {
cy.get('[name="hello"]')
.type('Hi\r\nHello', { parseSpecialCharSequences: false })
return cy.get('[type="submit"]')
@@ -309,7 +309,7 @@ describe('textarea', () => {

it('should get both values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -331,7 +331,7 @@ describe('textarea', () => {
hello: ['new value 1', 'another value 2'],
})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 7
- 7
cypress/integration/time.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('time', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -65,7 +65,7 @@ describe('time', () => {

it('should have blank form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -101,7 +101,7 @@ describe('time', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -142,7 +142,7 @@ describe('time', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -180,7 +180,7 @@ describe('time', () => {

it('should have form values set', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: '13:37', })
},
@@ -225,7 +225,7 @@ describe('time', () => {

it('should get both values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -247,7 +247,7 @@ describe('time', () => {
hello: ['04:20', '05:30'],
})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 7
- 7
cypress/integration/url.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('url', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -65,7 +65,7 @@ describe('url', () => {

it('should have blank form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -101,7 +101,7 @@ describe('url', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -142,7 +142,7 @@ describe('url', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -180,7 +180,7 @@ describe('url', () => {

it('should have form values set', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: 'https://www.example.com', })
},
@@ -225,7 +225,7 @@ describe('url', () => {

it('should get both values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -247,7 +247,7 @@ describe('url', () => {
hello: ['https://foo.example.com', 'https://bar.example.com/context'],
})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 7
- 7
cypress/integration/week.test.ts Переглянути файл

@@ -24,7 +24,7 @@ describe('week', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -65,7 +65,7 @@ describe('week', () => {

it('should have blank form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -101,7 +101,7 @@ describe('week', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -142,7 +142,7 @@ describe('week', () => {

it('should have single form value', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -180,7 +180,7 @@ describe('week', () => {

it('should have form values set', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, { hello: '2003-W25', })
},
@@ -225,7 +225,7 @@ describe('week', () => {

it('should get both values', () => {
utils.test({
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
@@ -247,7 +247,7 @@ describe('week', () => {
hello: ['2003-W40', '2003-W50'],
})
},
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'),
querySubmitter: (cy: any) => cy.get('[type="submit"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();


+ 20
- 21
cypress/utils/index.ts Переглянути файл

@@ -8,7 +8,7 @@ type RetrieveSubmitterFn = (wrapper: typeof cy | JSDOMDummyCypress) => any

type HTMLSubmitterElement = HTMLButtonElement | HTMLInputElement

type TestFn = (form: HTMLFormElement, submitter: HTMLSubmitterElement, after: ExpectedSearchValue) => unknown
type TestFn = (form: HTMLFormElement, submitter?: HTMLSubmitterElement, after?: ExpectedSearchValue) => unknown

export const setup = (template: string) => {
if (typeof cy !== 'undefined') {
@@ -26,18 +26,20 @@ export const setup = (template: string) => {
}

type TestOptions = {
actionBeforeSubmit: RetrieveSubmitterFn,
onSubmitted: TestFn,
querySubmitter: RetrieveSubmitterFn,
onSubmitted?: TestFn,
expectedStaticValue?: ExpectedSearchValue,
onLoaded?: Function,
onLoaded?: TestFn,
onBeforeSubmit?: RetrieveSubmitterFn,
}

export const test = (options: TestOptions) => {
const {
actionBeforeSubmit: retrieveSubmitterFn,
onSubmitted: testFn,
querySubmitter,
onSubmitted,
expectedStaticValue,
onLoaded,
onBeforeSubmit,
} = options;
let form: HTMLFormElement
let submitter: HTMLButtonElement | HTMLInputElement
@@ -49,15 +51,13 @@ export const test = (options: TestOptions) => {
.then((formResult: any) => {
[form] = Array.from(formResult);

if (typeof onLoaded === 'function') {
onLoaded(form);
}
onLoaded?.(form);
})

r = retrieveSubmitterFn(cy)
.then((submitterQueryEl: any) => {
[submitter] = Array.from(submitterQueryEl as any[])
})
onBeforeSubmit?.(cy);
r = querySubmitter(cy).then((submitterQueryEl: any) => {
[submitter] = Array.from(submitterQueryEl as any[])
})

if (typeof expectedStaticValue !== 'undefined') {
r.click()
@@ -66,7 +66,7 @@ export const test = (options: TestOptions) => {
.location('search')
.then((search: any) => {
setTimeout(() => {
testFn(form, submitter, search)
onSubmitted?.(form, submitter, search)
}, 0)
})
} else {
@@ -74,21 +74,20 @@ export const test = (options: TestOptions) => {
.location('search')
.then((search: any) => {
setTimeout(() => {
testFn(form, submitter, search)
onSubmitted?.(form, submitter, search)
}, 0);
})
}
} else {
r = retrieveSubmitterFn(new JSDOMDummyCypress())
const jsdomCy = new JSDOMDummyCypress()
onBeforeSubmit?.(jsdomCy);
r = querySubmitter(jsdomCy)
.then((submitterQueryEl: any) => {
[submitter] = Array.from(submitterQueryEl as any[]);
[form] = Array.from(window.document.getElementsByTagName('form'))

if (typeof onLoaded === 'function') {
onLoaded(form);
}

testFn(form, submitter, expectedStaticValue)
onLoaded?.(form);
onSubmitted?.(form, submitter, expectedStaticValue)
})

if (typeof expectedStaticValue !== 'undefined') {


+ 1
- 1
package.json Переглянути файл

@@ -1,6 +1,6 @@
{
"name": "@theoryofnekomata/formxtra",
"version": "1.0.3",
"version": "1.0.4",
"files": [
"dist",
"src"


+ 92
- 68
src/index.ts Переглянути файл

@@ -102,12 +102,10 @@ const setTextAreaFieldValue = (
elementsOfSameName: HTMLTextAreaElement[],
) => {
if (Array.isArray(value) && elementsOfSameName.length > 1) {
// eslint-disable-next-line no-param-reassign
textareaEl.value = value[nthOfName];
return;
}

// eslint-disable-next-line no-param-reassign
textareaEl.value = value as string;
};

@@ -146,7 +144,6 @@ const setSelectFieldValue = (
// If this happens, all values must correspond to a <select multiple> element.
const currentValue = valueArray[nthOfName] as string[];
Array.from(selectEl.options).forEach((el) => {
// eslint-disable-next-line no-param-reassign
el.selected = currentValue.includes(el.value);
});
return;
@@ -157,14 +154,12 @@ const setSelectFieldValue = (

if (elementsOfSameName.some((el) => el.multiple)) {
Array.from(selectEl.options).forEach((el) => {
// eslint-disable-next-line no-param-reassign
el.selected = (value as string[]).includes(el.value);
});
return;
}

Array.from(selectEl.options).forEach((el) => {
// eslint-disable-next-line no-param-reassign
el.selected = el.value === (value as string[])[nthOfName];
});

@@ -172,7 +167,6 @@ const setSelectFieldValue = (
}

Array.from(selectEl.options).forEach((el) => {
// eslint-disable-next-line no-param-reassign
el.selected = Array.isArray(value)
? (value as string[]).includes(el.value)
: el.value === value;
@@ -218,14 +212,12 @@ const setInputRadioFieldValue = (
const valueWhenChecked = inputEl.getAttribute(ATTRIBUTE_VALUE);

if (valueWhenChecked !== null) {
// eslint-disable-next-line no-param-reassign
inputEl.checked = (
Array.isArray(value) ? valueWhenChecked === value.slice(-1)[0] : valueWhenChecked === value
);
return;
}

// eslint-disable-next-line no-param-reassign
inputEl.checked = (
Array.isArray(value) ? value.includes('on') : value === 'on'
);
@@ -346,7 +338,6 @@ const setInputCheckboxFieldValue = (
const valueWhenChecked = inputEl.getAttribute(ATTRIBUTE_VALUE);

if (valueWhenChecked !== null) {
// eslint-disable-next-line no-param-reassign
inputEl.checked = (
Array.isArray(value)
? value.includes(valueWhenChecked)
@@ -357,7 +348,6 @@ const setInputCheckboxFieldValue = (

const newValue = parseBooleanValues(value);
if (typeof newValue === 'boolean') {
// eslint-disable-next-line no-param-reassign
inputEl.checked = newValue;
}
};
@@ -472,7 +462,6 @@ const setInputNumericFieldValue = (
elementsWithSameName: HTMLInputNumericElement[],
) => {
const valueArray = Array.isArray(value) ? value : [value];
// eslint-disable-next-line no-param-reassign
inputEl.valueAsNumber = Number(valueArray[elementsWithSameName.length > 1 ? nthOfName : 0]);
};

@@ -579,7 +568,6 @@ const setInputDateLikeFieldValue = (
const elementIndex = hasMultipleElementsOfSameName ? nthOfName : 0;

if (inputEl.type.toLowerCase() === INPUT_TYPE_DATE) {
// eslint-disable-next-line no-param-reassign
inputEl.value = new Date(
valueArray[elementIndex] as ConstructorParameters<typeof Date>[0],
)
@@ -589,7 +577,6 @@ const setInputDateLikeFieldValue = (
}

if (inputEl.type.toLowerCase() === INPUT_TYPE_DATETIME_LOCAL) {
// eslint-disable-next-line no-param-reassign
inputEl.value = new Date(
valueArray[elementIndex] as ConstructorParameters<typeof Date>[0],
)
@@ -598,7 +585,6 @@ const setInputDateLikeFieldValue = (
}

if (inputEl.type.toLowerCase() === INPUT_TYPE_MONTH) {
// eslint-disable-next-line no-param-reassign
inputEl.value = new Date(
valueArray[elementIndex] as ConstructorParameters<typeof Date>[0],
)
@@ -765,12 +751,10 @@ const setInputHiddenFieldValue = (
}

if (Array.isArray(value) && elementsWithSameName.length > 1) {
// eslint-disable-next-line no-param-reassign
inputEl.value = value[nthOfName];
return;
}

// eslint-disable-next-line no-param-reassign
inputEl.value = value as string;
};

@@ -866,12 +850,10 @@ const setInputGenericFieldValue = (
elementsWithSameName: HTMLInputElement[],
) => {
if (Array.isArray(value) && elementsWithSameName.length > 1) {
// eslint-disable-next-line no-param-reassign
inputEl.value = value[nthOfName];
return;
}

// eslint-disable-next-line no-param-reassign
inputEl.value = value as string;
};

@@ -1157,11 +1139,6 @@ export const getFormValues = (form: HTMLFormElement, options = {} as GetFormValu
...theFormValues,
[fieldName]: fieldValue,
};

// return {
// ...theFormValues,
// [fieldName]: [...oldFormValue, fieldValue],
// };
},
{} as Record<string, unknown>,
);
@@ -1201,6 +1178,64 @@ const normalizeValues = (values: unknown): Record<string, unknown | unknown[]> =
return values as Record<string, unknown | unknown[]>;
};

/**
* Performs setting of form values.
* @param fieldElementEntries - Entries of field names and their corresponding elements.
* @param elementsWithSameName - Map of field names to elements or array of elements if they have
* duplicates.
* @param objectValues - Values to apply to the form.
*/
const doSetFormValues = (
fieldElementEntries: [string, HTMLElementWithName][],
elementsWithSameName: Record<string, HTMLElement[]>,
objectValues: Record<string, unknown>,
) => {
const nthElementOfName = {} as Record<string, number>;
fieldElementEntries
.forEach(([, el]) => {
nthElementOfName[el.name] = (
typeof nthElementOfName[el.name] === 'number'
? nthElementOfName[el.name] + 1
: 0
);

setFieldValue(
el,
objectValues[el.name],
nthElementOfName[el.name],
elementsWithSameName[el.name],
);
});
};

/**
* Builds a map of field names with elements that may contain duplicates.
* @param fieldElementEntries - Entries of field names and their corresponding elements.
* @returns The map of field names to elements or array of elements if they have duplicates.
*/
const getElementsOfSameName = (fieldElementEntries: [string, HTMLElementWithName][]) => (
fieldElementEntries.reduce(
(currentCount, [, el]) => {
if (el.tagName === TAG_NAME_INPUT && el.type === INPUT_TYPE_RADIO) {
return {
...currentCount,
[el.name]: [el],
};
}

return {
...currentCount,
[el.name]: (
Array.isArray(currentCount[el.name])
? [...currentCount[el.name], el]
: [el]
),
};
},
{} as Record<string, HTMLElement[]>,
)
);

/**
* Sets the values of all the fields within the form through accessing the DOM nodes. Partial values
* may be passed to set values only to certain form fields.
@@ -1212,60 +1247,49 @@ export const setFormValues = (
values: unknown,
) => {
assertIsFormElement(form, 'getFormValues');

const valuesType = typeof values;
if (!['string', 'object'].includes(valuesType)) {
throw new TypeError(`Invalid values argument provided for setFormValues(). Expected "object" or "string", got ${valuesType}`);
}

if (!values) {
// reject `null`
return;
}

const fieldElements = filterFieldElements(form);
const objectValues = normalizeValues(values);
const fieldElements = filterFieldElements(form);
const filteredFieldElements = fieldElements.filter(([, el]) => el.name in objectValues);
const elementsWithSameName = getElementsOfSameName(filteredFieldElements);
doSetFormValues(filteredFieldElements, elementsWithSameName, objectValues);
};

const elementsWithSameName = fieldElements
.filter(([, el]) => el.name in objectValues)
.reduce(
(currentCount, [, el]) => {
if (el.tagName === TAG_NAME_INPUT && el.type === INPUT_TYPE_RADIO) {
return {
...currentCount,
[el.name]: [el],
};
}

return {
...currentCount,
[el.name]: (
Array.isArray(currentCount[el.name])
? [...currentCount[el.name], el]
: [el]
),
};
},
{} as Record<string, HTMLElement[]>,
);

const nthElementOfName = {} as Record<string, number>;

fieldElements
.filter(([, el]) => el.name in objectValues)
.forEach(([, el]) => {
nthElementOfName[el.name] = (
typeof nthElementOfName[el.name] === 'number'
? nthElementOfName[el.name] + 1
: 0
);

setFieldValue(
el,
objectValues[el.name],
nthElementOfName[el.name],
elementsWithSameName[el.name],
);
});
/**
* Clears the values of all the fields within the form through accessing the DOM nodes. Partial
* values may be passed to set values only to certain form fields.
*
* **Note:** This does not reset the inputs' values, instead only unsets them.
*
* @param form - The form.
* @param fieldNames - The field names to clear their corresponding element(s).
*/
export const clearFormValues = (
form: HTMLFormElement,
fieldNames: string | string[],
) => {
assertIsFormElement(form, 'clearFormValues');
const fieldNamesNormalized = Array.isArray(fieldNames) ? fieldNames : [fieldNames];
const fieldElements = filterFieldElements(form);
const filteredFieldElements = fieldElements.filter(
([, el]) => fieldNamesNormalized.includes(el.name),
);
const elementsWithSameName = getElementsOfSameName(filteredFieldElements);
const objectValues = Object.fromEntries(
Object.entries(elementsWithSameName).map(([key]) => [
key, '',
]),
);
doSetFormValues(filteredFieldElements, elementsWithSameName, objectValues);
};

/**
@@ -1276,7 +1300,7 @@ export const setFormValues = (
* @see getFormValues
*/
export default (...args: Parameters<typeof getFormValues>) => {
// eslint-disable-next-line no-console
console.warn('Default import is deprecated. Use named export `getFormValues()` instead. This default export is only for backwards compatibility.');
const logger = typeof console !== 'undefined' ? console : undefined;
logger?.warn?.('Default import is deprecated. Use named export `getFormValues()` instead. This default export is only for backwards compatibility.');
return getFormValues(...args);
};

Завантаження…
Відмінити
Зберегти