Blame view

天文台pc/tianwentai-ui/node_modules/react-day-picker/src/contexts/Focus/utils/getInitialFocusTarget.test.ts 1.21 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
  import { Modifiers } from 'types/Modifiers';
  
  import { getInitialFocusTarget } from './getInitialFocusTarget';
  
  describe('when no days are selected is selected', () => {
    test('should return the first day of month', () => {
      const displayMonth = new Date(2022, 7);
      const modifiers: Modifiers = {
        outside: [],
        disabled: [],
        selected: [],
        hidden: [],
        today: [],
        range_start: [],
        range_end: [],
        range_middle: []
      };
      const initialFocusTarget = getInitialFocusTarget([displayMonth], modifiers);
      expect(initialFocusTarget).toStrictEqual(displayMonth);
    });
  });
  
  describe('when a day is selected', () => {
    test('should return the selected day', () => {
      const displayMonths = [new Date(2022, 7)];
      const selectedDay1 = new Date(2022, 7, 17);
      const selectedDay2 = new Date(2022, 7, 19);
      const modifiers: Modifiers = {
        outside: [],
        disabled: [],
        selected: [selectedDay1, selectedDay2],
        hidden: [],
        today: [],
        range_start: [],
        range_end: [],
        range_middle: []
      };
      const initialFocusTarget = getInitialFocusTarget(displayMonths, modifiers);
      expect(initialFocusTarget).toStrictEqual(selectedDay1);
    });
  });