qt-public-ui
Version:
新设计规范下业务组件库
86 lines • 2.74 kB
JavaScript
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import React from 'react';
import { mount } from 'enzyme';
import { act } from 'react-dom/test-utils';
import StepBar from '../index';
var stepBarContent = [{
key: 'step1',
icon: 'ant-like',
tips: 'step1-bababababablalalallalallallaa...',
title: '获客'
}, {
key: 'step2',
icon: 'ant-like',
tips: 'step2-bababababablalalallalallallaa...',
title: '激活'
}, {
key: 'step3',
icon: 'ant-like',
tips: 'step3-bababababablalalallalallallaa...',
title: '分享'
}, {
key: 'step4',
icon: 'ant-like',
tips: 'step4-bababababablalalallalallallaa...',
title: '转化',
disabled: true
}, {
key: 'step5',
icon: 'ant-like',
tips: 'step-5bababababablalalallalallallaa...',
title: '运营',
disabled: true
}];
describe('StepBar', function () {
function showPopover(wrapper, index) {
act(function () {
wrapper.find('.umui-step-bar-item').at(index).children().simulate('mouseenter');
jest.runAllTimers();
});
wrapper.update();
}
beforeEach(function () {
jest.useFakeTimers();
});
afterEach(function () {
jest.useRealTimers();
});
it('Show tips when hovering', /*#__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(StepBar, {
content: stepBarContent,
onClick: console.log
}));
showPopover(wrapper, 2);
expect(wrapper.find('.ant-tooltip-inner').text()).toBe('step3-bababababablalalallalallallaa...');
case 3:
case "end":
return _context.stop();
}
}, _callee);
})));
it('Click event is ok', function () {
var fn = jest.fn();
var wrapper = mount( /*#__PURE__*/React.createElement(StepBar, {
content: stepBarContent,
onClick: fn
}));
wrapper.find('.umui-step-bar-item').at(2).children().simulate('click');
expect(wrapper.find('.umui-step-bar-item').at(2).hasClass('umui-step-bar-active')).toBe(true);
expect(fn).toHaveBeenCalled();
});
it('Disable is ok', function () {
var fn = jest.fn();
var wrapper = mount( /*#__PURE__*/React.createElement(StepBar, {
content: stepBarContent,
onClick: fn
}));
wrapper.find('.umui-step-bar-item').at(4).children().simulate('click');
expect(wrapper.find('.umui-step-bar-item').at(4).hasClass('umui-step-bar-active')).toBe(false);
expect(fn).not.toHaveBeenCalled();
});
});