Extract and set form values through the DOM—no frameworks required! https://github.com/TheoryOfNekomata/formxtra
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

single.test.ts 5.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import getFormValues from '../../src'
  2. import * as utils from '../../test/utils';
  3. describe('single input template', () => {
  4. beforeEach(utils.setup('single-input'))
  5. it('should have single form value', () => {
  6. utils.test(
  7. (cy: any) => cy.get('[type="submit"]'),
  8. (form: HTMLFormElement, submitter: any, search: any) => {
  9. const before = utils.makeSearchParams(getFormValues(form, {submitter})).toString();
  10. const after = utils.makeSearchParams(search).toString();
  11. expect(before).toEqual(after);
  12. },
  13. {
  14. hello: 'Hi',
  15. }
  16. );
  17. });
  18. })
  19. describe('single outside input template', () => {
  20. beforeEach(utils.setup('single-outside-input'))
  21. it('should have single form value', () => {
  22. utils.test(
  23. (cy: any) => cy.get('[type="submit"]'),
  24. (form: HTMLFormElement, submitter: any, search: any) => {
  25. const before = utils.makeSearchParams(getFormValues(form, {submitter})).toString();
  26. const after = utils.makeSearchParams(search).toString();
  27. expect(before).toEqual(after);
  28. },
  29. {
  30. hello: 'Hi',
  31. }
  32. );
  33. });
  34. })
  35. describe('single outside input and submitter template', () => {
  36. beforeEach(utils.setup('single-outside-input-and-submitter'))
  37. it('should have single form value', () => {
  38. utils.test(
  39. (cy: any) => cy.get('[type="submit"]'),
  40. (form: HTMLFormElement, submitter: any, search: any) => {
  41. const before = utils.makeSearchParams(getFormValues(form, {submitter})).toString();
  42. const after = utils.makeSearchParams(search).toString();
  43. expect(before).toEqual(after);
  44. },
  45. {
  46. hello: 'Hi',
  47. }
  48. );
  49. });
  50. })
  51. describe('single readonly template', () => {
  52. beforeEach(utils.setup('single-readonly-input'))
  53. it('should have single form value', () => {
  54. utils.test(
  55. (cy: any) => cy.get('[type="submit"]'),
  56. (form: HTMLFormElement, submitter: any, search: any) => {
  57. const before = utils.makeSearchParams(getFormValues(form, {submitter})).toString();
  58. const after = utils.makeSearchParams(search).toString();
  59. expect(before).toEqual(after);
  60. },
  61. {
  62. hello: 'Hi',
  63. }
  64. );
  65. });
  66. })
  67. describe('single disabled template', () => {
  68. beforeEach(utils.setup('single-disabled-input'))
  69. it('should have blank form value', () => {
  70. utils.test(
  71. (cy: any) => cy.get('[type="submit"]'),
  72. (form: HTMLFormElement, submitter: any, search: any) => {
  73. const before = utils.makeSearchParams(getFormValues(form, {submitter})).toString();
  74. const after = utils.makeSearchParams(search).toString();
  75. expect(before).toEqual(after);
  76. },
  77. {}
  78. );
  79. });
  80. })
  81. describe('single input with double button submitters template', () => {
  82. beforeEach(utils.setup('single-input-with-double-button-submitters'))
  83. it('should have double form values', () => {
  84. utils.test(
  85. (cy: any) => cy.get('[name="action"][value="Foo"]'),
  86. (form: HTMLFormElement, submitter: any, search: any) => {
  87. const before = utils.makeSearchParams(getFormValues(form, {submitter})).toString();
  88. const after = utils.makeSearchParams(search).toString();
  89. expect(before).toEqual(after);
  90. },
  91. {
  92. hello: 'Hi',
  93. action: 'Foo',
  94. }
  95. );
  96. });
  97. })
  98. describe('single input with double input submitters template', () => {
  99. beforeEach(utils.setup('single-input-with-double-input-submitters'))
  100. it('should have double form values', () => {
  101. utils.test(
  102. (cy: any) => cy.get('[name="action"][value="Bar"]'),
  103. (form: HTMLFormElement, submitter: any, search: any) => {
  104. const before = utils.makeSearchParams(getFormValues(form, {submitter})).toString();
  105. const after = utils.makeSearchParams(search).toString();
  106. expect(before).toEqual(after);
  107. },
  108. {
  109. hello: 'Hi',
  110. action: 'Bar',
  111. }
  112. );
  113. });
  114. })
  115. describe('single select template', () => {
  116. beforeEach(utils.setup('single-select'))
  117. it('should have single form value', () => {
  118. utils.test(
  119. (cy: any) => cy.get('[type="submit"]'),
  120. (form: HTMLFormElement, submitter: any, search: any) => {
  121. const before = utils.makeSearchParams(getFormValues(form, {submitter})).toString();
  122. const after = utils.makeSearchParams(search).toString();
  123. expect(before).toEqual(after);
  124. },
  125. {
  126. hello: 'Baz',
  127. }
  128. );
  129. });
  130. })
  131. describe('single multiple select template', () => {
  132. beforeEach(utils.setup('single-multiple-select'))
  133. it('should have single form value', () => {
  134. utils.test(
  135. (cy: any) => cy.get('[type="submit"]'),
  136. (form: HTMLFormElement, submitter: any, search: any) => {
  137. const before = utils.makeSearchParams(getFormValues(form, {submitter})).toString();
  138. const after = utils.makeSearchParams(search).toString();
  139. expect(before).toEqual(after);
  140. },
  141. {
  142. hello: 'Bar,Quux',
  143. }
  144. );
  145. });
  146. })
  147. describe('single file input template', () => {
  148. beforeEach(utils.setup('single-file-input'))
  149. it('should have no form values when no file is selected', () => {
  150. utils.test(
  151. (cy: any) => cy.get('[type="submit"]'),
  152. (form: HTMLFormElement, submitter: any, search: any) => {
  153. const before = utils.makeSearchParams(getFormValues(form, {submitter})).toString();
  154. const after = utils.makeSearchParams(search).toString();
  155. expect(before).toEqual(after);
  156. },
  157. {}
  158. );
  159. })
  160. it('should have single form value when a file is selected', () => {
  161. utils.test(
  162. (cy: any) => {
  163. cy
  164. .get('[name="hello"]')
  165. .attachFile('uploads/data.json')
  166. return cy.get('[type="submit"]')
  167. },
  168. (form: HTMLFormElement, submitter: any, search: any) => {
  169. const before = utils.makeSearchParams(getFormValues(form, {submitter})).toString();
  170. const after = utils.makeSearchParams(search).toString();
  171. expect(before).toEqual(after);
  172. },
  173. {
  174. hello: 'data.json',
  175. }
  176. );
  177. })
  178. })