Extract and set form values through the DOM—no frameworks required! https://github.com/TheoryOfNekomata/formxtra
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

88 rivejä
2.1 KiB

  1. import { getFormValues } from '../../src'
  2. import * as utils from '../utils'
  3. describe('select', () => {
  4. describe('multiple', () => {
  5. beforeEach(utils.setup(`
  6. <!DOCTYPE html>
  7. <html lang="en-PH">
  8. <head>
  9. <meta charset="UTF-8">
  10. <title>Select/Multiple</title>
  11. </head>
  12. <body>
  13. <form>
  14. <label>
  15. <span>Hello</span>
  16. <select name="hello" multiple>
  17. <option>Foo</option>
  18. <option selected>Bar</option>
  19. <option>Baz</option>
  20. <option selected>Quux</option>
  21. </select>
  22. </label>
  23. <button type="submit">Submit</button>
  24. </form>
  25. </body>
  26. </html>
  27. `))
  28. it('should have multiple form values on a single field', () => {
  29. utils.test({
  30. action: (cy: any) => cy.get('[type="submit"]'),
  31. test: (form: HTMLFormElement, submitter: any, search: any) => {
  32. const before = utils.makeSearchParams(getFormValues(form, { submitter }))
  33. .toString();
  34. const after = utils.makeSearchParams(search)
  35. .toString();
  36. expect(before)
  37. .toEqual(after);
  38. },
  39. expectedStaticValue: 'hello=Bar&hello=Quux'
  40. });
  41. });
  42. })
  43. describe('single', () => {
  44. beforeEach(utils.setup(`
  45. <!DOCTYPE html>
  46. <html lang="en-PH">
  47. <head>
  48. <meta charset="UTF-8">
  49. <title>Select/Single</title>
  50. </head>
  51. <body>
  52. <form>
  53. <label>
  54. <span>Hello</span>
  55. <select name="hello">
  56. <option>Foo</option>
  57. <option>Bar</option>
  58. <option selected>Baz</option>
  59. </select>
  60. </label>
  61. <button type="submit">Submit</button>
  62. </form>
  63. </body>
  64. </html>
  65. `))
  66. it('should have single form value on a single field', () => {
  67. utils.test({
  68. action: (cy: any) => cy.get('[type="submit"]'),
  69. test: (form: HTMLFormElement, submitter: any, search: any) => {
  70. const before = utils.makeSearchParams(getFormValues(form, { submitter }))
  71. .toString();
  72. const after = utils.makeSearchParams(search)
  73. .toString();
  74. expect(before)
  75. .toEqual(after);
  76. },
  77. expectedStaticValue: {
  78. hello: 'Baz',
  79. }
  80. });
  81. });
  82. })
  83. })