Blame view

天文台pc/tianwentai-ui/node_modules/react-day-picker/src/components/Row/Row.test.tsx 2.13 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
66
67
  import { screen } from '@testing-library/react';
  import { DayPickerProps } from 'DayPicker';
  
  import { customRender } from 'test/render/customRender';
  
  import { CustomComponents } from 'types/DayPickerBase';
  
  import { Row, RowProps } from './Row';
  
  function setup(props: RowProps, dayPickerProps?: DayPickerProps) {
    customRender(<Row {...props} />, dayPickerProps);
  }
  
  const props: RowProps = {
    displayMonth: new Date(2020, 1),
    weekNumber: 4,
    dates: [new Date(2020, 1, 1), new Date(2020, 1, 2), new Date(2020, 1, 3)]
  };
  
  describe('when "showWeekNumber" is set', () => {
    const dayPickerProps = {
      showWeekNumber: true,
      classNames: { cell: 'cell' },
      styles: { cell: { background: 'red' } }
    };
    beforeEach(() => {
      setup(props, dayPickerProps);
    });
    test('should display the cell with the week number', () => {
      const cell = screen.getByRole('cell', { name: `${props.weekNumber}` });
      expect(cell).toBeInTheDocument();
    });
    test('the cell should have the "cell" class name', () => {
      const cell = screen.getByRole('cell', { name: `${props.weekNumber}` });
      expect(cell).toHaveClass(dayPickerProps.classNames.cell);
    });
    test('the cell should have the "cell" style', () => {
      const cell = screen.getByRole('cell', { name: `${props.weekNumber}` });
      expect(cell).toHaveStyle(dayPickerProps.styles.cell);
    });
  });
  
  describe('when using a custom Day component', () => {
    const components: CustomComponents = {
      Day: () => <div>CustomDay</div>
    };
    const dayPickerProps = { components };
    beforeEach(() => {
      setup(props, dayPickerProps);
    });
    test('it should render the custom component instead', () => {
      expect(screen.getAllByText('CustomDay')).toHaveLength(props.dates.length);
    });
  });
  
  describe('when using a custom WeekNumber component', () => {
    const components: CustomComponents = {
      WeekNumber: () => <div>WeekNumber</div>
    };
    const dayPickerProps: DayPickerProps = { components, showWeekNumber: true };
    beforeEach(() => {
      setup(props, dayPickerProps);
    });
    test('it should render the custom component instead', () => {
      expect(screen.getByText('WeekNumber')).toBeInTheDocument();
    });
  });