|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- import { getFormValues, setFormValues } from '../../src';
- import * as utils from '../utils'
-
- describe('week', () => {
- describe('basic', () => {
- beforeEach(utils.setup(`
- <!DOCTYPE html>
- <html lang="en-PH">
- <head>
- <meta charset="UTF-8">
- <title>Week/Basic</title>
- </head>
- <body>
- <form>
- <label>
- <span>Hello</span>
- <input type="week" name="hello" value="2003-W25" />
- </label>
- <button type="submit">Submit</button>
- </form>
- </body>
- </html>
- `))
-
- it('should have single form value', () => {
- utils.test({
- querySubmitter: (cy: any) => cy.get('[type="submit"]'),
- onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
- const before = utils.makeSearchParams(getFormValues(form, { submitter }))
- .toString();
- const after = utils.makeSearchParams(search)
- .toString();
- expect(before)
- .toEqual(after);
- },
- expectedStaticValue: {
- hello: '2003-W25',
- },
- });
- });
- })
-
- describe('disabled', () => {
- beforeEach(utils.setup(`
- <!DOCTYPE html>
- <html lang="en-PH">
- <head>
- <meta charset="UTF-8">
- <title>Week/Disabled</title>
- </head>
- <body>
- <form>
- <label>
- <span>Hello</span>
- <input
- type="week" name="hello" value="2003-W25"
- disabled
- />
- </label>
- <button type="submit">Submit</button>
- </form>
- </body>
- </html>
- `))
-
- it('should have blank form value', () => {
- utils.test({
- querySubmitter: (cy: any) => cy.get('[type="submit"]'),
- onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
- const before = utils.makeSearchParams(getFormValues(form, { submitter }))
- .toString();
- const after = utils.makeSearchParams(search)
- .toString();
- expect(before)
- .toEqual(after);
- },
- expectedStaticValue: {},
- });
- });
- })
-
- describe('outside', () => {
- beforeEach(utils.setup(`
- <!DOCTYPE html>
- <html lang="en-PH">
- <head>
- <meta charset="UTF-8">
- <title>Week/Outside</title>
- </head>
- <body>
- <form id="form">
- <button type="submit">Submit</button>
- </form>
- <label>
- <span>Hello</span>
- <input type="week" name="hello" value="2003-W25" form="form" />
- </label>
- </body>
- </html>
- `))
-
- it('should have single form value', () => {
- utils.test({
- querySubmitter: (cy: any) => cy.get('[type="submit"]'),
- onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
- const before = utils.makeSearchParams(getFormValues(form, { submitter }))
- .toString();
- const after = utils.makeSearchParams(search)
- .toString();
- expect(before)
- .toEqual(after);
- },
- expectedStaticValue: {
- hello: '2003-W25',
- },
- });
- });
- });
-
- describe('readonly', () => {
- beforeEach(utils.setup(`
- <!DOCTYPE html>
- <html lang="en-PH">
- <head>
- <meta charset="UTF-8">
- <title>Text/Readonly</title>
- </head>
- <body>
- <form>
- <label>
- <span>Hello</span>
- <input
- type="text" name="hello" value="2003-W25"
- readonly
- />
- </label>
- <button type="submit">Submit</button>
- </form>
- </body>
- </html>
- `))
-
- it('should have single form value', () => {
- utils.test({
- querySubmitter: (cy: any) => cy.get('[type="submit"]'),
- onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
- const before = utils.makeSearchParams(getFormValues(form, { submitter }))
- .toString();
- const after = utils.makeSearchParams(search)
- .toString();
- expect(before)
- .toEqual(after);
- },
- expectedStaticValue: {
- hello: '2003-W25',
- },
- });
- });
- });
-
- describe('programmatic value setting', () => {
- beforeEach(utils.setup(`
- <!DOCTYPE html>
- <html lang="en-PH">
- <head>
- <meta charset="UTF-8">
- <title>Week/Programmatic Value Setting</title>
- </head>
- <body>
- <form>
- <label>
- <span>Hello</span>
- <input type="week" name="hello" />
- </label>
- <button type="submit">Submit</button>
- </form>
- </body>
- </html>
- `));
-
- it('should have form values set', () => {
- utils.test({
- querySubmitter: (cy: any) => cy.get('[type="submit"]'),
- onLoaded: (form: HTMLFormElement) => {
- setFormValues(form, { hello: '2003-W25', })
- },
- onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
- const before = utils.makeSearchParams(getFormValues(form, { submitter }))
- .toString();
- const after = utils.makeSearchParams(search)
- .toString();
- expect(before)
- .toEqual(after);
- },
- expectedStaticValue: {
- hello: '2003-W25',
- },
- });
- });
- });
-
- describe('duplicate', () => {
- beforeEach(utils.setup(`
- <!DOCTYPE html>
- <html lang="en-PH">
- <head>
- <meta charset="UTF-8">
- <title>Week/Duplicate</title>
- </head>
- <body>
- <form>
- <label>
- <span>Hello 1</span>
- <input id="hello1" type="week" name="hello" value="2003-W25"/>
- </label>
- <label>
- <span>Hello 2</span>
- <input id="hello2" type="week" name="hello" value="2003-W30"/>
- </label>
- <button type="submit">Submit</button>
- </form>
- </body>
- </html>
- `));
-
- it('should get both values', () => {
- utils.test({
- querySubmitter: (cy: any) => cy.get('[type="submit"]'),
- onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
- const before = utils.makeSearchParams(getFormValues(form, { submitter }))
- .toString();
- const after = utils.makeSearchParams(search)
- .toString();
- expect(before)
- .toEqual(after);
- },
- expectedStaticValue: {
- hello: ['2003-W25', '2003-W30'],
- },
- });
- });
-
- it('should set both values', () => {
- utils.test({
- onLoaded: (form: HTMLFormElement) => {
- setFormValues(form, {
- hello: ['2003-W40', '2003-W50'],
- })
- },
- querySubmitter: (cy: any) => cy.get('[type="submit"]'),
- onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
- const before = utils.makeSearchParams(getFormValues(form, { submitter }))
- .toString();
- const after = utils.makeSearchParams(search)
- .toString();
- expect(before)
- .toEqual(after);
- },
- expectedStaticValue: {
- hello: ['2003-W40', '2003-W50'],
- },
- });
- });
- });
- })
|