UNPKG

qt-public-ui

Version:

新设计规范下业务组件库

263 lines (259 loc) 8.58 kB
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import React from 'react'; import { mount } from 'enzyme'; import { BrowserRouter } from 'react-router-dom'; import IndexCard from '../'; import { sleep } from '../../../../../test/utils'; var tipProps = { config: [{ text: '指标1是balalalala' }] }; var data = [{ tips: tipProps, value: 12432131, title: '新增用户新', ratios: [{ label: '同比', value: 0, hint: 'This is hint!' }, { label: '同比', value: 0, hint: 'This is hint!' }] }, { tips: tipProps, value: 1243, title: '新增用户新增用户新增用户新增用户', ratios: [{ label: '同比', value: '--', hint: 'This is hint!' }, { label: '同比', value: 0, hint: 'This is hint!' }] }]; var data1 = [{ tips: tipProps, value: 12432131, title: '新增用户新', ratios: [{ label: '同比', value: 12.8, hint: 'This is hint!' }, { label: '占比', render: /*#__PURE__*/React.createElement(React.Fragment, null, "\u81EA\u5B9A\u4E49\u6E32\u67D3"), hint: 'This is hint!' }] }]; var data2 = [{ tips: tipProps, value: 12432131, title: '新增用户新', links: [{ label: '点击跳转', url: '/' }], ratios: [{ label: '同比', value: 1322.8, valueType: 'number' }] }, { tips: tipProps, value: 1243, title: '新增用户新增用户新增用户新增用户', ratios: [{ label: '同比', value: -12.8 }, { label: '占比', render: function render() { return null; }, hint: 'This is hint!' }] }]; var data3 = [{ tips: tipProps, title: '新增用户新' }]; var data4 = [{ tips: tipProps, value: 12432131, title: '新增用户新', ratios: [{ label: '同比', value: 12.8 }, { label: '同比', value: 0, hint: 'This is hint!' }] }, { desc: '新增用户新增用户新增用户新增用户新增用户新增用户新增用户新增用户新增用户新增用户新增用户新增用户', button: { children: '点我点我点我', type: 'primary' } }]; describe('DynamicList', function () { it('Select active', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { var wrapper; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: wrapper = mount( /*#__PURE__*/React.createElement(BrowserRouter, null, /*#__PURE__*/React.createElement(IndexCard.Group, { onChange: console.log }, /*#__PURE__*/React.createElement(IndexCard, { data: data, id: "2121", type: "pairs" }), /*#__PURE__*/React.createElement(IndexCard, { data: data2, id: "2120", type: "pairs" }), /*#__PURE__*/React.createElement(IndexCard, { data: data4, id: "2125", type: "pairs" })))); wrapper.find('.umui-index-card').at(1).simulate('click'); _context.next = 4; return sleep(1); case 4: wrapper.update(); expect(wrapper.find('.umui-index-card').at(1).hasClass('umui-active')).toBe(true); // 切换 wrapper.find('.umui-index-card').at(0).simulate('click'); _context.next = 9; return sleep(1); case 9: wrapper.update(); expect(wrapper.find('.umui-index-card').at(1).hasClass('umui-active')).toBe(false); expect(wrapper.find('.umui-index-card').at(0).hasClass('umui-active')).toBe(true); case 12: case "end": return _context.stop(); } }, _callee); }))); it('Multiple select active ', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { var wrapper; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: wrapper = mount( /*#__PURE__*/React.createElement(BrowserRouter, null, /*#__PURE__*/React.createElement(IndexCard.Group, { onChange: console.log, multiSelect: true, max: 3, min: 1 }, /*#__PURE__*/React.createElement(IndexCard, { data: data1, id: "2121" }), /*#__PURE__*/React.createElement(IndexCard, { data: data1, id: "2120" }), /*#__PURE__*/React.createElement(IndexCard, { data: data1, id: "2122" }), /*#__PURE__*/React.createElement(IndexCard, { data: data1, id: "2123" }), /*#__PURE__*/React.createElement(IndexCard, { data: data1, id: "2124" }), /*#__PURE__*/React.createElement(IndexCard, { data: data1, id: "2125" })))); // 一开始是false expect(wrapper.find('.umui-index-card').at(1).hasClass('umui-active')).toBe(false); // 点击后active wrapper.find('.umui-index-card').at(1).simulate('click'); _context2.next = 5; return sleep(1); case 5: wrapper.update(); expect(wrapper.find('.umui-index-card').at(1).hasClass('umui-active')).toBe(true); // 再次点击 测试min是否生效 wrapper.find('.umui-index-card').at(1).simulate('click'); _context2.next = 10; return sleep(1); case 10: wrapper.update(); expect(wrapper.find('.umui-index-card').at(1).hasClass('umui-active')).toBe(true); wrapper.find('.umui-index-card').at(2).simulate('click'); wrapper.find('.umui-index-card').at(3).simulate('click'); wrapper.find('.umui-index-card').at(4).simulate('click'); _context2.next = 17; return sleep(1); case 17: wrapper.update(); expect(wrapper.find('.umui-index-card').at(2).hasClass('umui-active')).toBe(true); expect(wrapper.find('.umui-index-card').at(3).hasClass('umui-active')).toBe(true); expect(wrapper.find('.umui-index-card').at(4).hasClass('umui-active')).toBe(false); // 测试max // 测试取消选中 wrapper.find('.umui-index-card').at(1).simulate('click'); _context2.next = 24; return sleep(1); case 24: wrapper.update(); expect(wrapper.find('.umui-index-card').at(1).hasClass('umui-active')).toBe(false); case 26: case "end": return _context2.stop(); } }, _callee2); }))); it('IndexCard.Add Icon', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() { var wrapper; return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: // index-add-icon wrapper = mount( /*#__PURE__*/React.createElement(IndexCard.Add, { text: "\u70B9\u51FB\u6DFB\u52A0", type: "pairs" })); console.log('cc', wrapper.find('.index-add-icon').find('svg').children().html()); expect(wrapper.find('.index-add-icon').find('svg').children().html()).toEqual('<use xlink:href="#umicon-plus"></use>'); wrapper.setProps({ icon: 'umicon-play' }); expect(wrapper.find('.index-add-icon').find('svg').children().html()).toEqual('<use xlink:href="#umicon-play"></use>'); case 5: case "end": return _context3.stop(); } }, _callee3); }))); it('IndexCard.Add onClick', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() { var fn, wrapper; return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: // index-add-icon fn = jest.fn(); wrapper = mount( /*#__PURE__*/React.createElement(IndexCard.Add, { onClick: fn, text: "\u70B9\u51FB\u6DFB\u52A0", type: "pairs" })); wrapper.find('.index-add').simulate('click'); _context4.next = 5; return sleep(1); case 5: wrapper.update(); expect(fn).toHaveBeenCalled(); case 7: case "end": return _context4.stop(); } }, _callee4); }))); });