Extract and set form values through the DOM—no frameworks required! https://github.com/TheoryOfNekomata/formxtra
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

39 regels
1.7 KiB

  1. import getFormValues from '../../src'
  2. import * as utils from '../../test/utils';
  3. describe('everything template', () => {
  4. beforeEach(utils.setup('everything'))
  5. it('should have correct form values', () => {
  6. utils.test(
  7. (cy) => {
  8. cy.get('[name="first_name"]').type('John')
  9. cy.get('[name="middle_name"]').type('Marcelo')
  10. cy.get('[name="last_name"]').type('Dela Cruz')
  11. cy.get('[name="gender"][value="m"]').check()
  12. cy.get('[name="civil_status"]').select('Married')
  13. cy.get('[name="new_registration"]').check()
  14. cy.get('[name="nationality"][value="filipino"]').check()
  15. cy.get('[name="dependent"][value="Jun"]').check()
  16. // Note: JSDOM is static for now
  17. cy.get('button.dependents').click()
  18. cy.get('.additional-dependent [name="dependent"][type="text"]').last().type('Juana')
  19. cy.get('button.dependents').click()
  20. cy.get('.additional-dependent [name="dependent"][type="text"]').last().type('Jane')
  21. cy.get('button.dependents').click()
  22. cy.get('.additional-dependent [name="dependent"][type="text"]').last().type('Josh')
  23. cy.get('[name="notes"]').type('Test content\n\nNew line\n\nAnother line')
  24. return cy.get('[name="submit"][value="Hi"]')
  25. },
  26. (form: HTMLFormElement, submitter: any, search: any) => {
  27. const before = utils.makeSearchParams(getFormValues(form, {submitter})).toString();
  28. const after = utils.makeSearchParams(search).toString();
  29. expect(before).toEqual(after);
  30. },
  31. 'first_name=John&middle_name=Marcelo&last_name=Dela+Cruz&gender=m&civil_status=married&new_registration=on&nationality=filipino&dependent=Jun&notes=Test+content%0D%0A%0D%0ANew+line%0D%0A%0D%0AAnother+line&submit=Hi',
  32. );
  33. });
  34. })