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