Extract and set form values through the DOM—no frameworks required! https://github.com/TheoryOfNekomata/formxtra
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

163 рядки
4.0 KiB

  1. /// <reference types="cypress" />
  2. import getFormValues from '../../src'
  3. import {makeSearchParams} from '../utils/search';
  4. describe('single input template', () => {
  5. beforeEach(() => {
  6. cy.intercept({ url: '/' }, { fixture: 'templates/single-input.html' });
  7. cy.intercept({ url: '/?*' }, { fixture: 'templates/single-input.html' }).as('submitted');
  8. })
  9. it('should have a single form value', () => {
  10. let form
  11. cy
  12. .visit('/')
  13. .get('form')
  14. .then((formResult) => {
  15. [form] = Array.from(formResult);
  16. })
  17. .get('[type="submit"]')
  18. .click()
  19. .wait('@submitted')
  20. .location('search')
  21. .then(search => {
  22. const before = makeSearchParams(getFormValues(form)).toString();
  23. const after = new URLSearchParams(search).toString();
  24. expect(before).to.equal(after);
  25. })
  26. })
  27. });
  28. describe('single readonly template', () => {
  29. beforeEach(() => {
  30. cy.intercept({ url: '/' }, { fixture: 'templates/single-readonly-input.html' });
  31. cy.intercept({ url: '/?*' }, { fixture: 'templates/single-readonly-input.html' }).as('submitted');
  32. })
  33. it('should have a single form value', () => {
  34. let form
  35. cy
  36. .visit('/')
  37. .get('form')
  38. .then((formResult) => {
  39. [form] = Array.from(formResult);
  40. })
  41. .get('[type="submit"]')
  42. .click()
  43. .wait('@submitted')
  44. .location('search')
  45. .then(search => {
  46. const before = makeSearchParams(getFormValues(form)).toString();
  47. const after = new URLSearchParams(search).toString();
  48. expect(before).to.equal(after);
  49. })
  50. })
  51. });
  52. describe('single disabled template', () => {
  53. beforeEach(() => {
  54. cy.intercept({ url: '/' }, { fixture: 'templates/single-disabled-input.html' });
  55. cy.intercept({ url: '/?*' }, { fixture: 'templates/single-disabled-input.html' }).as('submitted');
  56. })
  57. it('should have a single form value', () => {
  58. let form
  59. cy
  60. .visit('/')
  61. .get('form')
  62. .then((formResult) => {
  63. [form] = Array.from(formResult);
  64. })
  65. .get('[type="submit"]')
  66. .click()
  67. .wait('@submitted')
  68. .location('search')
  69. .then(search => {
  70. const before = makeSearchParams(getFormValues(form)).toString();
  71. const after = new URLSearchParams(search).toString();
  72. expect(before).to.equal(after);
  73. })
  74. })
  75. });
  76. describe('single input with double button submitters template', () => {
  77. beforeEach(() => {
  78. cy
  79. .intercept(
  80. { url: '/' },
  81. { fixture: 'templates/single-input-with-double-button-submitters.html' }
  82. );
  83. cy
  84. .intercept(
  85. { url: '/?*' },
  86. { fixture: 'templates/single-input-with-double-button-submitters.html' }
  87. )
  88. .as('submitted');
  89. })
  90. it('should have a single form value', () => {
  91. let submitter;
  92. let form;
  93. cy
  94. .visit('/')
  95. .get('form')
  96. .then((formResult) => {
  97. [form] = Array.from(formResult);
  98. })
  99. .get('[name="action"][value="Bar"]')
  100. .then((submitterEl) => {
  101. [submitter] = Array.from(submitterEl)
  102. })
  103. .click()
  104. .wait('@submitted')
  105. .location('search')
  106. .then(search => {
  107. const before = makeSearchParams(getFormValues(form, submitter as HTMLInputElement)).toString();
  108. const after = new URLSearchParams(search).toString();
  109. expect(before).to.equal(after);
  110. })
  111. })
  112. });
  113. describe('single input with double input submitters template', () => {
  114. beforeEach(() => {
  115. cy
  116. .intercept(
  117. { url: '/' },
  118. { fixture: 'templates/single-input-with-double-input-submitters.html' }
  119. );
  120. cy
  121. .intercept(
  122. { url: '/?*' },
  123. { fixture: 'templates/single-input-with-double-input-submitters.html' }
  124. )
  125. .as('submitted');
  126. })
  127. it('should have a single form value', () => {
  128. let submitter;
  129. let form;
  130. cy
  131. .visit('/')
  132. .get('form')
  133. .then((formResult) => {
  134. [form] = Array.from(formResult);
  135. })
  136. .get('[name="action"][value="Foo"]')
  137. .then((submitterEl) => {
  138. [submitter] = Array.from(submitterEl)
  139. })
  140. .click()
  141. .wait('@submitted')
  142. .location('search')
  143. .then(search => {
  144. const before = makeSearchParams(getFormValues(form, submitter as HTMLInputElement)).toString();
  145. const after = new URLSearchParams(search).toString();
  146. expect(before).to.equal(after);
  147. })
  148. })
  149. });