form.spec.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. // form.spec.js created with Cypress
  2. //
  3. // Start writing your Cypress tests below!
  4. // If you're unfamiliar with how Cypress works,
  5. // check out the link below and learn how to write your first test:
  6. // https://on.cypress.io/writing-first-test
  7. /**
  8. * why use `.then`?
  9. * @see https://docs.cypress.io/guides/core-concepts/variables-and-aliases#Return-Values
  10. */
  11. const D2C = { name: 'Semi D2C', role: 'Engineer' };
  12. const C2D = { name: 'Semi C2D', role: 'Designer' };
  13. const DSM = { name: 'Semi DSM', role: 'Designer' };
  14. describe('Form', () => {
  15. // it('formApi-setValue with array field path, 3 -> 2, remove middle line field', () => {
  16. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--use-form-api-set-value-update-array');
  17. // cy.get(':nth-child(3) > .semi-button').click();
  18. // // line 1
  19. // cy.get('[x-field-id="effects[0].name"] > .semi-form-field-main > .semi-input-wrapper > input').should('have.value', '1-name');
  20. // cy.get('[x-field-id="effects[0].type"] > .semi-form-field-main > .semi-input-wrapper > input').should('have.value', '1-type');
  21. // // line 2
  22. // cy.get('[x-field-id="effects[1].name"] > .semi-form-field-main > .semi-input-wrapper > input').should('have.value', '3-name');
  23. // cy.get('[x-field-id="effects[1].type"] > .semi-form-field-main > .semi-input-wrapper > input').should('have.value', '3-type');
  24. // // cy.get('body').find('.semi-popover .semi-datepicker').should('have.length', 0);
  25. // });
  26. // ❌ 发现了bug
  27. // modify
  28. // it('Basic usage - modify、add blank row、add withInitValue row', () => {
  29. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--basic-array-field-demo');
  30. // cy.get('#data-0-name').type('-new');
  31. // cy.get('#data-0-role').type('-new');
  32. // cy.get('#data-0-name').should('have.value', 'Semi D2C-new');
  33. // cy.get('#data-0-role').should('have.value', 'Engineer-new');
  34. // // add blank row
  35. // cy.get('#add').click();
  36. // cy.get('#data-2-name').should('have.value', '');
  37. // cy.get('#data-2-role').should('have.value', '');
  38. // // add withInitValue row
  39. // cy.get('#addWithInit').click();
  40. // cy.get('#data-3-name').should('have.value', 'Semi New-3');
  41. // cy.get('#data-3-role').should('have.value', 'Designer');
  42. // });
  43. // it('Basic usage - add withInitValue row、add blank row', () => {
  44. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--basic-array-field-demo');
  45. // // add withInitValue row
  46. // cy.get('#addWithInit').click();
  47. // cy.get('#data-2-name').should('have.value', 'Semi New-3');
  48. // cy.get('#data-2-role').should('have.value', 'Designer');
  49. // // add blank row
  50. // cy.get('#add').click();
  51. // cy.get('#data-3-name').should('have.value', '');
  52. // cy.get('#data-3-role').should('have.value', '');
  53. // });
  54. // // // remove row
  55. // it('Remove row - 3 -> 2, remove middle', () => {
  56. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--remove-demo');
  57. // cy.get('#data-1 button').click();
  58. // cy.get('#data-0-name').should('have.value', D2C.name);
  59. // cy.get('#data-0-role').should('have.value', D2C.role);
  60. // cy.get('#data-1-name').should('have.value', DSM.name);
  61. // cy.get('#data-1-role').should('have.value', DSM.role);
  62. // });
  63. // it('Remove row - 3 -> 2, remove middle, 2 -> 1, remove head', () => {
  64. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--remove-demo');
  65. // cy.get('#data-1 button').click();
  66. // cy.get('#data-0-name').should('have.value', D2C.name);
  67. // cy.get('#data-0-role').should('have.value', D2C.role);
  68. // cy.get('#data-1-name').should('have.value', DSM.name);
  69. // cy.get('#data-1-role').should('have.value', DSM.role);
  70. // cy.get('#data-0 button').click();
  71. // cy.get('#data-0-name').should('have.value', DSM.name);
  72. // cy.get('#data-0-role').should('have.value', DSM.role);
  73. // cy.get('#data-1').should('not.exist');
  74. // });
  75. // it('Remove row - 3 -> 2, remove head', () => {
  76. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--remove-demo');
  77. // cy.get('#data-2').should('exist');
  78. // cy.get('#data-0 button').click();
  79. // cy.get('#data-2').should('not.exist');
  80. // cy.get('#data-0-name').should('have.value', C2D.name);
  81. // cy.get('#data-0-role').should('have.value', C2D.role);
  82. // cy.get('#data-1-name').should('have.value', DSM.name);
  83. // cy.get('#data-1-role').should('have.value', DSM.role);
  84. // cy.get('#data-0 button').click();
  85. // cy.get('#data-0-name').should('have.value', DSM.name);
  86. // cy.get('#data-0-role').should('have.value', DSM.role);
  87. // });
  88. // it('Remove row - 3 -> 2, remove last', () => {
  89. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--remove-demo');
  90. // cy.get('#data-2').should('exist');
  91. // cy.get('#data-2 button').click();
  92. // cy.get('#data-2').should('not.exist');
  93. // cy.get('#data-0-name').should('have.value', D2C.name);
  94. // cy.get('#data-0-role').should('have.value', D2C.role);
  95. // cy.get('#data-1-name').should('have.value', C2D.name);
  96. // cy.get('#data-1-role').should('have.value', C2D.role);
  97. // });
  98. // // it('Basic usage - add、remove、reset', () => { });
  99. // // reset
  100. // it('Reset Usage: modify => reset ', () => {
  101. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--reset-demo');
  102. // cy.get('#data-0-name').type('-new');
  103. // cy.get('#data-0-role').type('-new');
  104. // cy.get('#data-0-name').should('have.value', `${D2C.name}-new`);
  105. // cy.get('#data-0-role').should('have.value', `${D2C.role}-new`);
  106. // cy.get('button[type=reset]').click();
  107. // cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  108. // cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  109. // });
  110. // it('Reset Usage: length 2 -> 1 => reset ', () => {
  111. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--reset-demo');
  112. // cy.get('#data-0 button').click();
  113. // cy.get('#data-1').should('not.exist');
  114. // cy.get('button[type=reset]').click();
  115. // // cy.get('#data-1').should('exist');
  116. // cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  117. // cy.get('#data-0-role').should('have.value', `${D2C.role}`);
  118. // cy.get('#data-1-name').should('have.value', `${C2D.name}`);
  119. // cy.get('#data-1-role').should('have.value', `${C2D.role}`);
  120. // });
  121. // it('Reset Usage: length 2 -> 0 -> 3 => reset ', () => {
  122. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--reset-demo');
  123. // cy.get('#data-1 button').click();
  124. // cy.get('#data-0 button').click();
  125. // cy.get('#data-0').should('not.exist');
  126. // cy.get('#addWithInit').click();
  127. // cy.get('#addWithInit').click();
  128. // cy.get('#addWithInit').click();
  129. // cy.get('#data-2').should('exist');
  130. // cy.get('button[type=reset]').click();
  131. // cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  132. // cy.get('#data-0-role').should('have.value', `${D2C.role}`);
  133. // cy.get('#data-1-name').should('have.value', `${C2D.name}`);
  134. // cy.get('#data-1-role').should('have.value', `${C2D.role}`);
  135. // cy.get('#data-2').should('not.exist');
  136. // });
  137. // it('Reset Usage: length 2 -> 0 -> 2 => reset ', () => {
  138. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--reset-demo');
  139. // cy.get('#data-1 button').click();
  140. // cy.get('#data-0 button').click();
  141. // cy.get('#data-0').should('not.exist');
  142. // cy.get('#addWithInit').click();
  143. // cy.get('#addWithInit').click();
  144. // cy.get('.line').should('have.length', 2);
  145. // cy.get('button[type=reset]').click();
  146. // cy.get('#data-2').should('not.exist');
  147. // cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  148. // cy.get('#data-0-role').should('have.value', `${D2C.role}`);
  149. // cy.get('#data-1-name').should('have.value', `${C2D.name}`);
  150. // cy.get('#data-1-role').should('have.value', `${C2D.role}`);
  151. // });
  152. // it('Combine Usage', () => {
  153. // // add -> remove -> modify
  154. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--basic-array-field-demo', {
  155. // onBeforeLoad(win) {
  156. // cy.stub(win.console, 'log').as('consoleLog');
  157. // },
  158. // });
  159. // cy.get('#addWithInit').click();
  160. // cy.get('#data-1 button').click();
  161. // cy.get('#data-0-role').type('-0');
  162. // cy.get('#data-0-name').type('-0');
  163. // cy.get('#data-0-name').should('have.value', `${D2C.name}-0`);
  164. // cy.get('#data-0-role').should('have.value', `${D2C.role}-0`);
  165. // cy.get('#data-1-name').should('have.value', `Semi New-3`);
  166. // cy.get('#data-1-role').should('have.value', `Designer`);
  167. // });
  168. // it('combine usage-2', () => {
  169. // // add -> remove -> modify -> reset
  170. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--basic-array-field-demo');
  171. // cy.get('#data-1 button').click();
  172. // cy.get('#data-0-role').type('-0');
  173. // cy.get('#data-0-name').type('-0');
  174. // cy.get('button[type=reset]').click();
  175. // cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  176. // cy.get('#data-0-role').should('have.value', `${D2C.role}`);
  177. // cy.get('#data-1-name').should('have.value', `${C2D.name}`);
  178. // cy.get('#data-1-role').should('have.value', `${C2D.role}`);
  179. // });
  180. // it('Init - Form Props initValues、ArrayField initValue、Field initValue', () => {
  181. // // 一个 Form 三个 ArrayField
  182. // });
  183. // it('Init - combine', () => {});
  184. // it('sync setValue - modify value, 2 -> 2', () => { });
  185. // it('sync setValue - add, 2 -> 3, add first', () => { });
  186. // it('sync setValue - add, 2 -> 3, add middle', () => { });
  187. // it('sync setValue - add, 2 -> 3, add last', () => { });
  188. // it('sync setValue - remove, 3 -> 2, remove first', () => { });
  189. // it('sync setValue - remove, 3 -> 2, remove middle', () => { });
  190. // it('sync setValue - remove, 3 -> 2, remove last', () => { });
  191. // it('sync setValue - remove, 3 -> 0, remove all', () => { });
  192. // it('sync setValues - modify', () => { });
  193. // it('sync setValues - add', () => { });
  194. // it('sync setValues - remove', () => { });
  195. // it('ASync setValues', () => { });
  196. // it('ASync setValue', () => { });
  197. // it('ASync setValue: ', () => { });
  198. // it('2 Nested ArrayField - add/remove', () => { });
  199. // it('2 Nested ArrayField - reset', () => { });
  200. // it('2 Nested ArrayField - formApi.setValues', () => { });
  201. // it('2 Nested ArrayField - formApi.setValue level-1', () => { });
  202. // it('2 Nested ArrayField - formApi.setValue level-2', () => { });
  203. // it('3 Nested ArrayField - add/remove', () => {});
  204. });