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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import { getFormValues, setFormValues } from '../../src';
  2. import * as utils from '../utils'
  3. describe('fieldset', () => {
  4. describe('basic', () => {
  5. beforeEach(utils.setup(`
  6. <!DOCTYPE html>
  7. <html lang="en-PH">
  8. <head>
  9. <meta charset="UTF-8">
  10. <title>Text/Basic</title>
  11. </head>
  12. <body>
  13. <form>
  14. <fieldset>
  15. <legend>Fieldset</legend>
  16. <label>
  17. <span>Hello</span>
  18. <input type="text" name="hello" value="Hi" />
  19. </label>
  20. </fieldset>
  21. <button type="submit">Submit</button>
  22. </form>
  23. </body>
  24. </html>
  25. `))
  26. it('should have single form value', () => {
  27. utils.test({
  28. querySubmitter: (cy: any) => cy.get('[type="submit"]'),
  29. onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
  30. const before = utils.makeSearchParams(getFormValues(form, { submitter }))
  31. .toString();
  32. const after = utils.makeSearchParams(search)
  33. .toString();
  34. expect(before)
  35. .toEqual(after);
  36. },
  37. expectedStaticValue: {
  38. hello: 'Hi',
  39. },
  40. });
  41. });
  42. });
  43. describe('disabled', () => {
  44. beforeEach(utils.setup(`
  45. <!DOCTYPE html>
  46. <html lang="en-PH">
  47. <head>
  48. <meta charset="UTF-8">
  49. <title>Text/Disabled</title>
  50. </head>
  51. <body>
  52. <form>
  53. <fieldset disabled>
  54. <legend>Fieldset</legend>
  55. <label>
  56. <span>Hello</span>
  57. <input type="text" name="hello" value="Hi"/>
  58. </label>
  59. </fieldset>
  60. <button type="submit">Submit</button>
  61. </form>
  62. </body>
  63. </html>
  64. `))
  65. it('should have blank form value', () => {
  66. utils.test({
  67. querySubmitter: (cy: any) => cy.get('[type="submit"]'),
  68. onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
  69. const before = utils.makeSearchParams(getFormValues(form, { submitter }))
  70. .toString();
  71. const after = utils.makeSearchParams(search)
  72. .toString();
  73. expect(before)
  74. .toEqual(after);
  75. },
  76. expectedStaticValue: {},
  77. });
  78. });
  79. })
  80. describe('outside', () => {
  81. beforeEach(utils.setup(`
  82. <!DOCTYPE html>
  83. <html lang="en-PH">
  84. <head>
  85. <meta charset="UTF-8">
  86. <title>Text/Outside</title>
  87. </head>
  88. <body>
  89. <form id="form">
  90. <button type="submit">Submit</button>
  91. </form>
  92. <fieldset form="form">
  93. <legend>Fieldset</legend>
  94. <label>
  95. <span>Hello</span>
  96. <input type="text" name="hello" value="Hi" form="form" />
  97. </label>
  98. </fieldset>
  99. </body>
  100. </html>
  101. `))
  102. it('should have single form value', () => {
  103. utils.test({
  104. querySubmitter: (cy: any) => cy.get('[type="submit"]'),
  105. onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
  106. const before = utils.makeSearchParams(getFormValues(form, { submitter }))
  107. .toString();
  108. const after = utils.makeSearchParams(search)
  109. .toString();
  110. expect(before)
  111. .toEqual(after);
  112. },
  113. expectedStaticValue: {
  114. hello: 'Hi',
  115. },
  116. });
  117. });
  118. });
  119. describe('outside disabled', () => {
  120. beforeEach(utils.setup(`
  121. <!DOCTYPE html>
  122. <html lang="en-PH">
  123. <head>
  124. <meta charset="UTF-8">
  125. <title>Text/Outside</title>
  126. </head>
  127. <body>
  128. <form id="form">
  129. <button type="submit">Submit</button>
  130. </form>
  131. <fieldset form="form" disabled>
  132. <legend>Fieldset</legend>
  133. <label>
  134. <span>Hello</span>
  135. <input type="text" name="hello" value="Hi" form="form" />
  136. </label>
  137. </fieldset>
  138. </body>
  139. </html>
  140. `))
  141. it('should have blank form value', () => {
  142. utils.test({
  143. querySubmitter: (cy: any) => cy.get('[type="submit"]'),
  144. onSubmitted: (form: HTMLFormElement, submitter: any, search: any) => {
  145. const before = utils.makeSearchParams(getFormValues(form, { submitter }))
  146. .toString();
  147. const after = utils.makeSearchParams(search)
  148. .toString();
  149. expect(before)
  150. .toEqual(after);
  151. },
  152. expectedStaticValue: {},
  153. });
  154. });
  155. });
  156. });