Extract and set form values through the DOM—no frameworks required! https://github.com/TheoryOfNekomata/formxtra
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

105 satır
1.9 KiB

  1. /// <reference types="cypress" />
  2. import getFormValues from '../../src'
  3. import {makeSearchParams} from '../utils/search';
  4. describe('default template', () => {
  5. beforeEach(() => {
  6. cy.intercept({ url: '/' }, { fixture: 'templates/everything.html' });
  7. cy.intercept({ url: '/?*' }, { fixture: 'templates/everything.html' }).as('submitted');
  8. })
  9. it('should have a single form value', () => {
  10. let form;
  11. let submitter;
  12. cy
  13. .visit('/')
  14. cy
  15. .get('[name="first_name"]')
  16. .type('John')
  17. cy
  18. .get('[name="middle_name"]')
  19. .type('Marcelo')
  20. cy
  21. .get('[name="last_name"]')
  22. .type('Dela Cruz')
  23. cy
  24. .get('[name="gender"][value="m"]')
  25. .check()
  26. cy
  27. .get('[name="civil_status"]')
  28. .select('Married')
  29. cy
  30. .get('[name="new_registration"]')
  31. .check()
  32. cy
  33. .get('[name="nationality"][value="filipino"]')
  34. .check()
  35. cy
  36. .get('[name="dependent"][value="Jun"]')
  37. .check()
  38. cy
  39. .get('button.dependents')
  40. .click()
  41. cy
  42. .get('.additional-dependent [name="dependent"][type="text"]')
  43. .last()
  44. .type('Juana')
  45. cy
  46. .get('button.dependents')
  47. .click()
  48. cy
  49. .get('.additional-dependent [name="dependent"][type="text"]')
  50. .last()
  51. .type('Jane')
  52. cy
  53. .get('button.dependents')
  54. .click()
  55. cy
  56. .get('.additional-dependent [name="dependent"][type="text"]')
  57. .last()
  58. .type('Josh')
  59. cy
  60. .get('[name="notes"]')
  61. .type('Test content\n\nNew line\n\nAnother line')
  62. cy
  63. .get('form')
  64. .then((theForm) => {
  65. [form] = Array.from(theForm)
  66. })
  67. cy
  68. .get('[name="submit"][value="Hi"]')
  69. .then((submitterEl) => {
  70. [submitter] = Array.from(submitterEl) as HTMLButtonElement[];
  71. submitterEl.trigger('click');
  72. })
  73. cy
  74. .wait('@submitted')
  75. .location('search')
  76. .then(search => {
  77. const before = makeSearchParams(getFormValues(form, submitter));
  78. const after = new URLSearchParams(search)
  79. expect(before.toString()).to.equal(after.toString());
  80. })
  81. })
  82. });