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

115 рядки
2.8 KiB

  1. /// <reference types="cypress" />
  2. import getFormValues from '../../src'
  3. import * as utils from '../utils';
  4. describe('single input template', () => {
  5. beforeEach(utils.setup('single-input'))
  6. it('should have single form value', () => {
  7. utils.test(
  8. (cy: any) => {
  9. cy.get('[type="submit"]').click()
  10. },
  11. (form: HTMLFormElement, search: any) => {
  12. const before = utils.makeSearchParams(getFormValues(form)).toString();
  13. const after = utils.makeSearchParams(search).toString();
  14. expect(before).toEqual(after);
  15. },
  16. {
  17. hello: 'Hi',
  18. }
  19. );
  20. });
  21. })
  22. describe('single readonly template', () => {
  23. beforeEach(utils.setup('single-readonly-input'))
  24. it('should have single form value', () => {
  25. utils.test(
  26. (cy: any) => {
  27. cy.get('[type="submit"]').click()
  28. },
  29. (form: HTMLFormElement, search: any) => {
  30. const before = utils.makeSearchParams(getFormValues(form)).toString();
  31. const after = utils.makeSearchParams(search).toString();
  32. expect(before).toEqual(after);
  33. },
  34. {
  35. hello: 'Hi',
  36. }
  37. );
  38. });
  39. })
  40. describe('single disabled template', () => {
  41. beforeEach(utils.setup('single-disabled-input'))
  42. it('should have blank form value', () => {
  43. utils.test(
  44. (cy: any) => {
  45. cy.get('[type="submit"]').click()
  46. },
  47. (form: HTMLFormElement, search: any) => {
  48. const before = utils.makeSearchParams(getFormValues(form)).toString();
  49. const after = utils.makeSearchParams(search).toString();
  50. expect(before).toEqual(after);
  51. },
  52. {}
  53. );
  54. });
  55. })
  56. describe('single input with double button submitters template', () => {
  57. beforeEach(utils.setup('single-input-with-double-button-submitters'))
  58. it('should have double form values', () => {
  59. let submitter: HTMLButtonElement
  60. utils.test(
  61. (cy: any) => {
  62. cy.get('[name="action"][value="Foo"]')
  63. .then((result: any) => {
  64. [submitter] = Array.from(result)
  65. })
  66. .click()
  67. },
  68. (form: HTMLFormElement, search: any) => {
  69. const before = utils.makeSearchParams(getFormValues(form, submitter)).toString();
  70. const after = utils.makeSearchParams(search).toString();
  71. expect(before).toEqual(after);
  72. },
  73. {
  74. hello: 'Hi',
  75. action: 'Foo',
  76. }
  77. );
  78. });
  79. })
  80. describe('single input with double input submitters template', () => {
  81. beforeEach(utils.setup('single-input-with-double-input-submitters'))
  82. it('should have double form values', () => {
  83. let submitter: HTMLInputElement
  84. utils.test(
  85. (cy: any) => {
  86. cy.get('[name="action"][value="Bar"]')
  87. .then((result: any) => {
  88. [submitter] = Array.from(result)
  89. })
  90. .click()
  91. },
  92. (form: HTMLFormElement, search: any) => {
  93. const before = utils.makeSearchParams(getFormValues(form, submitter)).toString();
  94. const after = utils.makeSearchParams(search).toString();
  95. expect(before).toEqual(after);
  96. },
  97. {
  98. hello: 'Hi',
  99. action: 'Bar',
  100. }
  101. );
  102. });
  103. })