select.spec.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. describe('Select', () => {
  12. it('option hover, change active', () => {
  13. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--select-filter-single');
  14. cy.get('.semi-select').eq(0).click();
  15. // hover can change active index
  16. cy.get('.semi-select-option').eq(5).trigger('mouseover');
  17. cy.get('.semi-select-option-focused .semi-select-option-text').eq(0).should('have.text', 'wym');
  18. // press downArrow to test it
  19. cy.get('input').eq(0).type('{downArrow}');
  20. cy.get('.semi-select-option-focused .semi-select-option-text').eq(0).should('have.text', 'opts');
  21. });
  22. it('keyboard-enter, select choose option', { keystrokeDelay: 0 }, () => {
  23. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--select-filter-single');
  24. cy.get('.semi-select').eq(0).click();
  25. cy.get('input').eq(0).type('o');
  26. cy.get('input').eq(0).type('{downArrow}');
  27. cy.get('input').eq(0).type('{downArrow}');
  28. cy.get('input').eq(0).type('{enter}');
  29. cy.get('.semi-select-selection-text').eq(0).should('have.text', 'opt1');
  30. });
  31. it('clickOutSide, should hide', () => {
  32. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--select-filter-single', {
  33. onBeforeLoad(win) {
  34. cy.stub(win.console, 'log').as('consoleLog');
  35. },
  36. });
  37. cy.get('.semi-select').eq(0).click();
  38. // should show now
  39. cy.get('.semi-select-option-list').should('exist');
  40. // should hide after click empty area
  41. cy.get('h5').eq(0).click();
  42. cy.get('.semi-select-option-list').should('not.exist');
  43. cy.get('@consoleLog').should('be.calledWith', 'onBlur');
  44. });
  45. it('emptyContent=null', () => {
  46. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--empty-content');
  47. // when emptyContent = null, The dropdown list will not be displayed
  48. // so element(which class has semi-popover-wrapper) show have 0px height;
  49. cy.get('.semi-popover-wrapper').eq(0).should('have.css', 'height', '0px');
  50. });
  51. it('autoClearSearchValue false + remote + optionList update async', () => {
  52. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--auto-clear-search-value');
  53. cy.get('.remote-select').eq(0).click();
  54. cy.get('.semi-select-option').eq(0).click();
  55. cy.get('.remote-select .semi-input').eq(0).type('123');
  56. cy.wait(500);
  57. cy.get('.semi-select-option').should('have.text', 'Design');
  58. });
  59. it('optionGroup without key setting, filter', () => {
  60. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--select-option-group');
  61. cy.get('#without-key').eq(0).click();
  62. cy.get('#without-key .semi-input').eq(0).type('dou');
  63. cy.wait(500);
  64. cy.get('.semi-select-option-keyword').should('have.text', 'Dou');
  65. cy.get('.semi-select-group').should('have.text', 'Group1');
  66. cy.get('#without-key .semi-input').eq(0).type('{backspace}{backspace}{backspace}');
  67. cy.wait(500);
  68. cy.get('.semi-select-group').eq(0).should('have.text', 'Group1');
  69. cy.get('.semi-select-group').eq(1).should('have.text', 'Group2');
  70. cy.get('.semi-select-option').eq(0).should('have.text', 'Douyin');
  71. cy.get('.semi-select-option').eq(1).should('have.text', 'Ulikecam');
  72. cy.get('.semi-select-option').eq(2).should('have.text', 'Capcut');
  73. cy.get('.semi-select-option').eq(3).should('have.text', 'Xigua');
  74. });
  75. it('blur trigger by mouse click after select option', () => {
  76. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--all-case-of-blur', {
  77. onBeforeLoad(win) {
  78. cy.stub(win.console, 'log').as('consoleLog');
  79. },
  80. });
  81. cy.viewport(1000, 1000);
  82. cy.get('[data-cy=singleDefault]').click();
  83. cy.get('.semi-select-option').eq(1).click();
  84. cy.root().click('right');
  85. cy.get('@consoleLog').should('be.calledWith', 'single autoFocus onBlur');
  86. cy.get('@consoleLog').should('be.calledWith', 'single default onBlur');
  87. cy.get('[data-cy=singleFilter]').click();
  88. cy.get('.semi-select-option').eq(1).click();
  89. cy.root().click('right');
  90. cy.get('@consoleLog').should('be.calledWith', 'single filter onBlur');
  91. cy.get('[data-cy=singleClickToHide]').click();
  92. cy.get('.semi-select-option').eq(1).click();
  93. cy.root().click('right');
  94. cy.get('@consoleLog').should('be.calledWith', 'single clickToHide onBlur');
  95. cy.get('[data-cy=singleShowClear]').click();
  96. cy.get('.semi-select-option').eq(1).click();
  97. cy.root().click('right');
  98. cy.get('@consoleLog').should('be.calledWith', 'single showClear onBlur');
  99. cy.get('[data-cy=multipleDefault]').click();
  100. cy.get('.semi-select-option').eq(1).click();
  101. cy.root().click('right');
  102. cy.get('@consoleLog').should('be.calledWith', 'multiple default onBlur');
  103. cy.get('[data-cy=multipleFilter]').click();
  104. cy.get('.semi-select-option').eq(1).click();
  105. cy.root().click('right');
  106. cy.get('@consoleLog').should('be.calledWith', 'multiple filter onBlur');
  107. cy.get('[data-cy=multipleClickToHide]').click();
  108. cy.get('.semi-select-option').eq(1).click();
  109. cy.root().click('right');
  110. cy.get('@consoleLog').should('be.calledWith', 'multiple clickToHide onBlur');
  111. });
  112. it('blur trigger by mouse click without select option', () => {
  113. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--all-case-of-blur', {
  114. onBeforeLoad(win) {
  115. cy.stub(win.console, 'log').as('consoleLog');
  116. },
  117. });
  118. cy.viewport(1000, 1000);
  119. cy.get('[data-cy=singleDefault]').click();
  120. cy.root().click('right');
  121. cy.get('@consoleLog').should('be.calledWith', 'single autoFocus onBlur');
  122. cy.get('@consoleLog').should('be.calledWith', 'single default onBlur');
  123. cy.get('[data-cy=singleFilter]').click();
  124. cy.root().click('right');
  125. cy.get('@consoleLog').should('be.calledWith', 'single filter onBlur');
  126. cy.get('[data-cy=singleClickToHide]').click();
  127. cy.root().click('right');
  128. cy.get('@consoleLog').should('be.calledWith', 'single clickToHide onBlur');
  129. cy.get('[data-cy=singleShowClear]').click();
  130. cy.root().click('right');
  131. cy.get('@consoleLog').should('be.calledWith', 'single showClear onBlur');
  132. cy.get('[data-cy=multipleDefault]').click();
  133. cy.get('.semi-select-option').eq(1).click();
  134. cy.root().click('right');
  135. cy.get('@consoleLog').should('be.calledWith', 'multiple default onBlur');
  136. cy.get('[data-cy=multipleFilter]').click();
  137. cy.root().click('right');
  138. cy.get('@consoleLog').should('be.calledWith', 'multiple filter onBlur');
  139. cy.get('[data-cy=multipleClickToHide]').click();
  140. cy.root().click('right');
  141. cy.get('@consoleLog').should('be.calledWith', 'multiple clickToHide onBlur');
  142. });
  143. it('Fixed PR-2139', () => {
  144. // 1.Select multi-select turns on onChangWithObject and value is controlled
  145. // 2. The current value does not exist in optionList
  146. // 3. The problem that rendering is not re - executed after updating other attributes in value(such as label, or any other Key)
  147. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--update-other-key-not-in-list');
  148. cy.get('.render-content').eq(0).should('have.text', 'AA-Label-AA-OtherProps');
  149. cy.get('#change').eq(0).click();
  150. cy.get('.render-content').eq(0).should('have.text', 'AA-Label-2-AA-OtherProps-2');
  151. });
  152. it('Controled mode, same label text in reactNode', () => {
  153. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--controled-same-label-in-node');
  154. cy.get('[data-cy=singleControl]').click();
  155. cy.get('[data-cy=a-1]').click();
  156. cy.wait(300);
  157. cy.get('[data-cy=singleControl]').click(); // show optionList again
  158. cy.wait(300);
  159. cy.get('[data-cy=a-1]').should('have.class', 'semi-select-option-selected');
  160. cy.get('[data-cy=a-2]').click();
  161. cy.wait(500);
  162. cy.get('[data-cy=singleControl]').click();
  163. cy.wait(300);
  164. cy.get('[data-cy=a-2]').should('have.class', 'semi-select-option-selected');
  165. });
  166. it('renderOptionItem, keyboard Up & Down', () => {
  167. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--render-option-item');
  168. cy.get('[data-cy=multiple]').click();
  169. cy.wait(300);
  170. cy.get('input').eq(0).type('{downArrow}');
  171. cy.get('[data-cy=option-2]').should('have.class', 'custom-option-render-focused');
  172. cy.get('input').eq(0).type('{downArrow}');
  173. cy.get('[data-cy=option-3]').should('have.class', 'custom-option-render-focused');
  174. cy.get('input').eq(0).type('{downArrow}');
  175. cy.get('[data-cy=option-4]').should('have.class', 'custom-option-render-focused');
  176. cy.get('input').eq(0).type('{downArrow}');
  177. cy.get('[data-cy=option-5]').should('have.class', 'custom-option-render-focused');
  178. cy.get('input').eq(0).type('{downArrow}');
  179. cy.get('[data-cy=option-6]').should('have.class', 'custom-option-render-focused');
  180. cy.get('input').eq(0).type('{downArrow}');
  181. cy.get('[data-cy=option-7]').should('have.class', 'custom-option-render-focused');
  182. cy.get('input').eq(0).type('{downArrow}');
  183. cy.get('[data-cy=option-8]').should('have.class', 'custom-option-render-focused');
  184. cy.get('input').eq(0).type('{downArrow}');
  185. cy.get('[data-cy=option-1]').should('have.class', 'custom-option-render-focused');
  186. cy.get('input').eq(0).type('{upArrow}');
  187. cy.get('[data-cy=option-8]').should('have.class', 'custom-option-render-focused');
  188. });
  189. it('Fixed PR-2465', () => {
  190. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--fix-2465');
  191. cy.get('.semi-select').eq(0).click();
  192. cy.get('button').contains('single close').eq(0).click();
  193. cy.get('.semi-select').eq(0).should('have.class', 'semi-select-focus');
  194. cy.root().click('right');
  195. cy.get('.semi-select').eq(0).should('not.have.class', 'semi-select-focus');
  196. cy.get('.semi-select').eq(1).click();
  197. cy.get('button').contains('multiple close').eq(0).click();
  198. cy.get('.semi-select').eq(1).should('have.class', 'semi-select-focus');
  199. cy.root().click('right');
  200. cy.get('.semi-select').eq(1).should('not.have.class', 'semi-select-focus');
  201. });
  202. // it('ellipsisTrigger', () => {
  203. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--fix-1560');
  204. // // add option
  205. // cy.get('.semi-select-arrow').eq(0).click();
  206. // cy.get('.semi-select-option').contains('剪映').click();
  207. // cy.get('.semi-tag-grey-light').eq(0).contains('+2');
  208. // // reduce option
  209. // cy.get('.semi-select-arrow').eq(0).click();
  210. // cy.get('.semi-select-option').contains('抖音').click();
  211. // cy.get('.semi-tag-large').eq(2).contains('剪映');
  212. // cy.get('body').click('right');
  213. // // reduce option
  214. // cy.get('.semi-select-arrow').eq(1).click();
  215. // cy.get('.semi-select-option').contains('西瓜视频').click();
  216. // cy.get('.semi-tag-grey-light').eq(0).contains('+1');
  217. // // add option
  218. // cy.get('.semi-select-arrow').eq(1).click();
  219. // cy.get('.semi-select-option').contains('西瓜视频').click();
  220. // cy.get('.semi-tag-grey-light').eq(0).contains('+2');
  221. // });
  222. // it('should trigger onSearch when click x icon', () => {
  223. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--select-filter-single');
  224. // cy.get('.semi-select').eq(0).click();
  225. // cy.get('.semi-select-option').eq(0).click();
  226. // cy.get('.semi-select').eq(0).click();
  227. // cy.get('.semi-select-clear').eq(0).click();
  228. // cy.get('.semi-select-input .semi-input').should('have.value', '');
  229. // });
  230. // it('should trigger onBlur and onSearch', () => {
  231. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--use-form-api-set-value-update-array');
  232. // });
  233. // it('keyboard-skip disabled option when press up/down', () => {
  234. // });
  235. // it('optionList scroll, should trigger onListScroll', () => {
  236. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--use-form-api-set-value-update-array');
  237. // });
  238. });