Extract and set form values through the DOM—no frameworks required! https://github.com/TheoryOfNekomata/formxtra
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

149 linhas
3.3 KiB

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