table.test.js 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887
  1. import BaseTable from '../Table';
  2. import Table from '../index';
  3. import Column from '../Column';
  4. import {Tag, Tooltip} from '../../index';
  5. import {
  6. getColumns,
  7. getData,
  8. getGroupColumns,
  9. getGroupData,
  10. getJSXColumns,
  11. getNestColumns,
  12. getNestData,
  13. getRandomNumber,
  14. getTreeData,
  15. mount,
  16. sleep,
  17. } from '../../_test_/utils';
  18. import {BASE_CLASS_PREFIX} from '../../../semi-foundation/base/constants';
  19. import {IconStar} from '@douyinfe/semi-icons';
  20. /**
  21. * Table 需要测试的使用场景
  22. * ✅ JSX 写法
  23. * ✅ 行选择
  24. * ✅ 分页
  25. * ✅ 固定列
  26. * ✅ 排序
  27. * ✅ 筛选
  28. * ✅ 展开
  29. * ✅ 树形展示
  30. * ✅ 自定义行或单元格
  31. * ✅ 分组
  32. * ✅ 表头合并
  33. * ✅ 更新数据
  34. * ✅ 完全自定义渲染
  35. * ✅ 行列合并
  36. * ❌ 可伸缩列(不好测试)
  37. * ❌ 拖拽排序(不好测试)
  38. * ❌ 虚拟化
  39. */
  40. const dataTotalSize = 46;
  41. const data = getData(dataTotalSize);
  42. const columns = getColumns();
  43. function testAppearance(demo, params) {
  44. const {onRow, myCls, myClsIndex} = params; // check table wrapper
  45. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-wrapper`).length).toBe(1); // check if has header
  46. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-title`).length).toBe(1); // check if has footer
  47. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-footer`).length).toBe(1); // check onRow
  48. expect(onRow.called).toBe(true);
  49. expect(
  50. demo
  51. .find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row`)
  52. .at(0)
  53. .hasClass(myCls)
  54. ).toBe(false);
  55. expect(
  56. demo.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row`).reduce((prev, item, index) => {
  57. if (item.hasClass(myCls)) {
  58. return index;
  59. } else {
  60. return prev;
  61. }
  62. }, -1)
  63. ).toBe(myClsIndex); // check pagination
  64. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-pagination-outer`).length).toBe(1); // click page 2
  65. const curPage = 2;
  66. demo.find(`.${BASE_CLASS_PREFIX}-page li`)
  67. .at(curPage)
  68. .simulate('click');
  69. expect(demo.find(BaseTable).state('pagination')).toHaveProperty('currentPage', curPage);
  70. }
  71. describe(`Table`, () => {
  72. it(`test jsx columns appearance`, async () => {
  73. const myCls = `my-tr-class`;
  74. const myClsIndex = 2;
  75. const onRow = sinon.spy((record, index) => ({
  76. className: index === myClsIndex ? myCls : '',
  77. }));
  78. const columns = getJSXColumns();
  79. const demo = mount(
  80. <Table
  81. dataSource={data}
  82. onRow={onRow}
  83. title={() => 'Table Title'}
  84. footer={() => 'Table Footer'}
  85. children={columns}
  86. />
  87. );
  88. testAppearance(demo, {
  89. onRow,
  90. myCls,
  91. myClsIndex,
  92. });
  93. const newColumns = getJSXColumns();
  94. demo.setProps({
  95. children: newColumns,
  96. });
  97. testAppearance(demo, {
  98. onRow,
  99. myCls,
  100. myClsIndex,
  101. });
  102. });
  103. it(`test object columns appearance`, async () => {
  104. const myCls = `my-tr-class`;
  105. const myClsIndex = 2;
  106. const onRow = sinon.spy((record, index) => ({
  107. className: index === myClsIndex ? myCls : '',
  108. }));
  109. const columns = getColumns();
  110. const demo = mount(
  111. <Table
  112. dataSource={data}
  113. onRow={onRow}
  114. title={() => 'Table Title'}
  115. footer={() => 'Table Footer'}
  116. columns={columns}
  117. />
  118. );
  119. testAppearance(demo, {
  120. onRow,
  121. myCls,
  122. myClsIndex,
  123. });
  124. const newColumns = getColumns();
  125. demo.setProps({
  126. columns: newColumns,
  127. });
  128. testAppearance(demo, {
  129. onRow,
  130. myCls,
  131. myClsIndex,
  132. });
  133. });
  134. it(`test dataSource change appearance`, async () => {
  135. const myCls = `my-tr-class`;
  136. const myClsIndex = 2;
  137. const onRow = sinon.spy((record, index) => ({
  138. className: index === myClsIndex ? myCls : '',
  139. }));
  140. const columns = getColumns();
  141. const data = getData(25);
  142. const demo = mount(
  143. <Table
  144. dataSource={data}
  145. onRow={onRow}
  146. title={() => 'Table Title'}
  147. footer={() => 'Table Footer'}
  148. columns={columns}
  149. />
  150. );
  151. testAppearance(demo, {
  152. onRow,
  153. myCls,
  154. myClsIndex,
  155. });
  156. const dataNum = getRandomNumber(100, 40);
  157. const newData = getData(dataNum);
  158. demo.setProps({
  159. dataSource: newData,
  160. });
  161. testAppearance(demo, {
  162. onRow,
  163. myCls,
  164. myClsIndex,
  165. });
  166. });
  167. it(`test selection`, async () => {
  168. const columns = getColumns();
  169. const selectedRowKeys = ['0'];
  170. const rowKey = 'key';
  171. const disabledKeys = ['4'];
  172. let rowSelection = {
  173. onChange: sinon.spy((selectedRowKeys, selectedRows) => {
  174. rowSelection = {...rowSelection, selectedRowKeys: [...selectedRowKeys]};
  175. demo.setProps({
  176. rowSelection,
  177. });
  178. }),
  179. onSelectAll: sinon.spy((selected, selectedRows, changedRows) => {
  180. rowSelection = {...rowSelection, selectedRowKeys: selected ? [...selectedRowKeys] : []};
  181. demo.setProps({
  182. rowSelection,
  183. });
  184. }),
  185. getCheckboxProps: sinon.spy(record => ({
  186. disabled: disabledKeys.includes(record[rowKey]),
  187. // Column configuration not to be checked
  188. name: record.name,
  189. })),
  190. onSelect: sinon.spy((record, selected) => {
  191. }),
  192. selectedRowKeys: ['3'],
  193. defaultSelectedRowKeys: ['0', '1'],
  194. };
  195. const demo = mount(<Table rowKey={rowKey} dataSource={data} columns={columns} rowSelection={rowSelection}/>);
  196. expect(demo.find(`.${BASE_CLASS_PREFIX}-checkbox`).length).toBeGreaterThan(0);
  197. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-row .${BASE_CLASS_PREFIX}-checkbox-inner-checked`).length).toBe(
  198. rowSelection.selectedRowKeys.length
  199. );
  200. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-checkbox-indeterminate`).length).toBe(
  201. 1
  202. );
  203. expect(
  204. demo
  205. .find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-checkbox`)
  206. .map(el => el)
  207. .every((el, index) =>
  208. disabledKeys.includes(index.toString())
  209. ? el.hasClass(`${BASE_CLASS_PREFIX}-checkbox-disabled`)
  210. : true
  211. )
  212. ).toBeTruthy(); // click disabled checkbox
  213. demo.find(`.${BASE_CLASS_PREFIX}-table-row .${BASE_CLASS_PREFIX}-checkbox-disabled`).simulate('click');
  214. expect(rowSelection.onSelect.notCalled).toBeTruthy(); // click first row checkbox
  215. demo.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row .${BASE_CLASS_PREFIX}-checkbox`)
  216. .at(0)
  217. .simulate('click');
  218. expect(rowSelection.onSelect.calledOnce).toBeTruthy(); // click table header checkbox and select all
  219. demo.find(
  220. `.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-table-column-selection .${BASE_CLASS_PREFIX}-checkbox`
  221. ).simulate('click');
  222. expect(rowSelection.onSelectAll.calledOnce).toBeTruthy();
  223. expect(demo.find(BaseTable).state('rowSelection')).toHaveProperty(
  224. 'selectedRowKeys',
  225. rowSelection.selectedRowKeys
  226. );
  227. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-checkbox-inner-checked`).length).toBe(
  228. 1
  229. ); // click table header checkbox and deselect all
  230. demo.find(
  231. `.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-table-column-selection .${BASE_CLASS_PREFIX}-checkbox`
  232. ).simulate('click');
  233. expect(rowSelection.onSelectAll.calledTwice).toBeTruthy();
  234. expect(demo.find(BaseTable).state('rowSelection')).toHaveProperty('selectedRowKeys', []);
  235. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-checkbox-inner-checked`).length).toBe(
  236. 0
  237. );
  238. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-checkbox-indeterminate`).length).toBe(
  239. 0
  240. );
  241. });
  242. it(`test selection after data change`, async () => {
  243. const columns = getColumns();
  244. const selectedRowKeys = ['0'];
  245. const rowKey = 'key';
  246. const disabledKeys = ['4'];
  247. let rowSelection = {
  248. onSelectAll: sinon.spy((selected, selectedRows, changedRows) => {
  249. rowSelection = {...rowSelection, selectedRowKeys: selected ? [...selectedRowKeys] : []};
  250. demo.setProps({
  251. rowSelection,
  252. });
  253. }),
  254. getCheckboxProps: sinon.spy(record => ({
  255. disabled: disabledKeys.includes(record[rowKey]),
  256. // Column configuration not to be checked
  257. name: record.name,
  258. })),
  259. onSelect: sinon.spy((record, selected) => {
  260. }),
  261. };
  262. const demo = mount(<Table rowKey={rowKey} dataSource={data} columns={columns} rowSelection={rowSelection}/>);
  263. const newData = getData(50);
  264. demo.setProps({
  265. dataSource: newData,
  266. }); // click disabled checkbox
  267. demo.find(`.${BASE_CLASS_PREFIX}-table-row .${BASE_CLASS_PREFIX}-checkbox-disabled`).simulate('click');
  268. expect(rowSelection.onSelect.notCalled).toBeTruthy(); // click first row checkbox
  269. demo.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row .${BASE_CLASS_PREFIX}-checkbox`)
  270. .at(0)
  271. .simulate('click');
  272. expect(rowSelection.onSelect.calledOnce).toBeTruthy(); // click table header checkbox and select all
  273. demo.find(
  274. `.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-table-column-selection .${BASE_CLASS_PREFIX}-checkbox`
  275. ).simulate('click');
  276. expect(rowSelection.onSelectAll.calledOnce).toBeTruthy(); // click table header checkbox and deselect all
  277. demo.find(
  278. `.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-table-column-selection .${BASE_CLASS_PREFIX}-checkbox`
  279. ).simulate('click');
  280. expect(rowSelection.onSelectAll.calledTwice).toBeTruthy();
  281. });
  282. it(`test expandedRowRender and fixed`, async () => {
  283. const columns = getColumns();
  284. const rowKey = 'key';
  285. const expandedRowRender = (record, index, expanded) => (
  286. <article
  287. style={{
  288. margin: 0,
  289. }}
  290. >
  291. <p>{record.description}</p>
  292. </article>
  293. );
  294. const unexpandableKey = '2';
  295. const demo = mount(
  296. <Table
  297. scroll={{
  298. x: '160%',
  299. y: 320,
  300. }}
  301. defaultExpandAllRows
  302. rowKey={rowKey}
  303. expandedRowRender={expandedRowRender}
  304. hideExpandedColumn={false}
  305. expandCellFixed={true}
  306. dataSource={data}
  307. columns={columns}
  308. rowExpandable={record => record[rowKey] !== unexpandableKey}
  309. />
  310. );
  311. const leftFixedCells = demo.find(`.${BASE_CLASS_PREFIX}-table-cell-fixed-left`);
  312. const rightFixedCells = demo.find(`.${BASE_CLASS_PREFIX}-table-cell-fixed-right`);
  313. expect(leftFixedCells.length).toBeGreaterThan(0);
  314. expect(rightFixedCells.length).toBeGreaterThan(0);
  315. expect(
  316. demo.find(`.${BASE_CLASS_PREFIX}-table-cell-fixed-left.${BASE_CLASS_PREFIX}-table-column-expand`).length
  317. ).toBeGreaterThan(0);
  318. const newData = getData(50);
  319. demo.setProps({
  320. dataSource: newData,
  321. });
  322. expect(
  323. demo.find(`.${BASE_CLASS_PREFIX}-table-cell-fixed-left.${BASE_CLASS_PREFIX}-table-column-expand`).length
  324. ).toBeGreaterThan(0);
  325. });
  326. it(`test tree data`, async () => {
  327. const rowKey = 'key';
  328. const childrenRecordName = 'children';
  329. const childrenData = getTreeData();
  330. let expandedRowKeys = [1];
  331. const onExpand = sinon.spy((expanded, record) => {
  332. const keySet = new Set([...expandedRowKeys]);
  333. if (expanded) {
  334. keySet.add(record[rowKey]);
  335. } else {
  336. keySet.delete(record[rowKey]);
  337. }
  338. expandedRowKeys = Array.from(keySet);
  339. demo.setProps({
  340. expandedRowKeys,
  341. });
  342. });
  343. const demo = mount(
  344. <Table
  345. rowKey={rowKey}
  346. childrenRecordName={childrenRecordName}
  347. expandedRowKeys={expandedRowKeys}
  348. columns={columns}
  349. dataSource={childrenData}
  350. onExpand={onExpand}
  351. />
  352. );
  353. const table = demo.find(BaseTable);
  354. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row`).length).toBe(
  355. childrenData[0].children.length + childrenData.length
  356. ); // click 3rd row to expand row
  357. table
  358. .find(
  359. `.${BASE_CLASS_PREFIX}-table-body .${BASE_CLASS_PREFIX}-table-row .${BASE_CLASS_PREFIX}-table-expand-icon`
  360. )
  361. .at(1)
  362. .simulate('click');
  363. expect(onExpand.calledOnce).toBeTruthy();
  364. expect(table.state(`expandedRowKeys`)).toEqual(expandedRowKeys); // click first expand button to collapse row
  365. table
  366. .find(
  367. `.${BASE_CLASS_PREFIX}-table-body .${BASE_CLASS_PREFIX}-table-row .${BASE_CLASS_PREFIX}-table-expand-icon`
  368. )
  369. .at(0)
  370. .simulate('click');
  371. expect(table.state('expandedRowKeys')).toEqual(expandedRowKeys);
  372. });
  373. it(`test grouped data`, async () => {
  374. const rowKey = record =>
  375. `${record.city && record.city.toLowerCase()}-${record.job && record.job.toLowerCase()}`;
  376. const data = [
  377. {
  378. city: 'Beijing',
  379. job: 'FE',
  380. department: 'IES',
  381. },
  382. {
  383. city: 'Beijing',
  384. job: 'BE',
  385. department: 'IES',
  386. },
  387. {
  388. city: 'Shanghai',
  389. job: 'Android',
  390. department: 'IES',
  391. },
  392. {
  393. city: 'Tokyo',
  394. job: 'Android',
  395. department: 'IES',
  396. },
  397. {
  398. city: 'Shanghai',
  399. job: 'IOS',
  400. department: 'EE',
  401. },
  402. {
  403. city: 'LA',
  404. job: 'SE',
  405. department: 'EE',
  406. },
  407. {
  408. city: 'Beijing',
  409. job: 'Android',
  410. department: 'EE',
  411. },
  412. {
  413. city: 'Tokyo',
  414. job: 'IOS',
  415. department: 'EE',
  416. },
  417. {
  418. city: 'Tokyo',
  419. job: 'SE',
  420. department: 'DATA',
  421. },
  422. {
  423. city: 'Shanghai',
  424. job: 'BE',
  425. department: 'DATA',
  426. },
  427. {
  428. city: 'LA',
  429. job: 'Android',
  430. department: 'DATA',
  431. },
  432. {
  433. city: 'LA',
  434. job: 'IOS',
  435. department: 'DATA',
  436. },
  437. ];
  438. const columns = [
  439. {
  440. dataIndex: 'city',
  441. title: 'City',
  442. width: 400,
  443. sorter: (a, b) => (a.city > b.city ? 1 : -1),
  444. },
  445. {
  446. dataIndex: 'job',
  447. title: 'Job',
  448. width: 200,
  449. filters: [
  450. {
  451. text: 'IOS',
  452. value: 'IOS',
  453. },
  454. {
  455. text: 'Android',
  456. value: 'Android',
  457. },
  458. ],
  459. onFilter: (value, record) => record.job && record.job.indexOf(value) === 0,
  460. },
  461. {
  462. dataIndex: 'department',
  463. title: 'Department',
  464. },
  465. ];
  466. const groupedRowClick = sinon.spy();
  467. const demo = mount(
  468. <Table
  469. dataSource={data}
  470. rowKey={rowKey}
  471. groupBy={'city'}
  472. columns={columns}
  473. renderGroupSection={groupKey => <strong>Jobs in {groupKey}:</strong>}
  474. onGroupedRow={(group, index) => ({
  475. onClick: groupedRowClick,
  476. })}
  477. clickGroupedRowToExpand
  478. scroll={{
  479. y: 480,
  480. }}
  481. />
  482. );
  483. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-row-section`).length).toBe(4);
  484. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-body .${BASE_CLASS_PREFIX}-table-row`).length).toBe(0);
  485. demo.find(`.${BASE_CLASS_PREFIX}-table-row-section`)
  486. .at(0)
  487. .simulate('click');
  488. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-row`).length).toBeGreaterThan(0);
  489. });
  490. it(`test events: page, filter, sort`, async () => {
  491. const columns = [
  492. {
  493. title: 'Name',
  494. dataIndex: 'name',
  495. width: 150,
  496. filters: [
  497. {
  498. text: '名字包含"1"',
  499. value: '1',
  500. },
  501. {
  502. text: '名字包含"2"',
  503. value: '2',
  504. },
  505. ],
  506. onFilter: (value, record) => record.name.indexOf(value) > -1,
  507. },
  508. {
  509. title: 'Age',
  510. dataIndex: 'age',
  511. width: 150,
  512. sorter: (a, b) => (a.age - b.age > 0 ? 1 : -1),
  513. },
  514. {
  515. title: 'Address',
  516. dataIndex: 'address',
  517. },
  518. {
  519. render: (text, record) => (
  520. <Tooltip content={record.description}>
  521. <Tag color="green">Show Info</Tag>
  522. </Tooltip>
  523. ),
  524. width: 150,
  525. },
  526. ];
  527. let onChangeCalledCount = 0;
  528. const onChange = sinon.spy();
  529. const demo = mount(<Table dataSource={data} columns={columns} onChange={onChange}/>);
  530. demo.find(`.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-table-column-filter`).simulate('click');
  531. expect(demo.find(`.${BASE_CLASS_PREFIX}-dropdown`).length).toBe(1);
  532. expect(onChange.callCount).toBe(onChangeCalledCount); // click first filter
  533. demo.find(`.${BASE_CLASS_PREFIX}-dropdown .${BASE_CLASS_PREFIX}-dropdown-item`)
  534. .at(0)
  535. .find(`.${BASE_CLASS_PREFIX}-checkbox`)
  536. .simulate('click', {
  537. nativeEvent: null,
  538. });
  539. expect(onChange.callCount).toBe(++onChangeCalledCount); // click first filter again
  540. demo.find(`.${BASE_CLASS_PREFIX}-dropdown .${BASE_CLASS_PREFIX}-dropdown-item`)
  541. .at(0)
  542. .find(`.${BASE_CLASS_PREFIX}-checkbox`)
  543. .simulate('click', {
  544. nativeEvent: null,
  545. });
  546. expect(onChange.callCount).toBe(++onChangeCalledCount); // to page 2
  547. demo.find(`.${BASE_CLASS_PREFIX}-page .${BASE_CLASS_PREFIX}-page-item`)
  548. .at(2)
  549. .simulate('click', {
  550. nativeEvent: null,
  551. });
  552. expect(onChange.callCount).toBe(++onChangeCalledCount); // to page 1
  553. demo.find(`.${BASE_CLASS_PREFIX}-page .${BASE_CLASS_PREFIX}-page-item`)
  554. .at(1)
  555. .simulate('click', {
  556. nativeEvent: null,
  557. });
  558. expect(onChange.callCount).toBe(++onChangeCalledCount); // sort
  559. demo.find(`.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-table-column-sorter`).simulate('click', {
  560. nativeEvent: null,
  561. });
  562. expect(onChange.callCount).toBe(++onChangeCalledCount);
  563. });
  564. it(`test filter, and update dataSource with exist filter`, () => {
  565. const columns = [
  566. {
  567. className: 'name-col',
  568. title: 'Name',
  569. dataIndex: 'name',
  570. width: 150,
  571. filters: [
  572. {
  573. text: '名字包含"1"',
  574. value: '1',
  575. },
  576. {
  577. text: '名字包含"2"',
  578. value: '2',
  579. },
  580. ],
  581. onFilter: (value, record) => record.name.indexOf(value) > -1,
  582. },
  583. {
  584. title: 'Age',
  585. dataIndex: 'age',
  586. width: 150,
  587. sorter: (a, b) => (a.age - b.age > 0 ? 1 : -1),
  588. },
  589. {
  590. title: 'Address',
  591. dataIndex: 'address',
  592. },
  593. ];
  594. const demo = mount(<Table dataSource={data} columns={columns} pagination={false}/>);
  595. demo.find(`.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-table-column-filter`).simulate('click'); // click first filter
  596. demo.find(`.${BASE_CLASS_PREFIX}-dropdown .${BASE_CLASS_PREFIX}-dropdown-item`)
  597. .at(0)
  598. .find(`.${BASE_CLASS_PREFIX}-checkbox`)
  599. .simulate('click', {
  600. nativeEvent: null,
  601. });
  602. const nameColList = demo.find('.semi-table-tbody .name-col');
  603. const filteredData = data.filter(item => item.name.indexOf('1') > -1);
  604. expect(nameColList.length).toBe(filteredData.length); // update dataSource with exist filter
  605. const newData = getData(10);
  606. const newFilteredData = newData.filter(item => item.name.indexOf('1') > -1);
  607. demo.setProps({
  608. dataSource: newData,
  609. });
  610. demo.update();
  611. const newNameColList = demo.find('.semi-table-tbody .name-col');
  612. expect(newNameColList.length).toBe(newFilteredData.length);
  613. });
  614. it(`test controlled dataSource and columns`, async () => {
  615. let pagination = {
  616. currentPage: 1,
  617. total: data.length,
  618. pageSize: 10,
  619. };
  620. const getPageData = () =>
  621. data.slice(
  622. (pagination.currentPage - 1) * pagination.pageSize,
  623. pagination.currentPage * pagination.pageSize
  624. );
  625. let currentData = getPageData();
  626. let columns = [
  627. {
  628. title: 'Name',
  629. dataIndex: 'name',
  630. width: 150,
  631. filters: [
  632. {
  633. text: '名字包含"1"',
  634. value: '1',
  635. },
  636. {
  637. text: '名字包含"2"',
  638. value: '2',
  639. },
  640. ],
  641. onFilter: (value, record) => record.name.indexOf(value) > -1,
  642. },
  643. {
  644. title: 'Age',
  645. dataIndex: 'age',
  646. width: 150,
  647. sorter: true,
  648. },
  649. {
  650. title: 'Address',
  651. dataIndex: 'address',
  652. },
  653. {
  654. render: (text, record) => (
  655. <Tooltip content={record.description}>
  656. <Tag color="green">Show Info</Tag>
  657. </Tooltip>
  658. ),
  659. width: 150,
  660. },
  661. ];
  662. const onChange = sinon.spy(({pagination: tablePagination, filters: tableFilters, sorters: tableSorters}) => {
  663. if (tablePagination && tablePagination.currentPage !== pagination.currentPage) {
  664. pagination.currentPage = tablePagination.currentPage;
  665. currentData = getPageData();
  666. columns = [...columns];
  667. demo.setProps({
  668. dataSource: currentData,
  669. columns,
  670. pagination,
  671. });
  672. }
  673. });
  674. const demo = mount(
  675. <Table onChange={onChange} dataSource={currentData} pagination={pagination} columns={columns}/>
  676. );
  677. const table = demo.find(BaseTable);
  678. demo.find(`.${BASE_CLASS_PREFIX}-page .${BASE_CLASS_PREFIX}-page-item`)
  679. .at(2)
  680. .simulate('click', {
  681. nativeEvent: null,
  682. });
  683. expect(onChange.called).toBe(true);
  684. expect(
  685. demo
  686. .find(`.${BASE_CLASS_PREFIX}-page .${BASE_CLASS_PREFIX}-page-item`)
  687. .at(2)
  688. .hasClass(`${BASE_CLASS_PREFIX}-page-item-active`)
  689. ).toBe(true);
  690. });
  691. it(`test resizable table`, async () => {
  692. let columns = [
  693. {
  694. title: 'Name',
  695. dataIndex: 'name',
  696. width: 150,
  697. filters: [
  698. {
  699. text: '名字包含"1"',
  700. value: '1',
  701. },
  702. {
  703. text: '名字包含"2"',
  704. value: '2',
  705. },
  706. ],
  707. onFilter: (value, record) => record.name.indexOf(value) > -1,
  708. },
  709. {
  710. title: 'Age',
  711. dataIndex: 'age',
  712. width: 150,
  713. sorter: true,
  714. },
  715. {
  716. title: 'Address',
  717. dataIndex: 'address',
  718. width: 300,
  719. },
  720. {
  721. render: (text, record) => (
  722. <Tooltip content={record.description}>
  723. <Tag color="green">Show Info</Tag>
  724. </Tooltip>
  725. ),
  726. },
  727. ];
  728. const expandedRowRender = (record, index, expanded) => (
  729. <article
  730. style={{
  731. margin: 0,
  732. }}
  733. >
  734. <p>{record.description}</p>
  735. </article>
  736. );
  737. const demo = mount(
  738. <Table columns={columns} dataSource={data} resizable expandedRowRender={expandedRowRender}/>
  739. );
  740. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-thead .react-resizable-handle`).length).toBe(
  741. columns.reduce((count, col) => (typeof col.width === 'number' ? count + 1 : count), 0)
  742. );
  743. });
  744. it('test table sortOrder descend', async () => {
  745. const sortColumns = [
  746. {
  747. title: 'Name',
  748. dataIndex: 'name',
  749. sorter: (a, b) => a.name.length - b.name.length,
  750. sortOrder: 'descend',
  751. },
  752. {
  753. title: 'Age',
  754. dataIndex: 'age',
  755. },
  756. {
  757. title: 'Address',
  758. dataIndex: 'address',
  759. },
  760. ];
  761. const sortData = [
  762. {
  763. key: '1',
  764. name: 'John Brown',
  765. age: 32,
  766. address: 'New York No. 1 Lake Park',
  767. },
  768. {
  769. key: '2',
  770. name: 'Jim Green',
  771. age: 42,
  772. address: 'London No. 1 Lake Park',
  773. },
  774. {
  775. key: '3',
  776. name: 'Joe Black',
  777. age: 32,
  778. address: 'Sidney No. 1 Lake Park',
  779. },
  780. {
  781. key: '4',
  782. name: 'Jim Red',
  783. age: 32,
  784. address: 'London No. 2 Lake Park',
  785. },
  786. ];
  787. const targetData = sortData.reduce((a, b) => (a.name.length > b.name.length ? a : b));
  788. const {name} = targetData;
  789. const sortTable = mount(<Table columns={sortColumns} dataSource={sortData}/>);
  790. const firstCell = sortTable.find('.semi-table-tbody .semi-table-row .semi-table-row-cell').at(0); // console.log(sortTable.debug({ ignoreProps: true }));
  791. expect(firstCell.text()).toBe(name);
  792. });
  793. it('test table sortOrder ascend', async () => {
  794. const sortColumns = [
  795. {
  796. title: 'Name',
  797. dataIndex: 'name',
  798. sorter: (a, b) => a.name.length - b.name.length,
  799. sortOrder: 'ascend',
  800. },
  801. {
  802. title: 'Age',
  803. dataIndex: 'age',
  804. },
  805. {
  806. title: 'Address',
  807. dataIndex: 'address',
  808. },
  809. ];
  810. const sortData = [
  811. {
  812. key: '1',
  813. name: 'John Brown',
  814. age: 32,
  815. address: 'New York No. 1 Lake Park',
  816. },
  817. {
  818. key: '2',
  819. name: 'Jim Green',
  820. age: 42,
  821. address: 'London No. 1 Lake Park',
  822. },
  823. {
  824. key: '3',
  825. name: 'Joe Black',
  826. age: 32,
  827. address: 'Sidney No. 1 Lake Park',
  828. },
  829. {
  830. key: '4',
  831. name: 'Jim Red',
  832. age: 32,
  833. address: 'London No. 2 Lake Park',
  834. },
  835. ];
  836. const targetData = sortData.reduce((a, b) => (a.name.length < b.name.length ? a : b));
  837. const {name} = targetData;
  838. const sortTable = mount(<Table columns={sortColumns} dataSource={sortData}/>);
  839. const firstCell = sortTable.find('.semi-table-tbody .semi-table-row .semi-table-row-cell').at(0);
  840. expect(firstCell.text()).toBe(name);
  841. });
  842. it('test controlled sortOrder', async () => {
  843. const sortColumns = [
  844. {
  845. title: 'Name',
  846. dataIndex: 'name',
  847. sorter: (a, b) => a.name.length - b.name.length,
  848. sortOrder: 'descend',
  849. },
  850. {
  851. title: 'Age',
  852. dataIndex: 'age',
  853. },
  854. {
  855. title: 'Address',
  856. dataIndex: 'address',
  857. },
  858. ];
  859. const sortData = [
  860. {
  861. key: '1',
  862. name: 'long name',
  863. age: 32,
  864. address: 'New York No. 1 Lake Park',
  865. },
  866. {
  867. key: '2',
  868. name: 'longest name',
  869. age: 42,
  870. address: 'London No. 1 Lake Park',
  871. },
  872. {
  873. key: '3',
  874. name: 'longer name',
  875. age: 32,
  876. address: 'Sidney No. 1 Lake Park',
  877. },
  878. {
  879. key: '4',
  880. name: 'short',
  881. age: 32,
  882. address: 'London No. 2 Lake Park',
  883. },
  884. ];
  885. const targetData = sortData.reduce((a, b) => (a.name.length > b.name.length ? a : b));
  886. const {name} = targetData;
  887. const sortTable = mount(<Table columns={sortColumns} dataSource={sortData}/>);
  888. const firstCell = sortTable.find('.semi-table-tbody .semi-table-row .semi-table-row-cell').at(0);
  889. expect(firstCell.text()).toBe(name);
  890. const ascendOrderColumns = [
  891. {
  892. title: 'Name',
  893. dataIndex: 'name',
  894. sorter: (a, b) => a.name.length - b.name.length,
  895. sortOrder: 'ascend',
  896. },
  897. {
  898. title: 'Age',
  899. dataIndex: 'age',
  900. },
  901. {
  902. title: 'Address',
  903. dataIndex: 'address',
  904. },
  905. ]; // test sortOrder: ascend
  906. sortTable.setProps({
  907. columns: ascendOrderColumns,
  908. });
  909. sortTable.update();
  910. const ascendTargetData = sortData.reduce((a, b) => (a.name.length < b.name.length ? a : b));
  911. const {name: ascendTargetName} = ascendTargetData;
  912. const ascendFirstCell = sortTable.find('.semi-table-tbody .semi-table-row .semi-table-row-cell').at(0);
  913. expect(ascendFirstCell.text()).toBe(ascendTargetName); // test sortOrder: false, expect order as given data
  914. const defaultOrderColumns = [
  915. {
  916. title: 'Name',
  917. dataIndex: 'name',
  918. sorter: (a, b) => a.name.length - b.name.length,
  919. sortOrder: false,
  920. },
  921. {
  922. title: 'Age',
  923. dataIndex: 'age',
  924. },
  925. {
  926. title: 'Address',
  927. dataIndex: 'address',
  928. },
  929. ];
  930. sortTable.setProps({
  931. columns: defaultOrderColumns,
  932. });
  933. sortTable.update();
  934. const defaultTargetData = sortData[0];
  935. const {name: defaultTargetName} = defaultTargetData;
  936. const defaultFirstCell = sortTable.find('.semi-table-tbody .semi-table-row .semi-table-row-cell').at(0);
  937. expect(defaultFirstCell.text()).toBe(defaultTargetName);
  938. });
  939. it('test table select all when disabled all rows', async () => {
  940. const columns = [
  941. {
  942. title: 'Name',
  943. dataIndex: 'name',
  944. width: 150,
  945. },
  946. {
  947. title: 'Age',
  948. dataIndex: 'age',
  949. width: 150,
  950. },
  951. {
  952. title: 'Address',
  953. dataIndex: 'address',
  954. },
  955. ];
  956. const rowSelection = {
  957. onSelectAll: sinon.spy(() => {
  958. }),
  959. getCheckboxProps: sinon.spy(record => ({
  960. disabled: true,
  961. // disabled all
  962. name: record.name,
  963. })),
  964. };
  965. const demo = mount(<Table columns={columns} dataSource={data} rowSelection={rowSelection}/>);
  966. demo.find(
  967. `.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-table-column-selection .${BASE_CLASS_PREFIX}-checkbox`
  968. ).simulate('click'); // should select 0 rows
  969. expect(rowSelection.onSelectAll.getCall(0).args[1].length).toBe(0);
  970. });
  971. it('test jsx async data', async () => {
  972. const asyncData = [
  973. {
  974. key: '1',
  975. name: 'John Brown',
  976. age: 32,
  977. address: 'New York No. 1 Lake Park, New York No. 1 Lake Park',
  978. },
  979. {
  980. key: '2',
  981. name: 'Jim Green',
  982. age: 42,
  983. address: 'London No. 1 Lake Park',
  984. },
  985. {
  986. key: '3',
  987. name: 'Joe Black',
  988. age: 32,
  989. address: 'Sidney No. 1 Lake Park',
  990. },
  991. {
  992. key: '4',
  993. name: 'Michael James',
  994. age: 99,
  995. address: 'Sidney No. 1 Lake Park',
  996. },
  997. ];
  998. const demo = mount(
  999. <Table dataSource={[]}>
  1000. <Column title="Name" dataIndex="name" key="name" render={(text, record, index) => <a>{text}</a>}/>
  1001. <Column title="Age" dataIndex="age" key="age"/>
  1002. <Column title="Address" dataIndex="address" key="address"/>
  1003. </Table>
  1004. );
  1005. setTimeout(() => {
  1006. demo.setProps({
  1007. dataSource: asyncData,
  1008. });
  1009. }, 2000);
  1010. await sleep(3000);
  1011. const baseTable = demo.find(BaseTable);
  1012. expect(baseTable.state('cachedColumns').length).toEqual(3);
  1013. expect(baseTable.state('dataSource').length).toEqual(4);
  1014. });
  1015. it('test cell align', async () => {
  1016. const columns = getColumns();
  1017. const alignRightColumns = columns.map(column => {
  1018. column.align = 'right';
  1019. return column;
  1020. });
  1021. const demo = mount(<Table dataSource={data} columns={alignRightColumns}/>);
  1022. const titleAlignCells = demo.find(`.${BASE_CLASS_PREFIX}-table-align-right`);
  1023. expect(titleAlignCells.length).toBeGreaterThan(0);
  1024. const bodyAlignCells = document.querySelectorAll(`.${BASE_CLASS_PREFIX}-table-row-cell`);
  1025. bodyAlignCells.forEach(cell => {
  1026. expect(cell.style.textAlign).toEqual('right');
  1027. });
  1028. });
  1029. it('test column className', async () => {
  1030. const columns = getColumns();
  1031. const alignRightColumns = columns.map(column => {
  1032. column.className = 'test';
  1033. return column;
  1034. });
  1035. const demo = mount(<Table dataSource={data} columns={alignRightColumns}/>);
  1036. const titleAlignCells = demo.find(`.${BASE_CLASS_PREFIX}-table-row-head`);
  1037. const bodyAlignCells = demo.find(`.${BASE_CLASS_PREFIX}-table-row-cell`);
  1038. titleAlignCells.forEach(cell => {
  1039. expect(cell.hasClass('test')).toBeTruthy();
  1040. });
  1041. bodyAlignCells.forEach(cell => {
  1042. expect(cell.hasClass('test')).toBeTruthy();
  1043. });
  1044. });
  1045. it('test header appearance', async () => {
  1046. // object column
  1047. const columns = getColumns();
  1048. const demo = mount(
  1049. <Table
  1050. dataSource={data}
  1051. columns={columns}
  1052. scroll={{
  1053. y: 500,
  1054. }}
  1055. />
  1056. );
  1057. expect(demo.find('.semi-table-thead').length).toEqual(1);
  1058. demo.setProps({
  1059. showHeader: false,
  1060. });
  1061. expect(demo.find('.semi-table-thead').length).toEqual(0); // jsx column
  1062. const jsxColumns = getJSXColumns();
  1063. const demo1 = mount(<Table dataSource={data}>{jsxColumns}</Table>);
  1064. expect(demo1.find('.semi-table-thead').length).toEqual(1);
  1065. demo1.setProps({
  1066. showHeader: false,
  1067. });
  1068. expect(demo1.find('.semi-table-thead').length).toEqual(0);
  1069. });
  1070. it('test ref getCurrentPageData', async () => {
  1071. // object column
  1072. const pageSize = 10;
  1073. const refObj = {
  1074. current: null,
  1075. };
  1076. const columns = getColumns();
  1077. const demo = mount(
  1078. <Table
  1079. dataSource={data}
  1080. ref={refObj}
  1081. columns={columns}
  1082. pagination={{
  1083. pageSize,
  1084. }}
  1085. />
  1086. );
  1087. const {dataSource} = refObj.current.getCurrentPageData();
  1088. expect(dataSource.length).toEqual(pageSize); // jsx column
  1089. const jsxColumns = getJSXColumns();
  1090. const jsxRefObj = {
  1091. current: null,
  1092. };
  1093. const jsxDemo = mount(
  1094. <Table
  1095. dataSource={data}
  1096. ref={jsxRefObj}
  1097. pagination={{
  1098. pageSize,
  1099. }}
  1100. >
  1101. {jsxColumns}
  1102. </Table>
  1103. );
  1104. const {dataSource: jsxData} = jsxRefObj.current.getCurrentPageData();
  1105. expect(jsxData.length).toEqual(pageSize);
  1106. });
  1107. it('test render expandIcon', async () => {
  1108. const expandedRowRender = () => <div>Semi Design</div>;
  1109. const columns = getColumns();
  1110. const demo = mount(
  1111. <Table
  1112. dataSource={data}
  1113. columns={columns}
  1114. expandedRowRender={expandedRowRender}
  1115. expandIcon={<IconStar size="small"/>}
  1116. />
  1117. );
  1118. expect(demo.find('.semi-icon-star').length).toBeGreaterThan(0);
  1119. const demo2 = mount(
  1120. <Table
  1121. dataSource={data}
  1122. columns={columns}
  1123. expandedRowRender={expandedRowRender}
  1124. defaultExpandAllRows
  1125. expandIcon={expanded => <div>{expanded && <IconStar size="small"/>}</div>}
  1126. />
  1127. );
  1128. expect(demo2.find('.semi-icon-star').length).toBeGreaterThan(0);
  1129. });
  1130. it(`test onRow/onCell`, async () => {
  1131. const onRowClick = sinon.spy(() => {
  1132. });
  1133. const onHeaderRowClick = sinon.spy(() => {
  1134. });
  1135. const onCellClick = sinon.spy(() => {
  1136. });
  1137. const onHeaderCellClick = sinon.spy(() => {
  1138. });
  1139. const onRow = sinon.spy((record, index) => ({
  1140. className: 'test-row',
  1141. onClick: onRowClick,
  1142. }));
  1143. const onHeaderRow = sinon.spy((record, index) => ({
  1144. className: 'test-row',
  1145. onClick: onHeaderRowClick,
  1146. }));
  1147. const columns = getColumns();
  1148. const onCellColumns = columns.map((column, index) => {
  1149. const style =
  1150. index === 0
  1151. ? {
  1152. width: 200,
  1153. height: 60,
  1154. }
  1155. : {};
  1156. column.onCell = () => ({
  1157. onClick: onCellClick,
  1158. onCellClick,
  1159. style,
  1160. });
  1161. column.onHeaderCell = () => ({
  1162. onClick: onHeaderCellClick,
  1163. style,
  1164. });
  1165. return column;
  1166. });
  1167. const demo = mount(<Table dataSource={data} onRow={onRow} onHeaderRow={onHeaderRow} columns={onCellColumns}/>);
  1168. const tableCells = demo.find('.semi-table-body .semi-table-row-cell');
  1169. const tableHeaderCells = demo.find('.semi-table-thead .semi-table-row-head'); // cell style
  1170. expect(tableCells.at(0).instance().style.width).toEqual('200px');
  1171. expect(tableCells.at(0).instance().style.height).toEqual('60px');
  1172. expect(tableHeaderCells.at(0).instance().style.width).toEqual('200px');
  1173. expect(tableHeaderCells.at(0).instance().style.height).toEqual('60px'); // body click
  1174. tableCells.at(0).simulate('click');
  1175. expect(onCellClick.called).toBeTruthy();
  1176. const tableRows = demo.find('.semi-table-body .semi-table-row');
  1177. tableRows.at(0).simulate('click');
  1178. expect(onRowClick.called).toBeTruthy(); // header click
  1179. tableHeaderCells.at(0).simulate('click');
  1180. expect(onHeaderCellClick.called).toBeTruthy();
  1181. const tableHeaderRows = demo.find('.semi-table-thead .semi-table-row');
  1182. tableHeaderRows.at(0).simulate('click');
  1183. expect(onHeaderRowClick.called).toBeTruthy();
  1184. });
  1185. it('test header merge', async () => {
  1186. // 测试头部合并
  1187. function testHeaderMerge(demo, params) {
  1188. const rows = demo.find('.semi-table-thead .semi-table-row');
  1189. expect(rows.length).toEqual(2);
  1190. const firstRow = rows.at(0);
  1191. const secondRow = rows.at(1);
  1192. expect(firstRow.childAt(0).instance().colSpan).toEqual(2);
  1193. expect(firstRow.childAt(1).instance().colSpan).toEqual(2);
  1194. expect(firstRow.childAt(2).instance().colSpan).toEqual(1);
  1195. expect(firstRow.childAt(2).instance().rowSpan).toEqual(2);
  1196. expect(secondRow.childAt(0).instance().colSpan).toEqual(1);
  1197. expect(secondRow.childAt(1).instance().colSpan).toEqual(1);
  1198. expect(secondRow.childAt(2).instance().colSpan).toEqual(1);
  1199. expect(secondRow.childAt(3).instance().colSpan).toEqual(1);
  1200. }
  1201. const nestData = getNestData();
  1202. const filters = [
  1203. {
  1204. text: 'Code 45',
  1205. value: '45',
  1206. },
  1207. {
  1208. text: 'King 4',
  1209. value: 'King 4',
  1210. },
  1211. ];
  1212. const jsxDemo = mount(
  1213. <Table dataSource={nestData}>
  1214. <Column title={'Base Information'} dataIndex={'base'} fixed="left">
  1215. <Column
  1216. title={'Name'}
  1217. dataIndex={'name'}
  1218. fixed="left"
  1219. width={200}
  1220. filters={filters}
  1221. onFilter={(value, record) => record.name.includes(value)}
  1222. />
  1223. <Column
  1224. title={'Age'}
  1225. dataIndex={'age'}
  1226. width={100}
  1227. fixed="left"
  1228. sorter={(a, b) => (a.age - b.age > 0 ? 1 : -1)}
  1229. />
  1230. </Column>
  1231. <Column title={'Company Information'} dataIndex={'company'}>
  1232. <Column title={'Company Name'} dataIndex={'company.name'}/>
  1233. <Column title={'Company Address'} dataIndex={'company.address'}/>
  1234. </Column>
  1235. <Column title={'Address'} dataIndex={'address'} width={250} fixed="right"/>
  1236. </Table>
  1237. );
  1238. const columns = getNestColumns();
  1239. const demo = mount(<Table dataSource={nestData} columns={columns}/>);
  1240. testHeaderMerge(jsxDemo);
  1241. testHeaderMerge(demo);
  1242. });
  1243. it('test without columns', async () => {
  1244. const jsxDemo = mount(<Table dataSource={data}></Table>);
  1245. const demo = mount(<Table dataSource={data} columns={[]}/>);
  1246. expect(jsxDemo.find('.semi-table-row-head').length).toBe(0);
  1247. expect(jsxDemo.find('.semi-table-row-cell').length).toBe(0);
  1248. expect(demo.find('.semi-table-row-head').length).toBe(0);
  1249. expect(demo.find('.semi-table-row-cell').length).toBe(0);
  1250. });
  1251. it('test useFullRender', async () => {
  1252. const columns = [
  1253. {
  1254. dataIndex: 'name',
  1255. width: 250,
  1256. filters: [
  1257. {
  1258. text: '名字包含"1"',
  1259. value: '1',
  1260. },
  1261. {
  1262. text: '名字包含"2"',
  1263. value: '2',
  1264. },
  1265. ],
  1266. onFilter: (value, record) => record.name.indexOf(value) > -1,
  1267. sorter: (a, b) => a.name.length - b.name.length,
  1268. // 此处将useFullRender设置为true开启完全自定义渲染
  1269. useFullRender: true,
  1270. // 此处从render的第四个形参中解构出 展开按钮、选择按钮、文本等内容
  1271. render: (text, record, index, {expandIcon, selection, indentText}) => {
  1272. return (
  1273. <span
  1274. className="custom-render"
  1275. style={{
  1276. display: 'inline-flex',
  1277. alignItems: 'center',
  1278. justifyContent: 'center',
  1279. }}
  1280. >
  1281. {indentText}
  1282. {expandIcon}
  1283. {selection}
  1284. <span
  1285. style={{
  1286. marginLeft: 8,
  1287. }}
  1288. >
  1289. {text}
  1290. </span>
  1291. </span>
  1292. );
  1293. },
  1294. title: ({sorter, filter, selection}) => (
  1295. <span
  1296. className="custom-title"
  1297. style={{
  1298. display: 'inline-flex',
  1299. alignItems: 'center',
  1300. paddingLeft: 20,
  1301. }}
  1302. >
  1303. {selection}
  1304. <span
  1305. style={{
  1306. marginLeft: 8,
  1307. }}
  1308. >
  1309. Name
  1310. </span>
  1311. {sorter}
  1312. {filter}
  1313. </span>
  1314. ),
  1315. },
  1316. {
  1317. title: 'Age',
  1318. dataIndex: 'age',
  1319. },
  1320. {
  1321. title: 'Address',
  1322. dataIndex: 'address',
  1323. },
  1324. ];
  1325. const rowSelection = {
  1326. hidden: true,
  1327. fixed: 'left',
  1328. };
  1329. const demo = mount(
  1330. <Table
  1331. rowSelection={rowSelection}
  1332. columns={columns}
  1333. dataSource={data}
  1334. expandedRowRender={record => <article>{record.description}</article>}
  1335. />
  1336. );
  1337. const node = demo.find('.custom-render').at(0);
  1338. expect(node.children().length).toEqual(3);
  1339. expect(node.childAt(0).exists('.semi-table-expand-icon')).toBeTruthy();
  1340. expect(node.childAt(1).exists('.semi-table-selection-wrap')).toBeTruthy();
  1341. const title = demo.find('.custom-title').at(0);
  1342. expect(title.children().length).toEqual(4);
  1343. expect(title.childAt(0).exists('.semi-table-selection-wrap')).toBeTruthy();
  1344. expect(title.childAt(1).text()).toEqual('Name');
  1345. expect(title.childAt(2).exists('.semi-table-column-sorter')).toBeTruthy();
  1346. expect(title.childAt(3).exists('.semi-table-column-filter')).toBeTruthy();
  1347. });
  1348. it('test defaultExpandedRowKeys changed', async () => {
  1349. const expandedRowRender = (record, index) => <div>{`Semi Design ${index}`}</div>;
  1350. const pageSize = 20;
  1351. const defaultExpandedRowKeys = Array.from({
  1352. length: getRandomNumber(pageSize),
  1353. }).map((_, i) => String(i));
  1354. const newDefaultExpandedRowKeys = Array.from({
  1355. length: getRandomNumber(pageSize),
  1356. }).map((_, i) => String(i));
  1357. const columns = getColumns();
  1358. const demo = mount(
  1359. <Table
  1360. dataSource={data}
  1361. columns={columns}
  1362. expandedRowRender={expandedRowRender}
  1363. defaultExpandedRowKeys={defaultExpandedRowKeys}
  1364. pagination={{
  1365. pageSize,
  1366. }}
  1367. />
  1368. );
  1369. expect(demo.find(BaseTable).state('expandedRowKeys').length).toEqual(defaultExpandedRowKeys.length);
  1370. demo.setProps({
  1371. defaultExpandedRowKeys: newDefaultExpandedRowKeys,
  1372. });
  1373. // 2.x defaultExpandedRowKeys 不再响应变化
  1374. expect(demo.find(BaseTable).state('expandedRowKeys').length).toEqual(defaultExpandedRowKeys.length);
  1375. });
  1376. it('test getCheckboxProps changed', async () => {
  1377. const defaultGetCheckboxProps = record => ({
  1378. disabled: record.key === '1',
  1379. });
  1380. const newGetCheckboxProps = record => ({
  1381. disabled: ['0', '1'].includes(record.key),
  1382. });
  1383. const columns = getColumns();
  1384. const demo = mount(
  1385. <Table
  1386. dataSource={getData(20)}
  1387. columns={columns}
  1388. pagination={false}
  1389. rowSelection={{
  1390. getCheckboxProps: defaultGetCheckboxProps,
  1391. }}
  1392. />
  1393. );
  1394. expect(demo.find(BaseTable).state('disabledRowKeys').length).toEqual(1);
  1395. demo.setProps({
  1396. rowSelection: {
  1397. getCheckboxProps: newGetCheckboxProps,
  1398. },
  1399. });
  1400. expect(demo.find(BaseTable).state('disabledRowKeys').length).toEqual(2);
  1401. });
  1402. it('test pagination changed', async () => {
  1403. const total = 100;
  1404. const pagination = {
  1405. pageSize: 10,
  1406. currentPage: 2,
  1407. };
  1408. const newPagination = {
  1409. pageSize: 5,
  1410. currentPage: 1,
  1411. };
  1412. const columns = getColumns();
  1413. const demo = mount(<Table dataSource={getData(total)} columns={columns} pagination={pagination}/>);
  1414. const paginationProps = demo.find(BaseTable).state('pagination');
  1415. expect(paginationProps.total).toEqual(total);
  1416. expect(paginationProps.pageSize).toEqual(pagination.pageSize);
  1417. expect(paginationProps.currentPage).toEqual(pagination.currentPage);
  1418. demo.setProps({
  1419. pagination: newPagination,
  1420. });
  1421. await sleep(2000);
  1422. const newPaginationProps = demo.find(BaseTable).state('pagination');
  1423. expect(newPaginationProps.pageSize).toEqual(newPagination.pageSize);
  1424. expect(newPaginationProps.currentPage).toEqual(newPagination.currentPage);
  1425. });
  1426. it(`test grouped data change dataSource`, async () => {
  1427. const data = getGroupData();
  1428. const columns = getGroupColumns();
  1429. const groupedRowClick = sinon.spy();
  1430. const rowKey = record =>
  1431. `${record.city && record.city.toLowerCase()}-${record.job && record.job.toLowerCase()}`;
  1432. const demo = mount(
  1433. <Table
  1434. dataSource={data}
  1435. rowKey={rowKey}
  1436. groupBy={'city'}
  1437. columns={columns}
  1438. renderGroupSection={groupKey => <strong>Jobs in {groupKey}:</strong>}
  1439. onGroupedRow={(group, index) => ({
  1440. onClick: groupedRowClick,
  1441. })}
  1442. clickGroupedRowToExpand
  1443. scroll={{
  1444. y: 480,
  1445. }}
  1446. />
  1447. );
  1448. const newData = [
  1449. {
  1450. city: 'Tianjin',
  1451. job: 'FE',
  1452. department: 'IES',
  1453. },
  1454. {
  1455. city: 'Tianjin',
  1456. job: 'Android',
  1457. department: 'IES',
  1458. },
  1459. {
  1460. city: 'Wuhan',
  1461. job: 'Android',
  1462. department: 'IES',
  1463. },
  1464. {
  1465. city: 'Wuhan',
  1466. job: 'SE',
  1467. department: 'EE',
  1468. },
  1469. {
  1470. city: 'Chengdu',
  1471. job: 'Android',
  1472. department: 'EE',
  1473. },
  1474. {
  1475. city: 'Chengdu',
  1476. job: 'IOS',
  1477. department: 'EE',
  1478. },
  1479. {
  1480. city: 'Xiamen',
  1481. job: 'SE',
  1482. department: 'DATA',
  1483. },
  1484. {
  1485. city: 'Xiamen',
  1486. job: 'IOS',
  1487. department: 'DATA',
  1488. },
  1489. ];
  1490. demo.setProps({
  1491. dataSource: newData,
  1492. });
  1493. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-row-section`).length).toBe(4);
  1494. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-body .${BASE_CLASS_PREFIX}-table-row`).length).toBe(0);
  1495. demo.find(`.${BASE_CLASS_PREFIX}-table-row-section`)
  1496. .at(0)
  1497. .simulate('click');
  1498. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-row`).length).toBeGreaterThan(0);
  1499. });
  1500. it(`test given object columns and children`, async () => {
  1501. const demo = mount(
  1502. <Table dataSource={data} columns={columns}>
  1503. <Table.Column title="Age" dataIndex="age" key="age"/>
  1504. </Table>
  1505. );
  1506. const test = demo.find(BaseTable); // 同时传columns与children时,columns优先
  1507. expect(test.state('cachedColumns')).toEqual(columns);
  1508. expect(test.state('queries').length).toEqual(columns.length);
  1509. });
  1510. it('test header colSpan', async () => {
  1511. const columns = [
  1512. {
  1513. title: 'Name',
  1514. dataIndex: 'name',
  1515. },
  1516. {
  1517. title: 'Age',
  1518. dataIndex: 'age',
  1519. },
  1520. {
  1521. title: 'Home phone',
  1522. colSpan: 2,
  1523. dataIndex: 'tel',
  1524. },
  1525. {
  1526. title: 'Phone',
  1527. colSpan: 0,
  1528. dataIndex: 'phone',
  1529. },
  1530. {
  1531. title: 'Address',
  1532. dataIndex: 'address',
  1533. },
  1534. ];
  1535. const data = [
  1536. {
  1537. key: '1',
  1538. name: 'ZhangSan',
  1539. age: 50,
  1540. tel: '010-20000000',
  1541. phone: 10010,
  1542. address: 'BeiJing No.1 High School',
  1543. },
  1544. {
  1545. key: '2',
  1546. name: 'LiSi',
  1547. tel: '010-30000000',
  1548. phone: 10086,
  1549. age: 40,
  1550. address: 'ShangHai No. 1 High School',
  1551. },
  1552. {
  1553. key: '3',
  1554. name: 'WangWu',
  1555. age: 60,
  1556. tel: '010-40000000',
  1557. phone: 10011,
  1558. address: 'NaiJing No.1 High School',
  1559. },
  1560. {
  1561. key: '4',
  1562. name: 'XiaoMing',
  1563. age: 20,
  1564. tel: '010-50000000',
  1565. phone: 12580,
  1566. address: 'ShiJiaZhuang No.1 High School',
  1567. },
  1568. {
  1569. key: '5',
  1570. name: 'XiaoHong',
  1571. age: 40,
  1572. tel: '010-60000000',
  1573. phone: 12530,
  1574. address: 'TaiBei No.2 High School',
  1575. },
  1576. ];
  1577. const demo = mount(<Table dataSource={data} columns={columns}/>);
  1578. expect(demo.find('.semi-table-row .semi-table-row-head').length).toBe(columns.length - 1);
  1579. });
  1580. it('test expandAllRows', async () => {
  1581. const expandedRowRender = () => <div>Semi Design</div>
  1582. const initData = [];
  1583. const columns = getColumns();
  1584. const demo = mount(<Table
  1585. dataSource={initData}
  1586. columns={columns}
  1587. expandedRowRender={expandedRowRender}
  1588. pagination={false}
  1589. expandAllRows
  1590. />);
  1591. const newData = getData(20);
  1592. demo.setProps({dataSource: newData});
  1593. demo.update();
  1594. const expandedRows = demo.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row-expanded`)
  1595. expect(expandedRows.length).toEqual(newData.length);
  1596. // 动态切换 expandAllRows
  1597. demo.setProps({expandAllRows: false});
  1598. demo.update();
  1599. const newExpandedRows = demo.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row-expanded`)
  1600. expect(newExpandedRows.length).toEqual(0);
  1601. });
  1602. it(`test defaultExpandAllGroupRows`, async () => {
  1603. const data = getGroupData();
  1604. const columns = getGroupColumns();
  1605. const rowKey = record => `${record.city && record.city.toLowerCase()}-${record.job && record.job.toLowerCase()}`;
  1606. const groupSize = new Set(data.map(item => item.city)).size;
  1607. const demo = mount(
  1608. <Table
  1609. dataSource={data}
  1610. rowKey={rowKey}
  1611. groupBy={'city'}
  1612. columns={columns}
  1613. renderGroupSection={groupKey => <strong>Jobs in {groupKey}:</strong>}
  1614. scroll={{y: 480}}
  1615. defaultExpandAllGroupRows
  1616. />
  1617. );
  1618. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row-section.on`).length).toBe(groupSize);
  1619. });
  1620. it(`test expandAllGroupRows`, async () => {
  1621. const data = getGroupData();
  1622. const groupSize = new Set(data.map(item => item.city)).size;
  1623. const columns = getGroupColumns();
  1624. const rowKey = record => `${record.city && record.city.toLowerCase()}-${record.job && record.job.toLowerCase()}`;
  1625. const demo = mount(
  1626. <Table
  1627. dataSource={[]}
  1628. rowKey={rowKey}
  1629. groupBy={'city'}
  1630. columns={columns}
  1631. renderGroupSection={groupKey => <strong>Jobs in {groupKey}:</strong>}
  1632. scroll={{y: 480}}
  1633. expandAllGroupRows={true}
  1634. />
  1635. );
  1636. demo.setProps({dataSource: data});
  1637. demo.update();
  1638. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row-section.on`).length).toBe(groupSize);
  1639. demo.setProps({expandAllGroupRows: false});
  1640. demo.update();
  1641. expect(demo.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row-section.on`).length).toBe(0);
  1642. });
  1643. it('test defaultSortOrder', async () => {
  1644. const sortColumns = [
  1645. {
  1646. title: 'Name',
  1647. dataIndex: 'name',
  1648. sorter: (a, b) => a.name.length - b.name.length,
  1649. defaultSortOrder: 'descend',
  1650. },
  1651. {
  1652. title: 'Age',
  1653. dataIndex: 'age',
  1654. },
  1655. {
  1656. title: 'Address',
  1657. dataIndex: 'address',
  1658. }
  1659. ];
  1660. const sortData = [
  1661. {
  1662. key: '1',
  1663. name: 'long name',
  1664. age: 32,
  1665. address: 'New York No. 1 Lake Park',
  1666. },
  1667. {
  1668. key: '2',
  1669. name: 'longest name',
  1670. age: 42,
  1671. address: 'London No. 1 Lake Park',
  1672. },
  1673. {
  1674. key: '3',
  1675. name: 'longer name',
  1676. age: 32,
  1677. address: 'Sidney No. 1 Lake Park',
  1678. },
  1679. {
  1680. key: '4',
  1681. name: 'short',
  1682. age: 32,
  1683. address: 'London No. 2 Lake Park',
  1684. },
  1685. ];
  1686. const onChange = sinon.spy(() => {
  1687. });
  1688. // test default descend
  1689. const targetData = sortData.reduce((a, b) => a.name.length > b.name.length ? a : b);
  1690. const {name} = targetData;
  1691. const sortTable = mount(<Table columns={sortColumns} dataSource={sortData} onChange={onChange}/>);
  1692. const firstCell = sortTable.find('.semi-table-tbody .semi-table-row .semi-table-row-cell').at(0);
  1693. expect(firstCell.text()).toBe(name);
  1694. // test default ascend
  1695. const ascendOrderColumns = [
  1696. {
  1697. title: 'Name',
  1698. dataIndex: 'name',
  1699. sorter: (a, b) => a.name.length - b.name.length,
  1700. defaultSortOrder: 'ascend',
  1701. },
  1702. {
  1703. title: 'Age',
  1704. dataIndex: 'age',
  1705. },
  1706. {
  1707. title: 'Address',
  1708. dataIndex: 'address',
  1709. }
  1710. ];
  1711. sortTable.setProps({columns: ascendOrderColumns})
  1712. sortTable.update()
  1713. const ascendTargetData = sortData.reduce((a, b) => a.name.length < b.name.length ? a : b);
  1714. const {name: ascendTargetName} = ascendTargetData;
  1715. const ascendFirstCell = sortTable.find('.semi-table-tbody .semi-table-row .semi-table-row-cell').at(0);
  1716. expect(ascendFirstCell.text()).toBe(ascendTargetName);
  1717. // test default false
  1718. const defaultOrderColumns = [
  1719. {
  1720. title: 'Name',
  1721. dataIndex: 'name',
  1722. sorter: (a, b) => a.name.length - b.name.length,
  1723. defaultSortOrder: false,
  1724. },
  1725. {
  1726. title: 'Age',
  1727. dataIndex: 'age',
  1728. },
  1729. {
  1730. title: 'Address',
  1731. dataIndex: 'address',
  1732. }
  1733. ]
  1734. sortTable.setProps({columns: defaultOrderColumns})
  1735. sortTable.update()
  1736. const defaultTargetData = sortData[0]
  1737. const {name: defaultTargetName} = defaultTargetData;
  1738. const defaultFirstCell = sortTable.find('.semi-table-tbody .semi-table-row .semi-table-row-cell').at(0);
  1739. expect(defaultFirstCell.text()).toBe(defaultTargetName);
  1740. // test click sorter
  1741. sortTable.find(`.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-table-column-sorter`).at(0).simulate('click', {nativeEvent: null});
  1742. expect(onChange.callCount).toBe(1);
  1743. expect(onChange.getCall(0).args[0].sorter.sortOrder).toBe('ascend');
  1744. sortTable.find(`.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-table-column-sorter`).at(0).simulate('click', {nativeEvent: null});
  1745. expect(onChange.callCount).toBe(2);
  1746. expect(onChange.getCall(1).args[0].sorter.sortOrder).toBe('descend');
  1747. // test change data
  1748. const newData = [
  1749. {
  1750. key: '1',
  1751. name: 'longest name',
  1752. age: 18,
  1753. address: 'New York No. 1 Lake Park',
  1754. },
  1755. {
  1756. key: '2',
  1757. name: 'long name',
  1758. age: 20,
  1759. address: 'London No. 1 Lake Park',
  1760. },
  1761. {
  1762. key: '3',
  1763. name: 'longer name',
  1764. age: 16,
  1765. address: 'Sidney No. 1 Lake Park',
  1766. },
  1767. {
  1768. key: '4',
  1769. name: 'short',
  1770. age: 33,
  1771. address: 'London No. 2 Lake Park',
  1772. },
  1773. ];
  1774. sortTable.setProps({dataSource: newData});
  1775. sortTable.update()
  1776. const newDescendTargetData = newData.reduce((a, b) => a.name.length > b.name.length ? a : b);
  1777. const {name: newDescendTargetName} = newDescendTargetData;
  1778. const newDataFirstCell = sortTable.find('.semi-table-tbody .semi-table-row .semi-table-row-cell').at(0);
  1779. expect(newDataFirstCell.text()).toBe(newDescendTargetName);
  1780. });
  1781. it(`test expandRowByClick`, async () => {
  1782. const onExpand = sinon.spy();
  1783. const onExpandedRowsChange = sinon.spy();
  1784. const demo = mount(
  1785. <Table
  1786. columns={columns}
  1787. dataSource={data}
  1788. onExpand={onExpand}
  1789. onExpandedRowsChange={onExpandedRowsChange}
  1790. expandedRowRender={() => <div>Semi Design</div>}
  1791. expandRowByClick
  1792. />
  1793. );
  1794. const table = demo.find(BaseTable);
  1795. const rows = demo.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row`);
  1796. rows.at(0).simulate('click');
  1797. rows.at(1).simulate('click');
  1798. expect(onExpand.calledTwice).toBeTruthy();
  1799. expect(onExpandedRowsChange.calledTwice).toBeTruthy();
  1800. expect(onExpand.getCall(1).args[0]).toEqual(true);
  1801. expect(onExpand.getCall(1).args[1]).toEqual(data[1]);
  1802. expect(onExpand.getCall(1).args[2].constructor.name).toBe('SyntheticEvent');
  1803. expect(onExpandedRowsChange.getCall(1).args[0].length).toEqual(2);
  1804. expect(table.state(`expandedRowKeys`)).toEqual(['0', '1']);
  1805. const expandedRows = demo.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row-expanded`);
  1806. expandedRows.at(0).simulate('click');
  1807. // 查看点击第二次是否折叠
  1808. const newExpandedRows = demo.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row-expanded`)
  1809. expect(newExpandedRows.length).toEqual(1);
  1810. expect(table.state(`expandedRowKeys`)).toEqual(['1']);
  1811. });
  1812. });