markdown.test.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. it(`test table with bold header`, async () => {
  39. const content = `
  40. | Name | **Brand** | Count | **Price** |
  41. | - | :- | -: | :-: |
  42. | Book | Semi | 10 | ¥100 |
  43. | Pen | Semi Design | 20 | ¥200 |
  44. `;
  45. const render = mount(
  46. <MarkdownRender raw={content} />
  47. );
  48. // check if has table container
  49. expect(render.exists(`.${BASE_CLASS_PREFIX}-table-container`)).toEqual(true);
  50. // check if has table head & body
  51. expect(render.exists(`.${BASE_CLASS_PREFIX}-table-thead`)).toEqual(true);
  52. expect(render.exists(`.${BASE_CLASS_PREFIX}-table-tbody`)).toEqual(true);
  53. // check has row is two
  54. expect(render.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row`).length).toBe(2);
  55. // exist 'Semi Design' text
  56. expect(render.contains('Semi Design')).toEqual(true);
  57. // exist 'Semi' text
  58. expect(render.contains('Semi')).toEqual(true);
  59. // exist '¥100' text
  60. expect(render.contains('¥100')).toEqual(true);
  61. // exist '¥200' text
  62. expect(render.contains('¥200')).toEqual(true);
  63. });
  64. it(`test table with bold and component header`, async () => {
  65. const content = `
  66. | Name | <h1>Brand</h1> | Count | **Price** |
  67. | - | :- | -: | :-: |
  68. | Book | Semi | 10 | ¥100 |
  69. | Pen | Semi Design | 20 | ¥200 |
  70. `;
  71. const render = mount(
  72. <MarkdownRender raw={content} format="mdx"/>
  73. );
  74. // check if has table container
  75. expect(render.exists(`.${BASE_CLASS_PREFIX}-table-container`)).toEqual(true);
  76. // check if has table head & body
  77. expect(render.exists(`.${BASE_CLASS_PREFIX}-table-thead`)).toEqual(true);
  78. expect(render.exists(`.${BASE_CLASS_PREFIX}-table-tbody`)).toEqual(true);
  79. // check has row is two
  80. expect(render.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row`).length).toBe(2);
  81. // exist 'Semi Design' text
  82. expect(render.contains('Semi Design')).toEqual(true);
  83. // exist 'Semi' text
  84. expect(render.contains('Semi')).toEqual(true);
  85. // exist '¥100' text
  86. expect(render.contains('¥100')).toEqual(true);
  87. // exist '¥200' text
  88. expect(render.contains('¥200')).toEqual(true);
  89. });
  90. });