form.spec.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  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. // ❌ 发现了bug
  12. // modify
  13. // it('Basic usage - modify、add blank row、add withInitValue row', () => {
  14. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--basic-array-field-demo');
  15. // cy.get('#data-0-name').type('-new');
  16. // cy.get('#data-0-role').type('-new');
  17. // cy.get('#data-0-name').should('have.value', 'Semi D2C-new');
  18. // cy.get('#data-0-role').should('have.value', 'Engineer-new');
  19. // // add blank row
  20. // cy.get('#add').click();
  21. // cy.wait(300);
  22. // cy.get('#data-2-name').should('have.value', '');
  23. // cy.get('#data-2-role').should('have.value', '');
  24. // // add withInitValue row
  25. // cy.get('#addWithInit').click();
  26. // cy.wait(300);
  27. // cy.get('#data-3-name').should('have.value', 'Semi New-3');
  28. // cy.get('#data-3-role').should('have.value', 'Designer');
  29. // });
  30. const D2C = { name: 'Semi D2C', role: 'Engineer' };
  31. const C2D = { name: 'Semi C2D', role: 'Designer' };
  32. const DSM = { name: 'Semi DSM', role: 'Designer' };
  33. describe('Form', () => {
  34. it('formApi-setValue with array field path, 3 -> 2, remove middle line field', () => {
  35. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--use-form-api-set-value-update-array');
  36. cy.get(':nth-child(3) > .semi-button').click();
  37. // line 1
  38. cy.get('[x-field-id="effects[0].name"] > .semi-form-field-main > .semi-input-wrapper > input').should('have.value', '1-name');
  39. cy.get('[x-field-id="effects[0].type"] > .semi-form-field-main > .semi-input-wrapper > input').should('have.value', '1-type');
  40. // line 2
  41. cy.get('[x-field-id="effects[1].name"] > .semi-form-field-main > .semi-input-wrapper > input').should('have.value', '3-name');
  42. cy.get('[x-field-id="effects[1].type"] > .semi-form-field-main > .semi-input-wrapper > input').should('have.value', '3-type');
  43. // cy.get('body').find('.semi-popover .semi-datepicker').should('have.length', 0);
  44. });
  45. it('Basic usage - add withInitValue row、add blank row', () => {
  46. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--basic-array-field-demo');
  47. // add withInitValue row
  48. cy.get('#addWithInit').click();
  49. cy.get('#data-2-name').should('have.value', 'Semi New-3');
  50. cy.get('#data-2-role').should('have.value', 'Designer');
  51. // add blank row
  52. cy.get('#add').click();
  53. cy.get('#data-3-name').should('have.value', '');
  54. cy.get('#data-3-role').should('have.value', '');
  55. });
  56. // // remove row
  57. it('Remove row - 3 -> 2, remove middle', () => {
  58. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--remove-demo');
  59. cy.get('#data-1 button').click();
  60. cy.get('#data-0-name').should('have.value', D2C.name);
  61. cy.get('#data-0-role').should('have.value', D2C.role);
  62. cy.get('#data-1-name').should('have.value', DSM.name);
  63. cy.get('#data-1-role').should('have.value', DSM.role);
  64. });
  65. it('Remove row - 3 -> 2, remove middle, 2 -> 1, remove head', () => {
  66. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--remove-demo');
  67. cy.get('#data-1 button').click();
  68. cy.get('#data-0-name').should('have.value', D2C.name);
  69. cy.get('#data-0-role').should('have.value', D2C.role);
  70. cy.get('#data-1-name').should('have.value', DSM.name);
  71. cy.get('#data-1-role').should('have.value', DSM.role);
  72. cy.get('#data-0 button').click();
  73. cy.get('#data-0-name').should('have.value', DSM.name);
  74. cy.get('#data-0-role').should('have.value', DSM.role);
  75. cy.get('#data-1').should('not.exist');
  76. });
  77. it('Remove row - 3 -> 2, remove head', () => {
  78. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--remove-demo');
  79. cy.get('#data-2').should('exist');
  80. cy.get('#data-0 button').click();
  81. cy.get('#data-2').should('not.exist');
  82. cy.get('#data-0-name').should('have.value', C2D.name);
  83. cy.get('#data-0-role').should('have.value', C2D.role);
  84. cy.get('#data-1-name').should('have.value', DSM.name);
  85. cy.get('#data-1-role').should('have.value', DSM.role);
  86. cy.get('#data-0 button').click();
  87. cy.get('#data-0-name').should('have.value', DSM.name);
  88. cy.get('#data-0-role').should('have.value', DSM.role);
  89. });
  90. it('Remove row - 3 -> 2, remove last', () => {
  91. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--remove-demo');
  92. cy.get('#data-2').should('exist');
  93. cy.get('#data-2 button').click();
  94. cy.get('#data-2').should('not.exist');
  95. cy.get('#data-0-name').should('have.value', D2C.name);
  96. cy.get('#data-0-role').should('have.value', D2C.role);
  97. cy.get('#data-1-name').should('have.value', C2D.name);
  98. cy.get('#data-1-role').should('have.value', C2D.role);
  99. });
  100. // it('Basic usage - add、remove、reset', () => { });
  101. // reset
  102. it('Reset Usage: modify => reset ', () => {
  103. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--reset-demo');
  104. cy.get('#data-0-name').type('-new');
  105. cy.get('#data-0-role').type('-new');
  106. cy.get('#data-0-name').should('have.value', `${D2C.name}-new`);
  107. cy.get('#data-0-role').should('have.value', `${D2C.role}-new`);
  108. cy.get('button[type=reset]').click();
  109. cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  110. cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  111. });
  112. it('Reset Usage: length 2 -> 1 => reset ', () => {
  113. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--reset-demo');
  114. cy.get('#data-0 button').click();
  115. cy.get('#data-1').should('not.exist');
  116. cy.get('button[type=reset]').click();
  117. // cy.get('#data-1').should('exist');
  118. cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  119. cy.get('#data-0-role').should('have.value', `${D2C.role}`);
  120. cy.get('#data-1-name').should('have.value', `${C2D.name}`);
  121. cy.get('#data-1-role').should('have.value', `${C2D.role}`);
  122. });
  123. it('Reset Usage: length 2 -> 0 -> 3 => reset ', () => {
  124. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--reset-demo');
  125. cy.get('#data-1 button').click();
  126. cy.get('#data-0 button').click();
  127. cy.get('#data-0').should('not.exist');
  128. cy.get('#addWithInit').click();
  129. cy.get('#addWithInit').click();
  130. cy.get('#addWithInit').click();
  131. cy.get('#data-2').should('exist');
  132. cy.get('button[type=reset]').click();
  133. cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  134. cy.get('#data-0-role').should('have.value', `${D2C.role}`);
  135. cy.get('#data-1-name').should('have.value', `${C2D.name}`);
  136. cy.get('#data-1-role').should('have.value', `${C2D.role}`);
  137. cy.get('#data-2').should('not.exist');
  138. });
  139. it('Reset Usage: length 2 -> 0 -> 2 => reset ', () => {
  140. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--reset-demo');
  141. cy.get('#data-1 button').click();
  142. cy.get('#data-0 button').click();
  143. cy.get('#data-0').should('not.exist');
  144. cy.get('#addWithInit').click();
  145. cy.get('#addWithInit').click();
  146. cy.get('.line').should('have.length', 2);
  147. cy.get('button[type=reset]').click();
  148. cy.get('#data-2').should('not.exist');
  149. cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  150. cy.get('#data-0-role').should('have.value', `${D2C.role}`);
  151. cy.get('#data-1-name').should('have.value', `${C2D.name}`);
  152. cy.get('#data-1-role').should('have.value', `${C2D.role}`);
  153. });
  154. it('Combine Usage', () => {
  155. // add -> remove -> modify
  156. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--basic-array-field-demo', {
  157. onBeforeLoad(win) {
  158. cy.stub(win.console, 'log').as('consoleLog');
  159. },
  160. });
  161. cy.get('#addWithInit').click();
  162. cy.get('#data-1 button').click();
  163. cy.get('#data-0-role').type('-0');
  164. cy.get('#data-0-name').type('-0');
  165. cy.get('#data-0-name').should('have.value', `${D2C.name}-0`);
  166. cy.get('#data-0-role').should('have.value', `${D2C.role}-0`);
  167. cy.get('#data-1-name').should('have.value', `Semi New-3`);
  168. cy.get('#data-1-role').should('have.value', `Designer`);
  169. });
  170. it('combine usage-2', () => {
  171. // add -> remove -> modify -> reset
  172. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--basic-array-field-demo');
  173. cy.get('#data-1 button').click();
  174. cy.get('#data-0-role').type('-0');
  175. cy.get('#data-0-name').type('-0');
  176. cy.get('button[type=reset]').click();
  177. cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  178. cy.get('#data-0-role').should('have.value', `${D2C.role}`);
  179. cy.get('#data-1-name').should('have.value', `${C2D.name}`);
  180. cy.get('#data-1-role').should('have.value', `${C2D.role}`);
  181. });
  182. it('sync setValue - modify value, 2 -> 2', () => {
  183. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--manual-set-demo');
  184. cy.get('#updateSync').click();
  185. cy.get('#data-0-name').should('have.value', `${D2C.name}-0`);
  186. cy.get('#data-0-role').should('have.value', `${D2C.role}-0`);
  187. cy.get('#data-1-name').should('have.value', `${C2D.name}-1`);
  188. cy.get('#data-1-role').should('have.value', `${C2D.role}`);
  189. });
  190. it('sync setValue - add, 2 -> 3, add tail', () => {
  191. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--manual-set-demo');
  192. cy.get('#addTailSync').click();
  193. cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  194. cy.get('#data-0-role').should('have.value', `${D2C.role}`);
  195. cy.get('#data-1-name').should('have.value', `${C2D.name}`);
  196. cy.get('#data-1-role').should('have.value', `${C2D.role}`);
  197. cy.get('#data-2-name').should('have.value', `${DSM.name}`);
  198. cy.get('#data-2-role').should('have.value', `${DSM.role}`);
  199. });
  200. it('sync setValue - add, 2 -> 3, add first', () => {
  201. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--manual-set-demo');
  202. cy.get('#addHeadSync').click();
  203. cy.get('#data-0-name').should('have.value', `${DSM.name}`);
  204. cy.get('#data-0-role').should('have.value', `${DSM.role}`);
  205. cy.get('#data-1-name').should('have.value', `${D2C.name}`);
  206. cy.get('#data-1-role').should('have.value', `${D2C.role}`);
  207. cy.get('#data-2-name').should('have.value', `${C2D.name}`);
  208. cy.get('#data-2-role').should('have.value', `${C2D.role}`);
  209. });
  210. it('sync setValue - add, 2 -> 3, add middle', () => {
  211. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--manual-set-demo');
  212. cy.get('#addMiddleSync').click();
  213. cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  214. cy.get('#data-0-role').should('have.value', `${D2C.role}`);
  215. cy.get('#data-2-name').should('have.value', `${C2D.name}`);
  216. cy.get('#data-2-role').should('have.value', `${C2D.role}`);
  217. cy.get('#data-1-name').should('have.value', `${DSM.name}`);
  218. cy.get('#data-1-role').should('have.value', `${DSM.role}`);
  219. });
  220. it('sync setValue - remove, 3 -> 2, remove first', () => {
  221. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--manual-set-demo');
  222. cy.get('#addTailSync').click();
  223. cy.get('#removeHeadSync').click();
  224. cy.get('#data-0-name').should('have.value', `${C2D.name}`);
  225. cy.get('#data-0-role').should('have.value', `${C2D.role}`);
  226. cy.get('#data-1-name').should('have.value', `${DSM.name}`);
  227. cy.get('#data-1-role').should('have.value', `${DSM.role}`);
  228. });
  229. it('sync setValue - remove, 3 -> 2, remove middle', () => {
  230. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--manual-set-demo');
  231. cy.get('#addTailSync').click();
  232. cy.get('#removeMiddleSync').click();
  233. cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  234. cy.get('#data-0-role').should('have.value', `${D2C.role}`);
  235. cy.get('#data-1-name').should('have.value', `${DSM.name}`);
  236. cy.get('#data-1-role').should('have.value', `${DSM.role}`);
  237. });
  238. it('sync setValue - remove, 3 -> 2, remove tail', () => {
  239. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--manual-set-demo');
  240. cy.get('#addTailSync').click();
  241. cy.get('#removeTailSync').click();
  242. cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  243. cy.get('#data-0-role').should('have.value', `${D2C.role}`);
  244. cy.get('#data-1-name').should('have.value', `${C2D.name}`);
  245. cy.get('#data-1-role').should('have.value', `${C2D.role}`);
  246. });
  247. it('sync setValue - remove, 3 -> 0, remove all', () => {
  248. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--manual-set-demo');
  249. cy.get('#addTailSync').click();
  250. cy.get('#removeAllSync').click();
  251. cy.get('.line').should('have.length', 0);
  252. });
  253. it('Async setValue - modify value, 2 -> 2', () => {
  254. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--manual-set-async-demo');
  255. cy.get('#updateAsync').click();
  256. cy.wait(500);
  257. cy.get('#data-0-name').should('have.value', `${D2C.name}-0`);
  258. cy.get('#data-0-role').should('have.value', `${D2C.role}-0`);
  259. cy.get('#data-1-name').should('have.value', `${C2D.name}-1`);
  260. cy.get('#data-1-role').should('have.value', `${C2D.role}`);
  261. });
  262. it('Async setValue - add, 2 -> 3, add tail', () => {
  263. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--manual-set-async-demo');
  264. cy.get('#addTailAsync').click();
  265. cy.wait(500);
  266. cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  267. cy.get('#data-0-role').should('have.value', `${D2C.role}`);
  268. cy.get('#data-1-name').should('have.value', `${C2D.name}`);
  269. cy.get('#data-1-role').should('have.value', `${C2D.role}`);
  270. cy.get('#data-2-name').should('have.value', `${DSM.name}`);
  271. cy.get('#data-2-role').should('have.value', `${DSM.role}`);
  272. });
  273. it('Async setValue - add, 2 -> 3, add first', () => {
  274. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--manual-set-async-demo');
  275. cy.get('#addHeadAsync').click();
  276. cy.wait(500);
  277. cy.get('#data-0-name').should('have.value', `${DSM.name}`);
  278. cy.get('#data-0-role').should('have.value', `${DSM.role}`);
  279. cy.get('#data-1-name').should('have.value', `${D2C.name}`);
  280. cy.get('#data-1-role').should('have.value', `${D2C.role}`);
  281. cy.get('#data-2-name').should('have.value', `${C2D.name}`);
  282. cy.get('#data-2-role').should('have.value', `${C2D.role}`);
  283. });
  284. it('Async setValue - add, 2 -> 3, add middle', () => {
  285. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--manual-set-async-demo');
  286. cy.get('#addMiddleAsync').click();
  287. cy.wait(500);
  288. cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  289. cy.get('#data-0-role').should('have.value', `${D2C.role}`);
  290. cy.get('#data-2-name').should('have.value', `${C2D.name}`);
  291. cy.get('#data-2-role').should('have.value', `${C2D.role}`);
  292. cy.get('#data-1-name').should('have.value', `${DSM.name}`);
  293. cy.get('#data-1-role').should('have.value', `${DSM.role}`);
  294. });
  295. it('Async setValue - remove, 3 -> 2, remove first', () => {
  296. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--manual-set-async-demo');
  297. cy.get('#addTailAsync').click();
  298. cy.wait(500);
  299. cy.get('#removeHeadAsync').click();
  300. cy.wait(500);
  301. cy.get('#data-0-name').should('have.value', `${C2D.name}`);
  302. cy.get('#data-0-role').should('have.value', `${C2D.role}`);
  303. cy.get('#data-1-name').should('have.value', `${DSM.name}`);
  304. cy.get('#data-1-role').should('have.value', `${DSM.role}`);
  305. });
  306. it('Async setValue - remove, 3 -> 2, remove middle', () => {
  307. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--manual-set-async-demo');
  308. cy.get('#addTailAsync').click();
  309. cy.wait(500);
  310. cy.get('#removeMiddleAsync').click();
  311. cy.wait(500);
  312. cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  313. cy.get('#data-0-role').should('have.value', `${D2C.role}`);
  314. cy.get('#data-1-name').should('have.value', `${DSM.name}`);
  315. cy.get('#data-1-role').should('have.value', `${DSM.role}`);
  316. });
  317. it('Async setValue - remove, 3 -> 2, remove tail', () => {
  318. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--manual-set-async-demo');
  319. cy.get('#addTailAsync').click();
  320. cy.wait(500);
  321. cy.get('#removeTailAsync').click();
  322. cy.wait(500);
  323. cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  324. cy.get('#data-0-role').should('have.value', `${D2C.role}`);
  325. cy.get('#data-1-name').should('have.value', `${C2D.name}`);
  326. cy.get('#data-1-role').should('have.value', `${C2D.role}`);
  327. });
  328. it('Async setValue - remove, 2 -> 0, remove all', () => {
  329. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--manual-set-async-demo');
  330. cy.get('#removeAllAsync').click();
  331. cy.wait(500);
  332. cy.get('.line').should('have.length', 0);
  333. });
  334. it('2 Nested ArrayField - basic', () => {
  335. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--basic-nested-demo');
  336. // check initValue
  337. cy.get('#data-0-name').should('have.value', `0`);
  338. cy.get('#data-0-rule-0-type').should('have.value', `0-0-type`);
  339. cy.get('#data-0-rule-0-desc').should('have.value', `0-0-desc`);
  340. cy.get('#data-0-rule-1-type').should('have.value', `0-1-type`);
  341. cy.get('#data-0-rule-1-desc').should('have.value', `0-1-desc`);
  342. cy.get('#data-1-name').should('have.value', `1`);
  343. cy.get('#data-1-rule-0-type').should('have.value', `1-0-type`);
  344. cy.get('#data-1-rule-0-desc').should('have.value', `1-0-desc`);
  345. });
  346. it('2 Nested ArrayField - add / remove / reset', () => {
  347. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--basic-nested-demo');
  348. // // add level 0
  349. cy.get('#data-1-add').click();
  350. cy.get('#data-2-name').should('have.value', `2`);
  351. cy.get('#data-2-rule-0-type').should('have.value', `2-0-type`);
  352. cy.get('#data-2-rule-0-desc').should('have.value', `2-0-desc`);
  353. // // add level 1
  354. cy.get('#data-0-rule-1-add').click();
  355. cy.get('#data-0-rule-2-type').should('have.value', `0-2-type`);
  356. cy.get('#data-0-rule-2-desc').should('have.value', `0-2-desc`);
  357. cy.get('#data-2-rule-0-add').click();
  358. cy.get('#data-2-rule-1-type').should('have.value', `2-1-type`);
  359. cy.get('#data-2-rule-1-desc').should('have.value', `2-1-desc`);
  360. // remove
  361. /**
  362. * 0 => 0
  363. * 0-0 0-0
  364. * 0-1 0-2
  365. * 0-2
  366. * 1 1
  367. * 1-0
  368. * 2 2
  369. * 2-0 2-0
  370. * 2-1
  371. */
  372. cy.get('#data-0-rule-1-remove').click();
  373. cy.get('#data-1-rule-0-remove').click();
  374. cy.get('#data-2-rule-1-remove').click();
  375. cy.get('#data-0-name').should('have.value', `0`);
  376. cy.get('#data-0-rule-0-type').should('have.value', `0-0-type`);
  377. cy.get('#data-0-rule-0-desc').should('have.value', `0-0-desc`);
  378. cy.get('#data-0-rule-1-type').should('have.value', `0-2-type`); // cause remove middle
  379. cy.get('#data-0-rule-1-desc').should('have.value', `0-2-desc`); // cause remove middle
  380. cy.get('#data-1-name').should('have.value', `1`);
  381. cy.get('#data-1-rule-0-type').should('not.exist');
  382. cy.get('#data-1-rule-0-desc').should('not.exist');
  383. cy.get('#data-2-name').should('have.value', `2`);
  384. cy.get('#data-2-rule-0-type').should('have.value', `2-0-type`); // cause remove tail
  385. cy.get('#data-2-rule-0-desc').should('have.value', `2-0-desc`); // cause remove tail
  386. // reset
  387. cy.get('button[type=reset]').click();
  388. cy.get('#data-0-name').should('have.value', `0`);
  389. cy.get('#data-0-rule-0-type').should('have.value', `0-0-type`);
  390. cy.get('#data-0-rule-0-desc').should('have.value', `0-0-desc`);
  391. cy.get('#data-0-rule-1-type').should('have.value', `0-1-type`);
  392. cy.get('#data-0-rule-1-desc').should('have.value', `0-1-desc`);
  393. cy.get('#data-1-name').should('have.value', `1`);
  394. cy.get('#data-1-rule-0-type').should('have.value', `1-0-type`);
  395. cy.get('#data-1-rule-0-desc').should('have.value', `1-0-desc`);
  396. cy.get('#data-2-name').should('not.exist');
  397. cy.get('#data-2-rule-0-type').should('not.exist');
  398. cy.get('#data-2-rule-0-desc').should('not.exist');
  399. });
  400. it('2 Nested ArrayField - formApi.setValue level-0', () => {
  401. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--basic-nested-demo');
  402. cy.get('#changeOutSide').click();
  403. cy.get('#data-0-name').should('have.value', `new-0`);
  404. cy.get('#data-0-rule-0-type').should('have.value', `new-0-0-type`);
  405. cy.get('#data-0-rule-0-desc').should('have.value', `new-0-0-desc`);
  406. cy.get('#data-0-rule-1-type').should('have.value', `new-0-1-type`);
  407. cy.get('#data-0-rule-1-desc').should('have.value', `new-0-1-desc`);
  408. cy.get('#data-1-name').should('have.value', `new-1`);
  409. cy.get('#data-1-rule-0-type').should('have.value', `new-1-0-type`);
  410. cy.get('#data-1-rule-0-desc').should('have.value', `new-1-0-desc`);
  411. cy.get('#data-2-name').should('have.value', `new-2`);
  412. cy.get('#data-2-rule-0-type').should('have.value', `new-2-0-type`);
  413. cy.get('#data-2-rule-0-desc').should('have.value', `new-2-0-desc`);
  414. cy.get('#data-2-rule-1-type').should('have.value', `new-2-1-type`);
  415. cy.get('#data-2-rule-1-desc').should('have.value', `new-2-1-desc`);
  416. cy.get('#data-2-rule-2-type').should('have.value', `new-2-2-type`);
  417. cy.get('#data-2-rule-2-desc').should('have.value', `new-2-2-desc`);
  418. });
  419. it('2 Nested ArrayField - formApi.setValue level-1', () => {
  420. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--basic-nested-demo');
  421. cy.get('#changeInside').click();
  422. cy.get('#data-0-rule-0-type').should('have.value', `new-0-0-type-in`);
  423. cy.get('#data-0-rule-0-desc').should('have.value', `new-0-0-desc-in`);
  424. cy.get('#data-0-rule-1-type').should('not.exist');
  425. cy.get('#data-0-rule-1-desc').should('not.exist');
  426. // still same
  427. cy.get('#data-0-name').should('have.value', `0`);
  428. cy.get('#data-1-name').should('have.value', `1`);
  429. cy.get('#data-1-rule-0-type').should('have.value', `1-0-type`);
  430. cy.get('#data-1-rule-0-desc').should('have.value', `1-0-desc`);
  431. });
  432. it('2 Nested ArrayField - formApi.setValue level-0 then set level-1', () => {
  433. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--basic-nested-demo');
  434. cy.get('#changeOutSide').click();
  435. cy.get('#changeInside').click();
  436. cy.get('#data-0-name').should('have.value', `new-0`);
  437. cy.get('#data-0-rule-0-type').should('have.value', `new-0-0-type-in`); // cause rewrite by changeInside
  438. cy.get('#data-0-rule-0-desc').should('have.value', `new-0-0-desc-in`); // cause rewrite by changeInside
  439. cy.get('#data-0-rule-1-type').should('not.exist'); // cause rewrite by changeInside
  440. cy.get('#data-0-rule-1-desc').should('not.exist'); // cause rewrite by changeInside
  441. cy.get('#data-1-name').should('have.value', `new-1`);
  442. cy.get('#data-1-rule-0-type').should('have.value', `new-1-0-type`);
  443. cy.get('#data-1-rule-0-desc').should('have.value', `new-1-0-desc`);
  444. cy.get('#data-2-name').should('have.value', `new-2`);
  445. cy.get('#data-2-rule-0-type').should('have.value', `new-2-0-type`);
  446. cy.get('#data-2-rule-0-desc').should('have.value', `new-2-0-desc`);
  447. cy.get('#data-2-rule-1-type').should('have.value', `new-2-1-type`);
  448. cy.get('#data-2-rule-1-desc').should('have.value', `new-2-1-desc`);
  449. cy.get('#data-2-rule-2-type').should('have.value', `new-2-2-type`);
  450. cy.get('#data-2-rule-2-desc').should('have.value', `new-2-2-desc`);
  451. });
  452. it('2 Nested ArrayField - formApi.setValue level-1 then set level-0 then reset', () => {
  453. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--basic-nested-demo');
  454. cy.get('#changeInside').click();
  455. cy.get('#data-0-name').should('have.value', `0`);
  456. cy.get('#data-0-rule-0-type').should('have.value', `new-0-0-type-in`);
  457. cy.get('#data-0-rule-0-desc').should('have.value', `new-0-0-desc-in`);
  458. cy.get('#data-0-rule-1-type').should('not.exist');
  459. cy.get('#data-0-rule-1-desc').should('not.exist');
  460. cy.get('#data-1-name').should('have.value', `1`);
  461. cy.get('#data-1-rule-0-type').should('have.value', `1-0-type`);
  462. cy.get('#data-1-rule-0-desc').should('have.value', `1-0-desc`);
  463. cy.get('#changeOutSide').click();
  464. cy.get('#data-0-name').should('have.value', `new-0`);
  465. cy.get('#data-0-rule-0-type').should('have.value', `new-0-0-type`);
  466. cy.get('#data-0-rule-0-desc').should('have.value', `new-0-0-desc`);
  467. cy.get('#data-0-rule-1-type').should('have.value', `new-0-1-type`);
  468. cy.get('#data-0-rule-1-desc').should('have.value', `new-0-1-desc`);
  469. cy.get('#data-1-name').should('have.value', `new-1`);
  470. cy.get('#data-1-rule-0-type').should('have.value', `new-1-0-type`);
  471. cy.get('#data-1-rule-0-desc').should('have.value', `new-1-0-desc`);
  472. cy.get('#data-2-name').should('have.value', `new-2`);
  473. cy.get('#data-2-rule-0-type').should('have.value', `new-2-0-type`);
  474. cy.get('#data-2-rule-0-desc').should('have.value', `new-2-0-desc`);
  475. cy.get('#data-2-rule-1-type').should('have.value', `new-2-1-type`);
  476. cy.get('#data-2-rule-1-desc').should('have.value', `new-2-1-desc`);
  477. cy.get('#data-2-rule-2-type').should('have.value', `new-2-2-type`);
  478. cy.get('#data-2-rule-2-desc').should('have.value', `new-2-2-desc`);
  479. cy.get('button[type=reset]').click();
  480. cy.get('#data-0-name').should('have.value', `0`);
  481. cy.get('#data-0-rule-0-type').should('have.value', `0-0-type`);
  482. cy.get('#data-0-rule-0-desc').should('have.value', `0-0-desc`);
  483. cy.get('#data-0-rule-1-type').should('have.value', `0-1-type`);
  484. cy.get('#data-0-rule-1-desc').should('have.value', `0-1-desc`);
  485. cy.get('#data-1-name').should('have.value', `1`);
  486. cy.get('#data-1-rule-0-type').should('have.value', `1-0-type`);
  487. cy.get('#data-1-rule-0-desc').should('have.value', `1-0-desc`);
  488. });
  489. it('2 Nested ArrayField - formApi.setValue level-0 then set level-1 then level-0 then reset', () => {
  490. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--basic-nested-demo');
  491. cy.get('#changeOutSide').click();
  492. cy.get('#changeInside').click();
  493. cy.get('#changeOutSide').click();
  494. cy.get('#data-0-name').should('have.value', `new-0`);
  495. cy.get('#data-0-rule-0-type').should('have.value', `new-0-0-type`);
  496. cy.get('#data-0-rule-0-desc').should('have.value', `new-0-0-desc`);
  497. cy.get('#data-0-rule-1-type').should('have.value', `new-0-1-type`);
  498. cy.get('#data-0-rule-1-desc').should('have.value', `new-0-1-desc`);
  499. cy.get('#data-1-name').should('have.value', `new-1`);
  500. cy.get('#data-1-rule-0-type').should('have.value', `new-1-0-type`);
  501. cy.get('#data-1-rule-0-desc').should('have.value', `new-1-0-desc`);
  502. cy.get('#data-2-name').should('have.value', `new-2`);
  503. cy.get('#data-2-rule-0-type').should('have.value', `new-2-0-type`);
  504. cy.get('#data-2-rule-0-desc').should('have.value', `new-2-0-desc`);
  505. cy.get('#data-2-rule-1-type').should('have.value', `new-2-1-type`);
  506. cy.get('#data-2-rule-1-desc').should('have.value', `new-2-1-desc`);
  507. cy.get('#data-2-rule-2-type').should('have.value', `new-2-2-type`);
  508. cy.get('#data-2-rule-2-desc').should('have.value', `new-2-2-desc`);
  509. cy.get('button[type=reset]').click();
  510. cy.get('#data-0-name').should('have.value', `0`);
  511. cy.get('#data-0-rule-0-type').should('have.value', `0-0-type`);
  512. cy.get('#data-0-rule-0-desc').should('have.value', `0-0-desc`);
  513. cy.get('#data-0-rule-1-type').should('have.value', `0-1-type`);
  514. cy.get('#data-0-rule-1-desc').should('have.value', `0-1-desc`);
  515. cy.get('#data-1-name').should('have.value', `1`);
  516. cy.get('#data-1-rule-0-type').should('have.value', `1-0-type`);
  517. cy.get('#data-1-rule-0-desc').should('have.value', `1-0-desc`);
  518. });
  519. it('2 Nested ArrayField - formApi.setValue special row', () => {
  520. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--basic-nested-demo');
  521. cy.get('#changeRow').click();
  522. cy.get('#data-0-name').should('have.value', `0`);
  523. cy.get('#data-0-rule-0-type').should('have.value', `special-row-type`);
  524. cy.get('#data-0-rule-0-desc').should('have.value', `special-row-desc`);
  525. cy.get('#data-0-rule-1-type').should('have.value', `0-1-type`);
  526. cy.get('#data-0-rule-1-desc').should('have.value', `0-1-desc`);
  527. cy.get('#data-1-name').should('have.value', `1`);
  528. cy.get('#data-1-rule-0-type').should('have.value', `1-0-type`);
  529. cy.get('#data-1-rule-0-desc').should('have.value', `1-0-desc`);
  530. });
  531. // // it('2 Nested ArrayField - formApi.setValues', () => { });
  532. // // it('Async setValues', () => { });
  533. // it('sync setValues - modify value, 2 -> 2', () => {
  534. // });
  535. // it('sync setValues - add, 2 -> 3, add tail', () => {
  536. // });
  537. // it('sync setValues - add, 2 -> 3, add first', () => {
  538. // });
  539. // it('sync setValues - add, 2 -> 3, add middle', () => {
  540. // });
  541. // it('sync setValues - remove, 3 -> 2, remove first', () => {
  542. // });
  543. // it('sync setValues - remove, 3 -> 2, remove middle', () => {
  544. // });
  545. // it('sync setValues - remove, 3 -> 2, remove tail', () => {
  546. // });
  547. // it('sync setValues - remove, 2 -> 0, remove all', () => {
  548. // });
  549. it('Init - Form Props initValues、ArrayField initValue、Field initValue', () => {
  550. // 一个 Form 三个 ArrayField
  551. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--init-demo');
  552. // Form Props initValues
  553. cy.get('#data-0-name').should('have.value', `${D2C.name}`);
  554. cy.get('#data-0-role').should('have.value', `${D2C.role}`);
  555. cy.get('#data-1-name').should('have.value', `${C2D.name}`);
  556. cy.get('#data-1-role').should('have.value', `${C2D.role}`);
  557. cy.get('#dataAddWithInit').click();
  558. cy.get('#data-2-name').should('have.value', 'Data-3');
  559. cy.get('#data-2-role').should('have.value', 'Designer');
  560. // ArrayField Props initValue
  561. cy.get('#dataB-0-name').should('have.value', 'NameInArrayFieldProp');
  562. cy.get('#dataB-0-role').should('have.value', 'RoleInArrayFieldProp');
  563. cy.get('#dataB-1-name').should('not.exist');
  564. cy.get('#dataB-1-role').should('not.exist');
  565. cy.get('#dataBAddWithInit').click();
  566. cy.get('#dataB-1-name').should('have.value', 'DataB-2');
  567. cy.get('#dataB-1-role').should('have.value', 'Designer');
  568. // Field Props initValue
  569. cy.get('#dataCAddWithInit').click();
  570. cy.get('#dataC-0-name').should('have.value', 'DataC-1');
  571. cy.get('#dataC-0-role').should('have.value', 'Designer');
  572. cy.get('#dataCAdd').click();
  573. // if add empty, should use field props
  574. // TODO
  575. });
  576. it('Init - combine, test priority', () => {
  577. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--init-combine-demo');
  578. // FormProps + ArrayField Props, should use ArrayField Props first
  579. cy.get('#data-0-name').should('have.value', 'NameInArrayFieldProp');
  580. cy.get('#data-0-role').should('have.value', 'RoleInArrayFieldProp');
  581. // ArrayField Props + Field Props, should use FieldProps first
  582. cy.get('#dataB-0-name').should('have.value', 'NameInFieldProp');
  583. cy.get('#dataB-0-role').should('have.value', 'RoleInFieldProp');
  584. });
  585. // it('Init - Nested', () => {
  586. // });
  587. });