Blame view

天文台pc/tianwentai-ui/node_modules/react-day-picker/src/components/Table/Table.test.tsx 1.52 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
  import { DayPickerProps } from 'DayPicker';
  
  import { customRender } from 'test/render/customRender';
  import { freezeBeforeAll } from 'test/utils';
  
  import { FooterProps } from 'components/Footer';
  
  import { Table, TableProps } from './Table';
  
  function setup(props: TableProps, dayPickerProps?: DayPickerProps) {
    return customRender(<Table {...props} />, dayPickerProps);
  }
  
  const today = new Date(2021, 11, 8);
  freezeBeforeAll(today);
  
  const props: TableProps = {
    displayMonth: new Date(2020, 1)
  };
  
  test('should render correctly', () => {
    const { container } = setup(props);
    expect(container.firstChild).toMatchSnapshot();
  });
  
  describe('when showing the week numbers', () => {
    const dayPickerProps = { showWeekNumber: true };
    test('should render correctly', () => {
      const { container } = setup(props, dayPickerProps);
      expect(container.firstChild).toMatchSnapshot();
    });
  });
  
  describe('when using custom components', () => {
    const dayPickerProps: DayPickerProps = {
      components: {
        Head: () => (
          <thead>
            <tr>
              <td>CustomHead</td>
            </tr>
          </thead>
        ),
        Row: () => (
          <tr>
            <td>CustomRow</td>
          </tr>
        ),
        Footer: (props: FooterProps) => (
          <tfoot>
            <tr>
              <td>{props.displayMonth?.toDateString()}</td>
            </tr>
          </tfoot>
        )
      }
    };
    test('should render correctly', () => {
      const { container } = setup(props, dayPickerProps);
      expect(container.firstChild).toMatchSnapshot();
    });
  });