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.

select.test.ts 1.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. (cy: any) => cy.get('[type="submit"]'),
  31. (form: HTMLFormElement, submitter: any, search: any) => {
  32. const before = utils.makeSearchParams(getFormValues(form, {submitter})).toString();
  33. const after = utils.makeSearchParams(search).toString();
  34. expect(before).toEqual(after);
  35. },
  36. 'hello=Bar&hello=Quux'
  37. );
  38. });
  39. })
  40. describe('single', () => {
  41. beforeEach(utils.setup(`
  42. <!DOCTYPE html>
  43. <html lang="en-PH">
  44. <head>
  45. <meta charset="UTF-8">
  46. <title>Select/Single</title>
  47. </head>
  48. <body>
  49. <form>
  50. <label>
  51. <span>Hello</span>
  52. <select name="hello">
  53. <option>Foo</option>
  54. <option>Bar</option>
  55. <option selected>Baz</option>
  56. </select>
  57. </label>
  58. <button type="submit">Submit</button>
  59. </form>
  60. </body>
  61. </html>
  62. `))
  63. it('should have single form value on a single field', () => {
  64. utils.test(
  65. (cy: any) => cy.get('[type="submit"]'),
  66. (form: HTMLFormElement, submitter: any, search: any) => {
  67. const before = utils.makeSearchParams(getFormValues(form, {submitter})).toString();
  68. const after = utils.makeSearchParams(search).toString();
  69. expect(before).toEqual(after);
  70. },
  71. {
  72. hello: 'Baz',
  73. }
  74. );
  75. });
  76. })
  77. })