markdown.test.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import MarkdownRender from '../index'
  2. import React from 'react';
  3. import { mount } from 'enzyme';
  4. import { BASE_CLASS_PREFIX } from '@douyinfe/semi-foundation/base/constants';
  5. describe(`MarkdownRender`, () => {
  6. it(`test table render`, async () => {
  7. const content = `
  8. | Name | Brand | Count | Price |
  9. | - | :- | -: | :-: |
  10. | Book | Semi | 10 | ¥100 |
  11. | Pen | Semi Design | 20 | ¥200 |
  12. `;
  13. const render = mount(
  14. <MarkdownRender raw={content} />
  15. );
  16. // check if has table container
  17. expect(render.exists(`.${BASE_CLASS_PREFIX}-table-container`)).toEqual(true);
  18. // check if has table head & body
  19. expect(render.exists(`.${BASE_CLASS_PREFIX}-table-thead`)).toEqual(true);
  20. expect(render.exists(`.${BASE_CLASS_PREFIX}-table-tbody`)).toEqual(true);
  21. // check has row is two
  22. expect(render.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row`).length).toBe(2);
  23. });
  24. it(`test table only header`, async () => {
  25. const content = `
  26. | Title | Name | Count | Price |
  27. | - | :- | -: | :-: |
  28. `;
  29. const render = mount(
  30. <MarkdownRender raw={content} />
  31. );
  32. // check if has table container
  33. expect(render.exists(`.${BASE_CLASS_PREFIX}-table-container`)).toEqual(true);
  34. // check if has table head & body
  35. expect(render.exists(`.${BASE_CLASS_PREFIX}-table-thead`)).toEqual(true);
  36. expect(render.exists(`.${BASE_CLASS_PREFIX}-table-tbody`)).toEqual(true);
  37. });
  38. });