Extract and set form values through the DOM—no frameworks required! https://github.com/TheoryOfNekomata/formxtra
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

82 satır
1.9 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. (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. })