Blame view

天文台pc/tianwentai-ui/node_modules/react-day-picker/src/hooks/useSelectedDays/useSelectedDays.test.ts 1.25 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
  import { DayPickerProps } from 'DayPicker';
  
  import { mockedContexts } from 'test/mockedContexts';
  import { renderDayPickerHook } from 'test/render';
  import { freezeBeforeAll } from 'test/utils';
  
  import { useSelectedDays } from './useSelectedDays';
  
  const today = new Date(2021, 11, 8);
  freezeBeforeAll(today);
  
  function renderHook(dayPickerProps: DayPickerProps) {
    return renderDayPickerHook(
      () => useSelectedDays(),
      dayPickerProps,
      mockedContexts
    );
  }
  
  describe('when in single selection mode', () => {
    const mode = 'single';
    test('should return the selection from the single context', () => {
      const result = renderHook({ mode, selected: today });
      expect(result.current).toBe(mockedContexts.single.selected);
    });
  });
  
  describe('when in multiple selection mode', () => {
    const mode = 'multiple';
    test('should return the selection from the multiple context', () => {
      const result = renderHook({ mode });
      expect(result.current).toBe(mockedContexts.multiple.selected);
    });
  });
  
  describe('when in range selection mode', () => {
    const mode = 'range';
    test('should return the selection from the range context', () => {
      const result = renderHook({ mode });
      expect(result.current).toBe(mockedContexts.range.selected);
    });
  });