1
0

table.spec.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. // table.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. describe('table', () => {
  8. it('row selection', () => {
  9. cy.visit('http://127.0.0.1:6006/iframe.html?id=table--selection-table&args=&viewMode=story');
  10. cy.get('.semi-table-row-head .semi-checkbox-inner-display').click();
  11. cy.get('.semi-checkbox-checked').should('have.length', 4);
  12. });
  13. /**
  14. * 测试 columns 为字面量时刷新 Table,页码应保持当前页
  15. * 即更新 columns 不影响 currentPage
  16. */
  17. it('columns change ', () => {
  18. cy.visit('http://localhost:6006/iframe.html?id=table--fixed-columns-change&viewMode=story');
  19. cy.get('.semi-page-item').contains('2').click();
  20. cy.get('.semi-table-tbody .semi-checkbox').eq(1).click()
  21. .then(() => {
  22. cy.get('.semi-page-item').contains('2').should('have.class', 'semi-page-item-active');
  23. });
  24. });
  25. it('defaultFilteredValue', () => {
  26. cy.visit('http://localhost:6006/iframe.html?id=table--default-filtered-value&args=&viewMode=story');
  27. // 筛选为默认值
  28. cy.contains('显示第 1 条-第 10 条,共 23 条');
  29. // 动态变更数据后,默认筛选生效
  30. cy.get('.semi-button').contains('toggle change dataSource (46/25)').click();
  31. cy.contains('显示第 1 条-第 10 条,共 12 条');
  32. // 筛选手动设置为空后,动态变更数据,筛选值为空
  33. cy.get('.semi-table-column-filter').click();
  34. cy.get('.semi-dropdown-menu .semi-dropdown-item:nth-child(2)').click();
  35. cy.get('.semi-button').contains('toggle change dataSource (46/25)').click();
  36. cy.contains('显示第 1 条-第 10 条,共 46 条');
  37. });
  38. it('jsx columns nested change', () => {
  39. cy.visit('http://localhost:6006/iframe.html?id=table--fixed-header-merge&args=&viewMode=story');
  40. cy.get('[data-cy=button]').click();
  41. cy.contains("Base Information");
  42. cy.contains("Company Information");
  43. });
  44. it('scroll', () => {
  45. cy.visit('http://localhost:6006/iframe.html?id=table--scroll-bar&args=&viewMode=story');
  46. cy.get('.semi-table-body').scrollTo('bottom');
  47. cy.get('.semi-table-body').scrollTo('top');
  48. cy.get('.semi-table-body').scrollTo('left');
  49. cy.get('.semi-table-body').scrollTo('right');
  50. });
  51. it('resizable header', () => {
  52. cy.visit('http://localhost:6006/iframe.html?id=table--resizable-columns&args=&viewMode=story');
  53. cy.get('.react-resizable-handle').eq(0)
  54. .trigger('mousedown', { which: 1 })
  55. .trigger('mousemove', { clientX: 400, clientY: 100 })
  56. .trigger('mouseup', { force: true });
  57. cy.get('.semi-table-row-cell').eq(0).should('have.css', 'width').and('eq', '364px');
  58. cy.get('.react-resizable-handle').eq(1)
  59. .trigger('mousedown', { which: 1 })
  60. .trigger('mousemove', { clientX: 800, clientY: 100 })
  61. .trigger('mouseup', { force: true });
  62. cy.get('.semi-table-row-cell').eq(1).should('have.css', 'width').and('eq', '400px');
  63. });
  64. it('scroll table header click', () => {
  65. cy.visit('http://localhost:6006/iframe.html?id=table--fixed-on-header-row&args=&viewMode=story');
  66. cy.contains('标题').click();
  67. cy.contains('header click').should('be.visible');
  68. });
  69. it('infinite scroll', () => {
  70. cy.visit('http://localhost:6006/iframe.html?id=table--infinite-scroll-demo&args=&viewMode=story');
  71. // fixed the viewport
  72. cy.viewport(1000, 660);
  73. // the virtualied table should not load all table item
  74. cy.get('div[role="row"]').should('have.length.below', 30);
  75. // test the scroll in virtualized table
  76. cy.get('.semi-table-body').scrollTo('bottom');
  77. // Wait for the scroll result to take effect
  78. cy.wait(500);
  79. cy.get('div[role="gridcell"]').contains('Edward King 14');
  80. cy.get('.semi-table-body').scrollTo('bottom');
  81. cy.wait(500);
  82. cy.get('div[role="row"]').contains('Edward King 34');
  83. cy.get('.semi-table-body').scrollTo('top');
  84. cy.wait(500);
  85. cy.get('div[role="row"]').contains('Edward King 0');
  86. });
  87. it.skip('scrollToFirstRowOnChange', () => {
  88. cy.visit('http://localhost:6006/iframe.html?id=table--virtualized&args=&viewMode=story');
  89. cy.get('.semi-table-body').scrollTo(0, 150);
  90. cy.get('div[role="button"]').click();
  91. cy.get('div[role="row"]').contains('Edward King 9983');
  92. });
  93. it('resize', () => {
  94. cy.visit('http://localhost:6006/iframe.html?id=table--dynamic-table&args=&viewMode=story');
  95. cy.viewport(1000, 660);
  96. cy.get('.semi-switch').eq(0).click();
  97. cy.get('.semi-table-body').should('have.css', "max-height", "300px");
  98. });
  99. it('fix filter', () => {
  100. cy.visit('http://localhost:6006/iframe.html?id=table--fixed-filter&args=&viewMode=story');
  101. cy.get('.semi-table-column-filter').click();
  102. cy.get('.semi-checkbox').contains('Semi Design 设计稿').click();
  103. cy.get('.semi-checkbox').contains('Semi Pro 设计稿').click();
  104. cy.get('.semi-table-tbody .semi-table-row').eq(0).should('contain', 'Semi Design 设计稿0.fig');
  105. cy.get('.semi-table-tbody .semi-table-row').eq(1).should('contain', 'Semi Pro 设计稿1.fig');
  106. });
  107. it('empty filters', () => {
  108. cy.visit('http://localhost:6006/iframe.html?id=table--empty-filters&args=&viewMode=story');
  109. // filter title with `Semi Pro`
  110. cy.get('.semi-input').type('Semi Pro');
  111. // expect title contains `Semi Pro`
  112. cy.get('.semi-table-body .semi-table-row').eq(0).contains('Semi Pro');
  113. cy.get('.semi-table-body .semi-table-row').eq(1).contains('Semi Pro');
  114. cy.get('.semi-table-body .semi-table-row').eq(2).contains('Semi Pro');
  115. cy.contains('显示第 1 条-第 10 条,共 23 条');
  116. });
  117. it('fixed row selection header state', () => {
  118. cy.visit('http://localhost:6006/iframe.html?id=table--fix-select-all-325&args=&viewMode=story');
  119. cy.get('.semi-table-row-head .semi-checkbox-inner-display').click();
  120. cy.get('.semi-checkbox-checked').should('have.length', 3);
  121. cy.get('.semi-page-item').contains('2').click();
  122. cy.get('.semi-table-row-head .semi-checkbox-checked');
  123. cy.get('.semi-table-row-head .semi-checkbox-indeterminate').should('not.exist');
  124. cy.get('.semi-checkbox-checked').should('have.length', 4);
  125. cy.get('.semi-table-tbody .semi-checkbox-inner-display').eq(0).click();
  126. cy.get('.semi-table-row-head .semi-checkbox-indeterminate');
  127. cy.get('.semi-table-row-head .semi-checkbox-inner-display').click();
  128. cy.get('.semi-table-row-head .semi-checkbox-checked');
  129. cy.get('.semi-checkbox-checked').should('have.length', 4);
  130. });
  131. it('normal table ellipsis title', () => {
  132. cy.visit('http://localhost:6006/iframe.html?id=table--ellipsis-normal-table&args=&viewMode=story');
  133. cy.get('.semi-table-row-head-title').eq(0).should('have.attr', 'title');
  134. cy.get('.semi-table-row-head-title').eq(1).should('have.attr', 'title');
  135. cy.get('.semi-table-row-head-title').eq(2).should('have.attr', 'title');
  136. cy.get('.semi-table-row-head-ellipsis').eq(3).should('have.attr', 'title');
  137. });
  138. it('fixed table ellipsis title', () => {
  139. cy.visit('http://localhost:6006/iframe.html?id=table--ellipsis-fixed-table&args=&viewMode=story');
  140. cy.get('.semi-table-row-head-title').eq(0).should('have.attr', 'title');
  141. cy.get('.semi-table-row-head-title').eq(1).should('have.attr', 'title');
  142. cy.get('.semi-table-row-head-title').eq(2).should('have.attr', 'title');
  143. cy.get('.semi-table-row-head-ellipsis').eq(3).should('have.attr', 'title');
  144. });
  145. it('fixed table ellipsis showTitle false', () => {
  146. cy.visit('http://localhost:6006/iframe.html?id=table--show-title-table&args=&viewMode=story');
  147. cy.get('.semi-table-row-head-title').eq(0).should('not.have.attr', 'title');
  148. cy.get('.semi-table-row-head-title').eq(1).should('not.have.attr', 'title');
  149. cy.get('.semi-table-row-head-title').eq(2).should('not.have.attr', 'title');
  150. cy.get('.semi-table-row-head-ellipsis').eq(3).should('not.have.attr', 'title');
  151. cy.get('.semi-table-row-cell').eq(0).should('not.have.attr', 'title');
  152. cy.get('.semi-table-row-cell').eq(1).should('not.have.attr', 'title');
  153. cy.get('.semi-table-row-cell').eq(2).should('not.have.attr', 'title');
  154. cy.get('.semi-table-row-cell').eq(3).should('not.have.attr', 'title');
  155. });
  156. it('fixed onChange filter incorrect, when setting defaultFilteredValue & without onFilter', () => {
  157. cy.visit('http://localhost:6006/iframe.html?id=table--fix-on-change&viewMode=story', {
  158. onBeforeLoad(win) {
  159. cy.stub(win.console, 'log').as('consoleLog'); // 测试时用到控制台的前置步骤
  160. },
  161. });
  162. cy.get('.semi-table-column-sorter').eq(1).click();
  163. // filters 长度应该为 1
  164. cy.get('@consoleLog').should('be.calledWith', 1);
  165. });
  166. it('resizable onHeaderCell', () => {
  167. cy.visit('http://localhost:6006/iframe.html?id=table--resizable-table&viewMode=story');
  168. cy.get('.test-1').should('have.length', 1);
  169. cy.get('.test-2').should('have.length', 1);
  170. });
  171. it('test sorter sortOrder parameter', () => {
  172. cy.visit('http://localhost:6006/iframe.html?id=table--sorter-sort-order&viewMode=story', {
  173. onBeforeLoad(win) {
  174. cy.stub(win.console, 'log').as('consoleLog'); // 测试时用到控制台的前置步骤
  175. },
  176. });
  177. cy.get('.semi-table-column-sorter').eq(0).click();
  178. cy.get('.semi-table-tbody .semi-table-row').eq(4).should('contain.text', '未知');
  179. cy.get('.semi-table-tbody .semi-table-row').eq(5).should('contain.text', '未知');
  180. cy.get('.semi-table-column-sorter').eq(0).click();
  181. cy.get('.semi-table-tbody .semi-table-row').eq(4).should('contain.text', '未知');
  182. cy.get('.semi-table-tbody .semi-table-row').eq(5).should('contain.text', '未知');
  183. });
  184. it('test given pageSize + showSizeChanger', () => {
  185. cy.visit('http://localhost:6006/iframe.html?id=table--fixed-pagination&viewMode=story');
  186. cy.get('.semi-page-switch').eq(0).click();
  187. cy.get('.semi-select-option').eq(0).click();
  188. cy.wait(500);
  189. cy.get('.semi-page-item').eq(4).click();
  190. cy.get('.semi-table-pagination-info').should('contain.text', '显示第 31 条-第 40 条,共 46 条')
  191. cy.get('.semi-page-item-active').eq(0).should('contain.text', '4');
  192. cy.get('.semi-page-item').eq(5).click();
  193. cy.get('.semi-table-pagination-info').should('contain.text', '显示第 41 条-第 46 条,共 46 条')
  194. cy.get('.semi-page-item-active').eq(0).should('contain.text', '5');
  195. })
  196. it('test virtualized showHeader false', () => {
  197. cy.visit('http://localhost:6006/iframe.html?args=&id=table--show-header&viewMode=story');
  198. cy.get('.semi-table-header').should('have.length', 1);
  199. cy.window().then(window => {
  200. const header = window.document.querySelector('.semi-table-header');
  201. const style = window.getComputedStyle(header);
  202. expect(style.height).eq('0px');
  203. });
  204. })
  205. it('test keepDOM', () => {
  206. cy.visit('http://localhost:6006/iframe.html?id=table--keep-dom&viewMode=story');
  207. cy.get('[data-cy=expand] .semi-table-row-hidden').should('have.length', 3);
  208. cy.get('[data-cy=tree] .semi-table-row-hidden').should('have.length', 5);
  209. cy.get('[data-cy=tree] .semi-table-expand-icon').eq(0).click();
  210. cy.get('[data-cy=tree] .semi-table-row-hidden').should('have.length', 3);
  211. cy.get('[data-cy=section] .semi-table-row-hidden').should('have.length', 10);
  212. cy.get('[data-cy=section] .semi-table-expand-icon').eq(0).click({ force: true });
  213. cy.get('[data-cy=section] .semi-table-row-hidden').should('have.length', 7);
  214. });
  215. it('test header selected status when all rows are disabled and selected ', () => {
  216. cy.visit('http://localhost:6006/iframe.html?id=table--fixed-all-disabled-and-selected&viewMode=story');
  217. cy.get('button').contains('点击全选').click();
  218. cy.get('.semi-table-thead .semi-checkbox-checked').should('exist')
  219. });
  220. it('test renderFilterDropdown', () => {
  221. cy.visit('http://localhost:6006/iframe.html?args=&id=table--feat-render-filter-dropdown&viewMode=story');
  222. // 测试第一个筛选器
  223. cy.get('.semi-table-column-filter').eq(0).click();
  224. cy.get('.semi-input').should('be.focused');
  225. cy.get('.semi-input').type('12');
  226. cy.get('.semi-button').contains('筛选+关闭').click();
  227. cy.get('.semi-table-tbody .semi-table-row').should('have.length', 1);
  228. cy.get('.semi-table-column-filter').eq(0).click();
  229. cy.get('.semi-input').should('be.focused');
  230. cy.get('.semi-button').contains('清除+关闭').click();
  231. cy.get('.semi-table-tbody .semi-table-row').should('have.length', 10);
  232. cy.get('.semi-table-column-filter').eq(0).click();
  233. cy.get('.semi-input').should('be.focused');
  234. cy.get('.semi-button').contains('直接关闭').click();
  235. cy.get('.semi-dropdown').should('not.exist');
  236. // 测试第二个筛选器
  237. cy.get('.semi-table-column-filter').eq(1).click();
  238. cy.get('.semi-input').should('have.value', '姜鹏志');
  239. cy.get('.semi-button').contains('清除后不关闭').click();
  240. cy.get('.semi-table-pagination-info').should('contain', '显示第 1 条-第 10 条,共 46 条');
  241. cy.get('.semi-dropdown').should('exist');
  242. cy.get('.semi-table-column-filter').eq(1).click();
  243. cy.get('.semi-input').type('郝宣');
  244. cy.get('.semi-button').contains('筛选后不关闭').click();
  245. cy.get('.semi-table-pagination-info').should('contain', '显示第 1 条-第 10 条,共 23 条');
  246. cy.get('.semi-dropdown').should('exist');
  247. cy.get('.semi-button').contains('直接关闭').click();
  248. cy.get('.semi-dropdown').should('not.exist');
  249. });
  250. });