UNPKG

qt-public-ui

Version:

新设计规范下业务组件库

89 lines 3.03 kB
import React from 'react'; import { mount } from 'enzyme'; import { BrowserRouter } from 'react-router-dom'; import { act } from 'react-dom/test-utils'; import { Select } from 'antd'; import AppSelect from '../index'; var apps_mock = [{ appkey: '56789ikdnbcvtyg7h8jficwev', platform: 'android', name: 'Android App Demo', appCode: 'kaide_miniapp', appDesc: '凯德-小程序', appId: 29192011131831, appInfoId: 29192011131831, appName: '凯德-小程序', appType: 'MINI_APP', creatorId: 96332007216368, creatorName: 'qingliang.hql@baba', iconUrl: 'http://aplus2-portal.emas-poc.com/images/app.png', isMyFavorite: true, ownerId: 96332007216368, ownerName: 'qingliang.hql@baba', status: 'VALID', tenantId: 13062007216102 }, { appkey: 'v78hnvubyuhiwnevuhcfdnvns', platform: 'iphone', name: 'iOS App Demo', appCode: 'amway_web2', appDesc: '安利-web测试2', appInfoId: 87322010211864, appName: '安利-web测试小程序1', appType: 'WEB', creatorId: 96332007216368, creatorName: 'qingliang.hql@baba', iconUrl: 'http://aplus2-pre.emas-poc.com/images/web.png', isMyFavorite: true, ownerId: 96332007216368, ownerName: 'qingliang.hql@baba', status: 'VALID', tenantId: 13062007216102, webDomain: 'https://dt-pre.alicdn.com' }]; describe('AppSelect', function () { it.only('should getJumpUrl to have been called', function () { var fn = jest.fn(); var wrapper = mount( /*#__PURE__*/React.createElement(BrowserRouter, null, /*#__PURE__*/React.createElement(AppSelect, { apps: apps_mock, getJumpUrl: fn // appId={matched?.[0]} }))); act(function () { wrapper.find('.ant-select-selector').simulate('mousedown'); }); wrapper.update(); console.log(wrapper.find('.ant-select-item-option').length, wrapper.find(Select).html()); act(function () { wrapper.find('.ant-select-item-option-content').at(1).simulate('click'); }); wrapper.update(); expect(fn).toHaveBeenCalledWith("/", "all", "v78hnvubyuhiwnevuhcfdnvns"); }); it('should hide all option when showAll is false', function () { var fn = jest.fn(); var wrapper = mount( /*#__PURE__*/React.createElement(BrowserRouter, null, /*#__PURE__*/React.createElement(AppSelect, { apps: apps_mock, getJumpUrl: fn, showAll: false // appId={matched?.[0]} }))); act(function () { wrapper.find('.ant-select-selector').simulate('mousedown'); }); wrapper.update(); expect(wrapper.find('.umui-option-all-app').length).toBe(0); }); it.only('should dropdown render corrent', function () { var fn = jest.fn(); var wrapper = mount( /*#__PURE__*/React.createElement(BrowserRouter, null, /*#__PURE__*/React.createElement(AppSelect, { apps: apps_mock, getJumpUrl: fn }))); act(function () { wrapper.find('.ant-select-selector').simulate('mousedown'); }); wrapper.update(); expect(wrapper.find('.ant-select-dropdown').render()).toMatchSnapshot(); }); });