typography.test.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import * as _ from 'lodash';
  2. import Typography from '../index';
  3. describe(`Typography`, () => {
  4. beforeEach(() => {
  5. document.getSelection = () => {
  6. return {
  7. removeAllRanges: () => { }
  8. };
  9. }
  10. });
  11. it('custom component', () => {
  12. let props = { component: 'div' };
  13. const typographyTitle = mount(<Typography.Title {...props} heading={1}>Semi Design</Typography.Title>)
  14. const title = typographyTitle.find('div.semi-typography-h1');
  15. expect(title.length).toEqual(1);
  16. const typographyText = mount(<Typography.Text {...props} id="text">Semi Design</Typography.Text>)
  17. const text = typographyText.find('div.semi-typography');
  18. expect(text.length).toEqual(1);
  19. const typographyParagraph = mount(<Typography.Paragraph {...props}>Semi Design</Typography.Paragraph>)
  20. const p = typographyParagraph.find('div.semi-typography-paragraph');
  21. expect(p.length).toEqual(1);
  22. typographyParagraph.unmount();
  23. });
  24. it('typography copyable', () => {
  25. const typographyParagraph = mount(<Typography.Paragraph copyable >Semi Design</Typography.Paragraph>)
  26. const p = typographyParagraph.find('.semi-icon-copy');
  27. expect(p.length).toEqual(1);
  28. p.at(0).simulate('click');
  29. expect(typographyParagraph.find('.semi-typography-action-copied').length).toEqual(1);
  30. typographyParagraph.setProps({copyable: false})
  31. typographyParagraph.update()
  32. expect(typographyParagraph.find('.semi-icon-copy').length).toEqual(0);
  33. });
  34. it('typography link', () => {
  35. const text = mount(
  36. <Typography.Text link={{ href: 'https://semi.design/' }}>链接文本</Typography.Text>
  37. )
  38. expect(text.find('.semi-typography.semi-typography-link').length).toEqual(1);
  39. text.setProps({disabled: true})
  40. text.update()
  41. expect(text.find('.semi-typography.semi-typography-disabled').length).toEqual(1);
  42. text.setProps({underline: true, link: false})
  43. text.update()
  44. expect(text.find('.semi-typography u').length).toEqual(1);
  45. });
  46. it('typography ellipsis', () => {
  47. const typographyParagraph = mount(<Typography.Paragraph ellipsis={{ showTooltip: true }} style={{ width: 250 }}>
  48. 是一个很长很长很长很长5号标题</Typography.Paragraph>)
  49. // jest 测不出layout,补一些无效用例,提高coverage
  50. expect(typographyParagraph.find('semi-typography-ellipsis').length).toEqual(0);
  51. typographyParagraph.setProps({children: '的撒的撒打算的撒的撒的撒打算打的撒的撒打算的撒的撒的撒打算打'})
  52. typographyParagraph.update()
  53. expect(typographyParagraph.find('semi-typography-ellipsis').length).toEqual(0);
  54. typographyParagraph.setProps({
  55. ellipsis: {
  56. expandText:'expandText',collapseText:'collapseText',
  57. rows: 1,
  58. showTooltip: {
  59. type: 'popover'
  60. },
  61. suffix: 'suffix'
  62. }
  63. })
  64. typographyParagraph.update()
  65. expect(typographyParagraph.find('semi-typography-ellipsis').length).toEqual(0);
  66. });
  67. });