import * as _ from 'lodash'; import Typography from '../index'; describe(`Typography`, () => { beforeEach(() => { document.getSelection = () => { return { removeAllRanges: () => {}, }; }; }); it('custom component', () => { let props = { component: 'div' }; const typographyTitle = mount( Semi Design ); const title = typographyTitle.find('div.semi-typography-h1'); expect(title.length).toEqual(1); const typographyText = mount( Semi Design ); const text = typographyText.find('div.semi-typography'); expect(text.length).toEqual(1); const typographyParagraph = mount(Semi Design); const p = typographyParagraph.find('div.semi-typography-paragraph'); expect(p.length).toEqual(1); typographyParagraph.unmount(); }); it('typography copyable', () => { const typographyParagraph = mount(Semi Design); const p = typographyParagraph.find('.semi-icon-copy'); expect(p.length).toEqual(1); p.at(0).simulate('click'); expect(typographyParagraph.find('.semi-typography-action-copied').length).toEqual(1); typographyParagraph.setProps({ copyable: false }); typographyParagraph.update(); expect(typographyParagraph.find('.semi-icon-copy').length).toEqual(0); }); it('typography link', () => { const text = mount(链接文本); expect(text.find('.semi-typography.semi-typography-link').length).toEqual(1); text.setProps({ disabled: true }); text.update(); expect(text.find('.semi-typography.semi-typography-disabled').length).toEqual(1); text.setProps({ underline: true, link: false }); text.update(); expect(text.find('.semi-typography u').length).toEqual(1); }); it('typography ellipsis', () => { const typographyParagraph = mount( 是一个很长很长很长很长5号标题 ); // jest 测不出layout,补一些无效用例,提高coverage expect(typographyParagraph.find('semi-typography-ellipsis').length).toEqual(0); typographyParagraph.setProps({ children: '的撒的撒打算的撒的撒的撒打算打的撒的撒打算的撒的撒的撒打算打' }); typographyParagraph.update(); expect(typographyParagraph.find('semi-typography-ellipsis').length).toEqual(0); typographyParagraph.setProps({ ellipsis: { expandText: 'expandText', collapseText: 'collapseText', rows: 1, showTooltip: { type: 'popover', }, suffix: 'suffix', }, }); typographyParagraph.update(); expect(typographyParagraph.find('semi-typography-ellipsis').length).toEqual(0); }); it('typography Numeral', () => { let numeral = mount(
预期价格:{() => 1.555}; 成本: -1; 盈利: 0.555 Currency symbols: $
); expect(numeral.find('.price').text()).toEqual('1.56-1.00,0.56'); numeral = mount(
Total revenue: $ 1992.15
) expect(numeral.find('.price').text()).toEqual('Total revenue: $ 1.99e+3') // test: parser numeral.setProps({ parser: oldVal => oldVal.replace(/[^\d.]/g, '') }) expect(numeral.find('.price').text()).toEqual('1992.15') }) });