Blame view

天文台pc/tianwentai-ui/node_modules/react-day-picker/src/components/Head/Head.test.tsx 1.4 KB
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  import { RenderResult, screen } from '@testing-library/react';
  import { DayPickerProps } from 'DayPicker';
  
  import { customRender } from 'test/render';
  
  import { Head } from './Head';
  
  let container: HTMLElement;
  let view: RenderResult;
  
  function setup(dayPickerProps: DayPickerProps = {}) {
    view = customRender(
      <table>
        <Head />
      </table>,
      dayPickerProps
    );
    container = view.container.firstChild as HTMLTableCellElement;
  }
  
  const dayPickerProps = {
    styles: {
      head: { color: 'red' },
      head_row: { color: 'blue' },
      head_cell: { color: 'green' }
    },
    classNames: {
      head: 'foo',
      head_row: 'foo_row',
      head_cell: 'foo_head-cell'
    }
  };
  
  describe('when rendered', () => {
    beforeEach(() => {
      setup(dayPickerProps);
    });
  
    test('thead should have the `head` style', () => {
      expect(container.firstChild).toHaveStyle(dayPickerProps.styles.head);
    });
  
    test('thead should have the `head` class', () => {
      expect(container.firstChild).toHaveClass(dayPickerProps.classNames.head);
    });
  });
  
  describe('when using a custom HeadRow component', () => {
    beforeEach(() => {
      setup({
        ...dayPickerProps,
        components: {
          HeadRow: () => (
            <tr>
              <td>custom head</td>
            </tr>
          )
        }
      });
    });
  
    test('should render the custom component', () => {
      expect(screen.getByText('custom head')).toBeInTheDocument();
    });
  });