@@ -24,8 +24,8 @@ describe('checkbox', () => { | |||
it('should have no form values', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
const before = utils.makeSearchParams(values) | |||
.toString(); | |||
@@ -42,8 +42,8 @@ describe('checkbox', () => { | |||
it('should have false checked value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, | |||
{ | |||
submitter, | |||
@@ -79,8 +79,8 @@ describe('checkbox', () => { | |||
it('should have single form value on a single field', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -127,8 +127,8 @@ describe('checkbox', () => { | |||
it('should get both values', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -144,13 +144,13 @@ describe('checkbox', () => { | |||
it('should set both values', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { | |||
enabled: ['hello 3', 'hello 4'], | |||
}) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -187,11 +187,11 @@ describe('checkbox', () => { | |||
it('should check for boolean "true"', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: true, }) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBe('on'); | |||
}, | |||
@@ -201,11 +201,11 @@ describe('checkbox', () => { | |||
it('should check for string "true"', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: 'true', }) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBe('on'); | |||
}, | |||
@@ -215,11 +215,11 @@ describe('checkbox', () => { | |||
it('should check for string "yes"', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: 'yes', }) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBe('on'); | |||
}, | |||
@@ -229,11 +229,11 @@ describe('checkbox', () => { | |||
it('should check for string "on"', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: 'on', }) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBe('on'); | |||
}, | |||
@@ -243,13 +243,13 @@ describe('checkbox', () => { | |||
it('should uncheck for boolean "false"', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: false, }) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).not.toBe('on'); | |||
expect(values['enabled']).toBeUndefined() | |||
}, | |||
expectedStaticValue: '', | |||
}); | |||
@@ -257,13 +257,13 @@ describe('checkbox', () => { | |||
it('should uncheck for string "false"', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: 'false', }) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).not.toBe('on'); | |||
expect(values['enabled']).toBeUndefined() | |||
}, | |||
expectedStaticValue: '', | |||
}); | |||
@@ -271,13 +271,13 @@ describe('checkbox', () => { | |||
it('should uncheck for string "no"', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: 'no', }) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).not.toBe('on'); | |||
expect(values['enabled']).toBeUndefined() | |||
}, | |||
expectedStaticValue: '', | |||
}); | |||
@@ -285,13 +285,13 @@ describe('checkbox', () => { | |||
it('should uncheck for string "off"', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: 'off', }) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).not.toBe('on'); | |||
expect(values['enabled']).toBeUndefined() | |||
}, | |||
expectedStaticValue: '', | |||
}); | |||
@@ -299,11 +299,11 @@ describe('checkbox', () => { | |||
it('should check for number "1"', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: 1, }) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBe('on'); | |||
}, | |||
@@ -313,11 +313,11 @@ describe('checkbox', () => { | |||
it('should check for string "1"', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: '1', }) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBe('on'); | |||
}, | |||
@@ -327,13 +327,13 @@ describe('checkbox', () => { | |||
it('should uncheck for number "0"', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: 0, }) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).not.toBe('on'); | |||
expect(values['enabled']).toBeUndefined() | |||
}, | |||
expectedStaticValue: '', | |||
}); | |||
@@ -341,13 +341,13 @@ describe('checkbox', () => { | |||
it('should uncheck for string "0"', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: '0', }) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).not.toBe('on'); | |||
expect(values['enabled']).toBeUndefined() | |||
}, | |||
expectedStaticValue: '', | |||
}); | |||
@@ -355,13 +355,13 @@ describe('checkbox', () => { | |||
it('should uncheck for object "null"', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: null, }) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).not.toBe('on'); | |||
expect(values['enabled']).toBeUndefined() | |||
}, | |||
expectedStaticValue: '', | |||
}); | |||
@@ -369,13 +369,13 @@ describe('checkbox', () => { | |||
it('should uncheck for string "null"', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: 'null', }) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).not.toBe('on'); | |||
expect(values['enabled']).toBeUndefined() | |||
}, | |||
expectedStaticValue: '', | |||
}); | |||
@@ -0,0 +1,393 @@ | |||
import getFormValuesDeprecated, { | |||
getFormValues, | |||
setFormValues, | |||
isFieldElement, | |||
isElementValueIncludedInFormSubmit, | |||
getValue, | |||
} from '../../src'; | |||
import * as utils from '../utils' | |||
describe('misc', () => { | |||
describe('core', () => { | |||
beforeEach(utils.setup(` | |||
<!DOCTYPE html> | |||
<html lang="en-PH"> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<title>Misc/Blank</title> | |||
</head> | |||
<body> | |||
<form> | |||
<button type="submit">Submit</button> | |||
</form> | |||
</body> | |||
</html> | |||
`)) | |||
it('should call console.warn for deprecated default import usage', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (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 | |||
}; | |||
getFormValuesDeprecated(form, { submitter }); | |||
expect(consoleWarnCalled).toBe(true); | |||
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"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
getFormValues(0 as unknown as HTMLFormElement, {}); | |||
} catch { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(true); | |||
}, | |||
}); | |||
}); | |||
it('should throw an error when providing null as form to getFormValues', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
getFormValues(null as unknown as HTMLFormElement, {}); | |||
} catch { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(true); | |||
}, | |||
}); | |||
}); | |||
it('should throw an error when providing a different element type as form to getFormValues', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
getFormValues(document.body as unknown as HTMLFormElement, {}); | |||
} catch { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(true); | |||
}, | |||
}); | |||
}); | |||
it('should throw an error when providing invalid argument type as form to setFormValues', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(0 as unknown as HTMLFormElement, {}); | |||
} catch { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(true); | |||
}, | |||
}); | |||
}); | |||
it('should throw an error when providing null as form to setFormValues', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(null as unknown as HTMLFormElement, {}); | |||
} catch { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(true); | |||
}, | |||
}); | |||
}); | |||
it('should throw an error when providing a different element type as form to setFormValues', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(document.body as unknown as HTMLFormElement, {}); | |||
} catch { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(true); | |||
}, | |||
}); | |||
}); | |||
it('should throw an error when providing invalid argument type as values to setFormValues', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(form, 0); | |||
} catch { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(true); | |||
}, | |||
}); | |||
}); | |||
it('should not throw an error when providing null as form to setFormValues', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(form, null); | |||
} catch (e) { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(false); | |||
}, | |||
}); | |||
}); | |||
it('should throw an error when providing undefined as form to setFormValues', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(form, undefined); | |||
} catch (e) { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(true); | |||
}, | |||
}); | |||
}); | |||
}); | |||
describe('utilities', () => { | |||
beforeEach(utils.setup(` | |||
<!DOCTYPE html> | |||
<html lang="en-PH"> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<title>Misc/Utilities</title> | |||
</head> | |||
<body> | |||
<form> | |||
<input id="input" type="text" name="foobar" /> | |||
<input id="notField" type="text" /> | |||
<input id="disabled" disabled type="text" name="disabled" /> | |||
<meter id="meter" min="1" max="10" value="5" /> | |||
<button type="submit">Submit</button> | |||
</form> | |||
</body> | |||
</html> | |||
`)); | |||
it('should check for valid field elements value', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const meter = document.getElementById('meter'); | |||
expect(getValue(meter)).toBe(5); | |||
}, | |||
}); | |||
}); | |||
it('should check for invalid field elements value', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
expect(getValue(document.body)).toBe(null); | |||
}, | |||
}); | |||
}); | |||
it('should check for elements as included fields', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const input = document.getElementById('input'); | |||
expect(isElementValueIncludedInFormSubmit(input)).toBe(true); | |||
}, | |||
}); | |||
}); | |||
it('should check for elements as excluded fields', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const notField = document.getElementById('notField'); | |||
expect(isElementValueIncludedInFormSubmit(notField)).toBe(false); | |||
const disabled = document.getElementById('disabled'); | |||
expect(isElementValueIncludedInFormSubmit(disabled)).toBe(false); | |||
const meter = document.getElementById('meter'); | |||
expect(isElementValueIncludedInFormSubmit(meter)).toBe(false); | |||
}, | |||
}); | |||
}); | |||
it('should check for elements as valid for fields', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const input = document.getElementById('input'); | |||
expect(isFieldElement(input)).toBe(true); | |||
const disabled = document.getElementById('disabled'); | |||
expect(isFieldElement(disabled)).toBe(true); | |||
}, | |||
}); | |||
}); | |||
it('should check for elements as invalid for fields', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const meter = document.getElementById('meter'); | |||
expect(isFieldElement(meter)).toBe(false); | |||
const notField = document.getElementById('notField'); | |||
expect(isFieldElement(notField)).toBe(false); | |||
}, | |||
}); | |||
}); | |||
}); | |||
describe('setting values', () => { | |||
beforeEach(utils.setup(` | |||
<!DOCTYPE html> | |||
<html lang="en-PH"> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<title>Misc/Blank</title> | |||
</head> | |||
<body> | |||
<form> | |||
<input type="text" name="foobar" /> | |||
<button type="submit">Submit</button> | |||
</form> | |||
</body> | |||
</html> | |||
`)) | |||
it('should parse string values for setFormValues', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(form, 'foobar=baz'); | |||
} catch (e) { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(false); | |||
expect(getFormValues(form)).toEqual({ foobar: 'baz', }); | |||
}, | |||
}) | |||
}); | |||
it('should parse entries values for setFormValues', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(form, [['foobar', 'baz']]); | |||
} catch (e) { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(false); | |||
expect(getFormValues(form)).toEqual({ foobar: 'baz', }); | |||
}, | |||
}) | |||
}); | |||
it('should parse URLSearchParams values for setFormValues', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(form, new URLSearchParams('foobar=baz')); | |||
} catch (e) { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(false); | |||
expect(getFormValues(form)).toEqual({ foobar: 'baz', }); | |||
}, | |||
}) | |||
}); | |||
it('should parse object values for setFormValues', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(form, { foobar: 'baz', }); | |||
} catch (e) { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(false); | |||
expect(getFormValues(form)).toEqual({ foobar: 'baz', }); | |||
}, | |||
}) | |||
}); | |||
}); | |||
describe('duplicates', () => { | |||
beforeEach(utils.setup(` | |||
<!DOCTYPE html> | |||
<html lang="en-PH"> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<title>Misc/Blank</title> | |||
</head> | |||
<body> | |||
<form> | |||
<input type="text" name="foobar" /> | |||
<input type="text" name="foobar" /> | |||
<input type="text" name="foobar" /> | |||
<button type="submit">Submit</button> | |||
</form> | |||
</body> | |||
</html> | |||
`)); | |||
it('should parse duplicates correctly', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { foobar: ['foo', 'bar', 'baz']}) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
expect(getFormValues(form)).toEqual({ foobar: ['foo', 'bar', 'baz'], }); | |||
}, | |||
}) | |||
}); | |||
}); | |||
}); |
@@ -24,8 +24,8 @@ describe('date', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -41,8 +41,8 @@ describe('date', () => { | |||
it('should enable Date representation', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (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 | |||
// object? | |||
@@ -78,8 +78,8 @@ describe('date', () => { | |||
it('should have blank form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -114,8 +114,8 @@ describe('date', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -155,8 +155,8 @@ describe('date', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -193,11 +193,11 @@ describe('date', () => { | |||
it('should have form values set', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
preAction: (form: HTMLFormElement) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { hello: new Date('2000-01-01'), }) | |||
}, | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -238,8 +238,8 @@ describe('date', () => { | |||
it('should get both values', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -255,13 +255,13 @@ describe('date', () => { | |||
it('should set both values', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { | |||
hello: ['2006-06-06', '2005-05-05'], | |||
}) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -24,8 +24,8 @@ describe('date', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -41,8 +41,8 @@ describe('date', () => { | |||
it('should enable Date representation', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (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 | |||
// object? | |||
@@ -78,8 +78,8 @@ describe('date', () => { | |||
it('should have blank form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -114,8 +114,8 @@ describe('date', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -155,8 +155,8 @@ describe('date', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -193,11 +193,11 @@ describe('date', () => { | |||
it('should have form values set', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
preAction: (form: HTMLFormElement) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { hello: new Date('2000-01-01T13:37'), }) | |||
}, | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -238,8 +238,8 @@ describe('date', () => { | |||
it('should get both values', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -255,13 +255,13 @@ describe('date', () => { | |||
it('should set both values', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { | |||
hello: ['2006-06-06T13:37', '2005-05-05T13:37'], | |||
}) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -24,8 +24,8 @@ describe('file', () => { | |||
it('should have no form values when no file is selected', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -41,14 +41,14 @@ describe('file', () => { | |||
it('should have single form value when a file is selected', () => { | |||
utils.test({ | |||
action: (cy: any) => { | |||
actionBeforeSubmit: (cy: any) => { | |||
cy | |||
.get('[name="hello"]') | |||
.attachFile('uploads/data.json') | |||
return cy.get('[type="submit"]') | |||
}, | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -64,14 +64,14 @@ describe('file', () => { | |||
it('should retrieve the file list upon setting appropriate option', () => { | |||
utils.test({ | |||
action: (cy: any) => { | |||
actionBeforeSubmit: (cy: any) => { | |||
cy | |||
.get('[name="hello"]') | |||
.attachFile('uploads/data.json') | |||
return cy.get('[type="submit"]') | |||
}, | |||
test: (form: HTMLFormElement, submitter: any) => { | |||
onSubmitted: (form: HTMLFormElement, submitter: any) => { | |||
const formValues = getFormValues(form, | |||
{ | |||
submitter, | |||
@@ -86,11 +86,11 @@ describe('file', () => { | |||
it('should do nothing when attempting to set the value of the file', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { hello: 'data.json' }); | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any) => { | |||
const formValues = getFormValues( | |||
form, | |||
{ | |||
@@ -127,8 +127,8 @@ describe('file', () => { | |||
it('should have no form values when no file is selected', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -144,14 +144,14 @@ describe('file', () => { | |||
it('should have single form value when a file is selected', () => { | |||
utils.test({ | |||
action: (cy: any) => { | |||
actionBeforeSubmit: (cy: any) => { | |||
cy | |||
.get('[name="hello"]') | |||
.attachFile(['uploads/data.json', 'uploads/data2.json']) | |||
return cy.get('[type="submit"]') | |||
}, | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -165,14 +165,14 @@ describe('file', () => { | |||
it('should retrieve the file list upon setting appropriate option', () => { | |||
utils.test({ | |||
action: (cy: any) => { | |||
actionBeforeSubmit: (cy: any) => { | |||
cy | |||
.get('[name="hello"]') | |||
.attachFile(['uploads/data.json', 'uploads/data2.json']) | |||
return cy.get('[type="submit"]') | |||
}, | |||
test: (form: HTMLFormElement, submitter: any) => { | |||
onSubmitted: (form: HTMLFormElement, submitter: any) => { | |||
const formValues = getFormValues(form, | |||
{ | |||
submitter, | |||
@@ -1,396 +1,7 @@ | |||
import getFormValuesDeprecated, { | |||
getFormValues, | |||
setFormValues, | |||
isFieldElement, | |||
isElementValueIncludedInFormSubmit, | |||
getValue, | |||
} from '../../src'; | |||
import { getFormValues, setFormValues } from '../../src'; | |||
import * as utils from '../utils' | |||
describe('misc', () => { | |||
describe('core', () => { | |||
beforeEach(utils.setup(` | |||
<!DOCTYPE html> | |||
<html lang="en-PH"> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<title>Misc/Blank</title> | |||
</head> | |||
<body> | |||
<form> | |||
<button type="submit">Submit</button> | |||
</form> | |||
</body> | |||
</html> | |||
`)) | |||
it('should call console.warn for deprecated default import usage', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let consoleWarnCalled = false | |||
const defaultConsoleWarn = console.warn | |||
console.warn = (...args: unknown[]) => { | |||
consoleWarnCalled = true | |||
}; | |||
getFormValuesDeprecated(form, { submitter }); | |||
expect(consoleWarnCalled).toBe(true); | |||
console.warn = defaultConsoleWarn; | |||
}, | |||
}); | |||
}); | |||
it('should throw an error when providing invalid argument type as form to getFormValues', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
getFormValues(0 as unknown as HTMLFormElement, {}); | |||
} catch { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(true); | |||
}, | |||
}); | |||
}); | |||
it('should throw an error when providing null as form to getFormValues', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
getFormValues(null as unknown as HTMLFormElement, {}); | |||
} catch { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(true); | |||
}, | |||
}); | |||
}); | |||
it('should throw an error when providing a different element type as form to getFormValues', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
getFormValues(document.body as unknown as HTMLFormElement, {}); | |||
} catch { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(true); | |||
}, | |||
}); | |||
}); | |||
it('should throw an error when providing invalid argument type as form to setFormValues', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(0 as unknown as HTMLFormElement, {}); | |||
} catch { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(true); | |||
}, | |||
}); | |||
}); | |||
it('should throw an error when providing null as form to setFormValues', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(null as unknown as HTMLFormElement, {}); | |||
} catch { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(true); | |||
}, | |||
}); | |||
}); | |||
it('should throw an error when providing a different element type as form to setFormValues', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(document.body as unknown as HTMLFormElement, {}); | |||
} catch { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(true); | |||
}, | |||
}); | |||
}); | |||
it('should throw an error when providing invalid argument type as values to setFormValues', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(form, 0); | |||
} catch { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(true); | |||
}, | |||
}); | |||
}); | |||
it('should not throw an error when providing null as form to setFormValues', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(form, null); | |||
} catch (e) { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(false); | |||
}, | |||
}); | |||
}); | |||
it('should throw an error when providing undefined as form to setFormValues', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(form, undefined); | |||
} catch (e) { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(true); | |||
}, | |||
}); | |||
}); | |||
}); | |||
describe('utilities', () => { | |||
beforeEach(utils.setup(` | |||
<!DOCTYPE html> | |||
<html lang="en-PH"> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<title>Misc/Utilities</title> | |||
</head> | |||
<body> | |||
<form> | |||
<input id="input" type="text" name="foobar" /> | |||
<input id="notField" type="text" /> | |||
<input id="disabled" disabled type="text" name="disabled" /> | |||
<meter id="meter" min="1" max="10" value="5" /> | |||
<button type="submit">Submit</button> | |||
</form> | |||
</body> | |||
</html> | |||
`)); | |||
it('should check for valid field elements value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const meter = document.getElementById('meter'); | |||
expect(getValue(meter)).toBe(5); | |||
}, | |||
}); | |||
}); | |||
it('should check for invalid field elements value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
expect(getValue(document.body)).toBe(null); | |||
}, | |||
}); | |||
}); | |||
it('should check for elements as included fields', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const input = document.getElementById('input'); | |||
expect(isElementValueIncludedInFormSubmit(input)).toBe(true); | |||
}, | |||
}); | |||
}); | |||
it('should check for elements as excluded fields', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const notField = document.getElementById('notField'); | |||
expect(isElementValueIncludedInFormSubmit(notField)).toBe(false); | |||
const disabled = document.getElementById('disabled'); | |||
expect(isElementValueIncludedInFormSubmit(disabled)).toBe(false); | |||
const meter = document.getElementById('meter'); | |||
expect(isElementValueIncludedInFormSubmit(meter)).toBe(false); | |||
}, | |||
}); | |||
}); | |||
it('should check for elements as valid for fields', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const input = document.getElementById('input'); | |||
expect(isFieldElement(input)).toBe(true); | |||
const disabled = document.getElementById('disabled'); | |||
expect(isFieldElement(disabled)).toBe(true); | |||
}, | |||
}); | |||
}); | |||
it('should check for elements as invalid for fields', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const meter = document.getElementById('meter'); | |||
expect(isFieldElement(meter)).toBe(false); | |||
const notField = document.getElementById('notField'); | |||
expect(isFieldElement(notField)).toBe(false); | |||
}, | |||
}); | |||
}); | |||
}); | |||
describe('setting values', () => { | |||
beforeEach(utils.setup(` | |||
<!DOCTYPE html> | |||
<html lang="en-PH"> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<title>Misc/Blank</title> | |||
</head> | |||
<body> | |||
<form> | |||
<input type="text" name="foobar" /> | |||
<button type="submit">Submit</button> | |||
</form> | |||
</body> | |||
</html> | |||
`)) | |||
it('should parse string values for setFormValues', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(form, 'foobar=baz'); | |||
} catch (e) { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(false); | |||
expect(getFormValues(form)).toEqual({ foobar: 'baz', }); | |||
}, | |||
}) | |||
}); | |||
it('should parse entries values for setFormValues', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(form, [['foobar', 'baz']]); | |||
} catch (e) { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(false); | |||
expect(getFormValues(form)).toEqual({ foobar: 'baz', }); | |||
}, | |||
}) | |||
}); | |||
it('should parse URLSearchParams values for setFormValues', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(form, new URLSearchParams('foobar=baz')); | |||
} catch (e) { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(false); | |||
expect(getFormValues(form)).toEqual({ foobar: 'baz', }); | |||
}, | |||
}) | |||
}); | |||
it('should parse object values for setFormValues', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
let isThrown = false; | |||
try { | |||
setFormValues(form, { foobar: 'baz', }); | |||
} catch (e) { | |||
isThrown = true; | |||
} | |||
expect(isThrown).toBe(false); | |||
expect(getFormValues(form)).toEqual({ foobar: 'baz', }); | |||
}, | |||
}) | |||
}); | |||
}); | |||
describe('duplicates', () => { | |||
beforeEach(utils.setup(` | |||
<!DOCTYPE html> | |||
<html lang="en-PH"> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<title>Misc/Blank</title> | |||
</head> | |||
<body> | |||
<form> | |||
<input type="text" name="foobar" /> | |||
<input type="text" name="foobar" /> | |||
<input type="text" name="foobar" /> | |||
<button type="submit">Submit</button> | |||
</form> | |||
</body> | |||
</html> | |||
`)); | |||
it('should parse duplicates correctly', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
setFormValues(form, { foobar: ['foo', 'bar', 'baz']}) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
expect(getFormValues(form)).toEqual({ foobar: ['foo', 'bar', 'baz'], }); | |||
}, | |||
}) | |||
}); | |||
}); | |||
describe('blank', () => { | |||
beforeEach(utils.setup(` | |||
<!DOCTYPE html> | |||
@@ -409,8 +20,8 @@ describe('misc', () => { | |||
it('should have blank form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -569,7 +180,7 @@ describe('misc', () => { | |||
it('should have correct form values', () => { | |||
utils.test({ | |||
action: (cy) => { | |||
actionBeforeSubmit: (cy) => { | |||
cy.get('[name="first_name"]') | |||
.type('John') | |||
cy.get('[name="middle_name"]') | |||
@@ -619,7 +230,7 @@ describe('misc', () => { | |||
.type('Test content\n\nNew line\n\nAnother line') | |||
return cy.get('[name="submit"][value="Hi"]') | |||
}, | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -634,8 +245,8 @@ describe('misc', () => { | |||
it('should have filled form values', () => { | |||
utils.test({ | |||
action: (cy) => cy.wait(3000).get('[name="submit"][value="Hi"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy) => cy.wait(3000).get('[name="submit"][value="Hi"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -644,7 +255,7 @@ describe('misc', () => { | |||
expect(before) | |||
.toEqual(after); | |||
}, | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { | |||
first_name: 'John', | |||
middle_name: 'Marcelo', | |||
@@ -24,8 +24,8 @@ describe('month', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -41,8 +41,8 @@ describe('month', () => { | |||
it('should enable Date representation', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (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 | |||
// object? | |||
@@ -78,8 +78,8 @@ describe('month', () => { | |||
it('should have blank form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -114,8 +114,8 @@ describe('month', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -155,8 +155,8 @@ describe('month', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -193,11 +193,11 @@ describe('month', () => { | |||
it('should have form values set', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
preAction: (form: HTMLFormElement) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { hello: '2003-05', }) | |||
}, | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -238,8 +238,8 @@ describe('month', () => { | |||
it('should get both values', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -255,13 +255,13 @@ describe('month', () => { | |||
it('should set both values', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { | |||
hello: ['2003-04', '2003-02'], | |||
}) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -24,8 +24,8 @@ describe('number', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter, forceNumberValues: true, })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -65,8 +65,8 @@ describe('number', () => { | |||
it('should have blank form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -101,8 +101,8 @@ describe('number', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -142,8 +142,8 @@ describe('number', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -180,11 +180,11 @@ describe('number', () => { | |||
it('should have form values set', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
preAction: (form: HTMLFormElement) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { hello: 5, }) | |||
}, | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter, forceNumberValues: true, })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -225,8 +225,8 @@ describe('number', () => { | |||
it('should get both values', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter, forceNumberValues: true, })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -242,13 +242,13 @@ describe('number', () => { | |||
it('should set both values', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { | |||
hello: [4, 2], | |||
}) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -0,0 +1,419 @@ | |||
import { getFormValues, setFormValues } from '../../src'; | |||
import * as utils from '../utils' | |||
describe('radio', () => { | |||
describe('basic', () => { | |||
beforeEach(utils.setup(` | |||
<!DOCTYPE html> | |||
<html lang="en-PH"> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<title>Radio/Basic</title> | |||
</head> | |||
<body> | |||
<form> | |||
<label> | |||
<span>Hello</span> | |||
<input type="radio" name="enabled" /> | |||
</label> | |||
<button type="submit">Submit</button> | |||
</form> | |||
</body> | |||
</html> | |||
`)) | |||
it('should have no form values', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
const before = utils.makeSearchParams(values) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
.toString(); | |||
expect(values['enabled']) | |||
.toBeUndefined(); | |||
expect(before) | |||
.toEqual(after); | |||
}, | |||
expectedStaticValue: '', | |||
}); | |||
}); | |||
}); | |||
describe('checked', () => { | |||
beforeEach(utils.setup(` | |||
<!DOCTYPE html> | |||
<html lang="en-PH"> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<title>Radio/Checked</title> | |||
</head> | |||
<body> | |||
<form> | |||
<label> | |||
<span>Hello</span> | |||
<input type="radio" name="enabled" checked /> | |||
</label> | |||
<button type="submit">Submit</button> | |||
</form> | |||
</body> | |||
</html> | |||
`)) | |||
it('should have single form value on a single field', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
.toString(); | |||
expect(before) | |||
.toEqual(after); | |||
}, | |||
expectedStaticValue: 'enabled=on', | |||
}); | |||
}); | |||
}); | |||
describe('duplicate', () => { | |||
beforeEach(utils.setup(` | |||
<!DOCTYPE html> | |||
<html lang="en-PH"> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<title>Radio/Duplicate</title> | |||
</head> | |||
<body> | |||
<form> | |||
<label> | |||
<span>Hello 1</span> | |||
<input type="radio" name="enabled" value="hello 1" checked /> | |||
</label> | |||
<label> | |||
<span>Hello 2</span> | |||
<input type="radio" name="enabled" value="hello 2" checked /> | |||
</label> | |||
<label> | |||
<span>Hello 3</span> | |||
<input type="radio" name="enabled" value="hello 3" /> | |||
</label> | |||
<label> | |||
<span>Hello 4</span> | |||
<input type="radio" name="enabled" value="hello 4" /> | |||
</label> | |||
<button type="submit">Submit</button> | |||
</form> | |||
</body> | |||
</html> | |||
`)); | |||
it('should get last value as checked', () => { | |||
utils.test({ | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
.toString(); | |||
expect(before) | |||
.toEqual(after); | |||
}, | |||
expectedStaticValue: { | |||
enabled: 'hello 2', | |||
}, | |||
}); | |||
}); | |||
it('should set to last value', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { | |||
enabled: ['hello 3', 'hello 4'], | |||
}) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
.toString(); | |||
expect(before) | |||
.toEqual(after); | |||
}, | |||
expectedStaticValue: { | |||
enabled: 'hello 4', | |||
}, | |||
}); | |||
}); | |||
}); | |||
describe('setting values', () => { | |||
beforeEach(utils.setup(` | |||
<!DOCTYPE html> | |||
<html lang="en-PH"> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<title>Radio/Setting Values</title> | |||
</head> | |||
<body> | |||
<form> | |||
<label> | |||
<span>Hello</span> | |||
<input type="radio" name="enabled" value="default" checked /> | |||
<input type="radio" name="enabled" /> | |||
<input type="radio" name="enabled" value="true" /> | |||
<input type="radio" name="enabled" value="yes" /> | |||
<input type="radio" name="enabled" value="1" /> | |||
<input type="radio" name="enabled" value="false" /> | |||
<input type="radio" name="enabled" value="no" /> | |||
<input type="radio" name="enabled" value="off" /> | |||
<input type="radio" name="enabled" value="0" /> | |||
<input type="radio" name="enabled" value="null" /> | |||
</label> | |||
<button type="submit">Submit</button> | |||
</form> | |||
</body> | |||
</html> | |||
`)) | |||
it('should uncheck for boolean "true"', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: true, }) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBeUndefined() | |||
}, | |||
expectedStaticValue: '', | |||
}); | |||
}); | |||
it('should check for string "true"', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: 'true', }) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBe('true'); | |||
}, | |||
expectedStaticValue: 'enabled=true', | |||
}); | |||
}); | |||
it('should check for string "yes"', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: 'yes', }) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBe('yes'); | |||
}, | |||
expectedStaticValue: 'enabled=yes', | |||
}); | |||
}); | |||
it('should check for string "on"', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: 'on', }) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBe('on'); | |||
}, | |||
expectedStaticValue: 'enabled=on', | |||
}); | |||
}); | |||
it('should uncheck for boolean "false"', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: false, }) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBeUndefined() | |||
}, | |||
expectedStaticValue: '', | |||
}); | |||
}); | |||
it('should check for string "false"', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: 'false', }) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBe('false'); | |||
}, | |||
expectedStaticValue: 'enabled=false', | |||
}); | |||
}); | |||
it('should check for string "no"', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: 'no', }) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBe('no') | |||
}, | |||
expectedStaticValue: 'enabled=no', | |||
}); | |||
}); | |||
it('should check for string "off"', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: 'off', }) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBe('off'); | |||
}, | |||
expectedStaticValue: 'enabled=off', | |||
}); | |||
}); | |||
it('should uncheck for number "1"', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: 1, }) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBeUndefined(); | |||
}, | |||
expectedStaticValue: '', | |||
}); | |||
}); | |||
it('should check for string "1"', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: '1', }) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBe('1'); | |||
}, | |||
expectedStaticValue: 'enabled=1', | |||
}); | |||
}); | |||
it('should uncheck for number "0"', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: 0, }) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBeUndefined() | |||
}, | |||
expectedStaticValue: '', | |||
}); | |||
}); | |||
it('should check for string "0"', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: '0', }) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBe('0') | |||
}, | |||
expectedStaticValue: 'enabled=0', | |||
}); | |||
}); | |||
it('should uncheck for object "null"', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: null, }) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBeUndefined() | |||
}, | |||
expectedStaticValue: '', | |||
}); | |||
}); | |||
it('should check for string "null"', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: 'null', }) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBe('null'); | |||
}, | |||
expectedStaticValue: 'null', | |||
}); | |||
}); | |||
it('should check for boolean "true"', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: true, }) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBeUndefined() | |||
}, | |||
expectedStaticValue: '', | |||
}); | |||
}); | |||
it('should check valueless radio for last value on', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: ['foo', 'bar', 'baz', 'on'], }) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBe('on') | |||
}, | |||
expectedStaticValue: 'enabled=on', | |||
}); | |||
}); | |||
it('should check radio with value for last value', () => { | |||
utils.test({ | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { enabled: ['foo', 'bar', 'baz', 'on', 'default', 'true'], }) | |||
}, | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const values = getFormValues(form, { submitter }) | |||
expect(values['enabled']).toBe('true') | |||
}, | |||
expectedStaticValue: 'enabled=true', | |||
}); | |||
}); | |||
}); | |||
}); |
@@ -24,8 +24,8 @@ describe('range', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter, forceNumberValues: true, })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -65,8 +65,8 @@ describe('range', () => { | |||
it('should have blank form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -101,8 +101,8 @@ describe('range', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -142,8 +142,8 @@ describe('range', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -180,11 +180,11 @@ describe('range', () => { | |||
it('should have form values set', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
preAction: (form: HTMLFormElement) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { hello: 5, }) | |||
}, | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter, forceNumberValues: true, })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -225,8 +225,8 @@ describe('range', () => { | |||
it('should get both values', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter, forceNumberValues: true, })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -242,13 +242,13 @@ describe('range', () => { | |||
it('should set both values', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { | |||
hello: [4, 2], | |||
}) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -29,8 +29,8 @@ describe('select', () => { | |||
it('should have multiple form values on a single field', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -44,11 +44,11 @@ describe('select', () => { | |||
it('should set values correctly', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { hello: ['Foo', 'Baz'] }); | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -94,8 +94,8 @@ describe('select', () => { | |||
it('should have multiple form values on a single field', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -109,11 +109,11 @@ describe('select', () => { | |||
it('should set multiple form values across all selects', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { hello: ['Foo', 'Baz', 'Chocolate', 'Vanilla'] }) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -127,11 +127,11 @@ describe('select', () => { | |||
it('should set multiple form values on each corresponding select element', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { hello: [['Foo', 'Baz', 'Chocolate'], ['Vanilla']] }) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -170,8 +170,8 @@ describe('select', () => { | |||
it('should have single form value on a single field', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -220,8 +220,8 @@ describe('select', () => { | |||
it('should have multiple form values on a single field', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -235,11 +235,11 @@ describe('select', () => { | |||
it('should set multiple form values across all selects', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { hello: ['Foo', 'Chocolate'] }) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -253,11 +253,11 @@ describe('select', () => { | |||
it('should set multiple form values on each corresponding select element', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { hello: ['Foo', 'Ube'] }) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -25,8 +25,8 @@ describe('submitter', () => { | |||
it('should have double form values', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[name="action"][value="Foo"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[name="action"][value="Foo"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -65,8 +65,8 @@ describe('submitter', () => { | |||
it('should have double form values', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[name="action"][value="Bar"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[name="action"][value="Bar"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -103,8 +103,8 @@ describe('submitter', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -24,8 +24,8 @@ describe('text', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -65,8 +65,8 @@ describe('text', () => { | |||
it('should have blank form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -101,8 +101,8 @@ describe('text', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -142,8 +142,8 @@ describe('text', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -180,11 +180,11 @@ describe('text', () => { | |||
it('should have form values set', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
preAction: (form: HTMLFormElement) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { hello: 'Hi', }) | |||
}, | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -225,8 +225,8 @@ describe('text', () => { | |||
it('should get both values', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -242,13 +242,13 @@ describe('text', () => { | |||
it('should set both values', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { | |||
hello: ['new value 1', 'another value 2'], | |||
}) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -24,8 +24,8 @@ describe('textarea', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -65,8 +65,8 @@ describe('textarea', () => { | |||
it('should have blank form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -101,8 +101,8 @@ describe('textarea', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -142,8 +142,8 @@ describe('textarea', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -180,11 +180,11 @@ describe('textarea', () => { | |||
it('should have form values set', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
preAction: (form: HTMLFormElement) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { hello: 'Hi', }) | |||
}, | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -221,12 +221,12 @@ describe('textarea', () => { | |||
it('should read LF line breaks', () => { | |||
utils.test({ | |||
action: (cy: any) => { | |||
actionBeforeSubmit: (cy: any) => { | |||
cy.get('[name="hello"]') | |||
.type('Hi\nHello', { parseSpecialCharSequences: false }) | |||
return cy.get('[type="submit"]') | |||
}, | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter, lineEndings: LineEnding.LF })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -242,12 +242,12 @@ describe('textarea', () => { | |||
it('should read CR line breaks', () => { | |||
utils.test({ | |||
action: (cy: any) => { | |||
actionBeforeSubmit: (cy: any) => { | |||
cy.get('[name="hello"]') | |||
.type('Hi\rHello', { parseSpecialCharSequences: false }) | |||
return cy.get('[type="submit"]') | |||
}, | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter, lineEndings: LineEnding.CR })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -263,12 +263,12 @@ describe('textarea', () => { | |||
it('should read CRLF line breaks', () => { | |||
utils.test({ | |||
action: (cy: any) => { | |||
actionBeforeSubmit: (cy: any) => { | |||
cy.get('[name="hello"]') | |||
.type('Hi\r\nHello', { parseSpecialCharSequences: false }) | |||
return cy.get('[type="submit"]') | |||
}, | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter, lineEndings: LineEnding.CRLF })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -309,8 +309,8 @@ describe('textarea', () => { | |||
it('should get both values', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -326,13 +326,13 @@ describe('textarea', () => { | |||
it('should set both values', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { | |||
hello: ['new value 1', 'another value 2'], | |||
}) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -24,8 +24,8 @@ describe('time', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -65,8 +65,8 @@ describe('time', () => { | |||
it('should have blank form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -101,8 +101,8 @@ describe('time', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -142,8 +142,8 @@ describe('time', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -180,11 +180,11 @@ describe('time', () => { | |||
it('should have form values set', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
preAction: (form: HTMLFormElement) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { hello: '13:37', }) | |||
}, | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -225,8 +225,8 @@ describe('time', () => { | |||
it('should get both values', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -242,13 +242,13 @@ describe('time', () => { | |||
it('should set both values', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { | |||
hello: ['04:20', '05:30'], | |||
}) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -24,8 +24,8 @@ describe('week', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -65,8 +65,8 @@ describe('week', () => { | |||
it('should have blank form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -101,8 +101,8 @@ describe('week', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -142,8 +142,8 @@ describe('week', () => { | |||
it('should have single form value', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -180,11 +180,11 @@ describe('week', () => { | |||
it('should have form values set', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
preAction: (form: HTMLFormElement) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { hello: '2003-W25', }) | |||
}, | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -225,8 +225,8 @@ describe('week', () => { | |||
it('should get both values', () => { | |||
utils.test({ | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -242,13 +242,13 @@ describe('week', () => { | |||
it('should set both values', () => { | |||
utils.test({ | |||
preAction: (form: HTMLFormElement) => { | |||
onLoaded: (form: HTMLFormElement) => { | |||
setFormValues(form, { | |||
hello: ['2003-W40', '2003-W50'], | |||
}) | |||
}, | |||
action: (cy: any) => cy.get('[type="submit"]'), | |||
test: (form: HTMLFormElement, submitter: any, search: any) => { | |||
actionBeforeSubmit: (cy: any) => cy.get('[type="submit"]'), | |||
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => { | |||
const before = utils.makeSearchParams(getFormValues(form, { submitter })) | |||
.toString(); | |||
const after = utils.makeSearchParams(search) | |||
@@ -13,7 +13,7 @@ type TestFn = (form: HTMLFormElement, submitter: HTMLSubmitterElement, after: Ex | |||
export const setup = (template: string) => { | |||
if (typeof cy !== 'undefined') { | |||
return () => { | |||
cy.intercept({ url: '/' }, { body: template }); | |||
cy.intercept({ url: '/' }, { body: template }).as('loaded'); | |||
cy.intercept({ url: '/?*' }, { body: template }).as('submitted'); | |||
} | |||
} | |||
@@ -26,18 +26,18 @@ export const setup = (template: string) => { | |||
} | |||
type TestOptions = { | |||
action: RetrieveSubmitterFn, | |||
test: TestFn, | |||
actionBeforeSubmit: RetrieveSubmitterFn, | |||
onSubmitted: TestFn, | |||
expectedStaticValue?: ExpectedSearchValue, | |||
preAction?: Function, | |||
onLoaded?: Function, | |||
} | |||
export const test = (options: TestOptions) => { | |||
const { | |||
action: retrieveSubmitterFn, | |||
test: testFn, | |||
actionBeforeSubmit: retrieveSubmitterFn, | |||
onSubmitted: testFn, | |||
expectedStaticValue, | |||
preAction, | |||
onLoaded, | |||
} = options; | |||
let form: HTMLFormElement | |||
let submitter: HTMLButtonElement | HTMLInputElement | |||
@@ -49,8 +49,8 @@ export const test = (options: TestOptions) => { | |||
.then((formResult: any) => { | |||
[form] = Array.from(formResult); | |||
if (typeof preAction === 'function') { | |||
preAction(form); | |||
if (typeof onLoaded === 'function') { | |||
onLoaded(form); | |||
} | |||
}) | |||
@@ -65,13 +65,17 @@ export const test = (options: TestOptions) => { | |||
.wait('@submitted') | |||
.location('search') | |||
.then((search: any) => { | |||
testFn(form, submitter, search) | |||
setTimeout(() => { | |||
testFn(form, submitter, search) | |||
}, 0) | |||
}) | |||
} else { | |||
cy | |||
.location('search') | |||
.then((search: any) => { | |||
testFn(form, submitter, search) | |||
setTimeout(() => { | |||
testFn(form, submitter, search) | |||
}, 0); | |||
}) | |||
} | |||
} else { | |||
@@ -80,8 +84,8 @@ export const test = (options: TestOptions) => { | |||
[submitter] = Array.from(submitterQueryEl as any[]); | |||
[form] = Array.from(window.document.getElementsByTagName('form')) | |||
if (typeof preAction === 'function') { | |||
preAction(form); | |||
if (typeof onLoaded === 'function') { | |||
onLoaded(form); | |||
} | |||
testFn(form, submitter, expectedStaticValue) | |||
@@ -216,8 +216,19 @@ const setInputRadioFieldValue = ( | |||
value: unknown, | |||
) => { | |||
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 = valueWhenChecked === value; | |||
inputEl.checked = ( | |||
Array.isArray(value) ? value.includes('on') : value === 'on' | |||
); | |||
}; | |||
/** | |||