import { getFormValues, setFormValues } from '../../src';
import * as utils from '../utils'
describe('misc', () => {
describe('blank', () => {
beforeEach(utils.setup(`
Misc/Blank
`))
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('everything', () => {
beforeEach(utils.setup(`
Misc/Everything
`))
it('should have correct form values', () => {
utils.test({
onBeforeSubmit: (cy) => {
cy.get('[name="first_name"]')
.type('John')
cy.get('[name="middle_name"]')
.type('Marcelo')
cy.get('[name="last_name"]')
.type('Dela Cruz')
cy.get('[name="gender"][value="m"]')
.check()
cy.get('[name="birthday"]')
.type('1989-06-04')
cy.get('[name="civil_status"]')
.select('Married')
cy.get('[name="new_registration"]')
.check()
cy.get('[name="last_appointment_datetime"]')
.type('2001-09-11T06:09')
cy.get('[name="new_appointment_week"]')
.type('2001-W51')
cy.get('[name="start_month"]')
.type('2002-03')
cy.get('[name="nationality"][value="filipino"]')
.check()
cy.get('[name="gross"]')
.type('131072')
cy.get('[name="dependent"][value="Jun"]')
.check()
cy.get('button.dependents')
.click()
cy.get('.additional-dependent [name="dependent"][type="text"]')
.last()
.type('Juana')
cy.get('button.dependents')
.click()
cy.get('.additional-dependent [name="dependent"][type="text"]')
.last()
.type('Jane')
cy.get('button.dependents')
.click()
cy.get('.additional-dependent [name="dependent"][type="text"]')
.last()
.type('Josh')
cy.get('[name="qos"]')
.invoke('val', 9.5)
.trigger('change')
cy.get('[name="notes"]')
.type('Test content\n\nNew line\n\nAnother line')
},
querySubmitter: (cy) => cy.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)
.toString();
expect(before)
.toEqual(after);
},
expectedStaticValue: 'first_name=John&middle_name=Marcelo&last_name=Dela+Cruz&gender=m&birthday=1989-06-04&civil_status=married&new_registration=on&last_appointment_datetime=2001-09-11T06%3A09&new_appointment_week=2001-W51&start_month=2002-03&nationality=filipino&gross=131072&dependent=Jun¬es=Test+content%0D%0A%0D%0ANew+line%0D%0A%0D%0AAnother+line&qos=9.5&submit=Hi',
});
});
it('should have filled form values', () => {
utils.test({
onBeforeSubmit: (cy: any) => cy.wait(3000),
querySubmitter: (cy) => cy.get('[name="submit"][value="Hi"]'),
onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
const before = utils.makeSearchParams(getFormValues(form, { submitter }))
.toString();
const after = utils.makeSearchParams(search)
.toString();
expect(before)
.toEqual(after);
},
onLoaded: (form: HTMLFormElement) => {
setFormValues(form, {
first_name: 'John',
middle_name: 'Marcelo',
last_name: 'Dela Cruz',
gender: 'm',
birthday: new Date('1989-06-04'),
civil_status: 'married',
new_registration: 'on',
last_appointment_datetime: new Date('2001-09-11T06:09:00'),
new_appointment_week: '2001-W51',
start_month: '2002-03',
nationality: 'filipino',
gross: 131072,
dependent: 'Jun',
notes: `Test content
New line
Another line`,
qos: 9.5,
});
},
expectedStaticValue: 'first_name=John&middle_name=Marcelo&last_name=Dela+Cruz&gender=m&birthday=1989-06-04&civil_status=married&new_registration=on&last_appointment_datetime=2001-09-11T06%3A09&new_appointment_week=2001-W51&start_month=2002-03&nationality=filipino&gross=131072&dependent=Jun¬es=Test+content%0D%0A%0D%0ANew+line%0D%0A%0D%0AAnother+line&qos=9.5&submit=Hi',
});
});
});
// TODO implement tests for multiple values
});