Blame view

天文台pc/tianwentai-ui/node_modules/react-day-picker/src/contexts/Navigation/utils/getPreviousMonth.test.ts 1.97 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
  import { addMonths, isSameMonth } from 'date-fns';
  
  import { getPreviousMonth } from './getPreviousMonth';
  
  const startingMonth = new Date(2020, 4, 31);
  
  describe('when number of months is 1', () => {
    describe('when the navigation is disabled', () => {
      const disableNavigation = true;
      it('the previous month is undefined', () => {
        const result = getPreviousMonth(startingMonth, { disableNavigation });
        expect(result).toBe(undefined);
      });
    });
    describe('when in the navigable range', () => {
      const fromDate = addMonths(startingMonth, -3);
      it('the previous month is not undefined', () => {
        const result = getPreviousMonth(startingMonth, { fromDate });
        const expectedPrevMonth = addMonths(startingMonth, -1);
        expect(result && isSameMonth(result, expectedPrevMonth)).toBeTruthy();
      });
    });
    describe('when not in the navigable range', () => {
      const fromDate = startingMonth;
      it('the previous month is undefined', () => {
        const result = getPreviousMonth(startingMonth, { fromDate });
        expect(result).toBe(undefined);
      });
    });
  });
  describe('when displaying 3 months', () => {
    const numberOfMonths = 3;
    describe('when the navigation is paged', () => {
      const pagedNavigation = true;
      it('the previous month is 3 months back', () => {
        const result = getPreviousMonth(startingMonth, {
          numberOfMonths,
          pagedNavigation
        });
        const expectedPrevMonth = addMonths(startingMonth, -numberOfMonths);
        expect(result && isSameMonth(result, expectedPrevMonth)).toBeTruthy();
      });
    });
    describe('when the navigation is not paged', () => {
      const pagedNavigation = false;
      it('the previous month is 1 months back', () => {
        const result = getPreviousMonth(startingMonth, {
          numberOfMonths,
          pagedNavigation
        });
        const expectedPrevMonth = addMonths(startingMonth, -1);
        expect(result && isSameMonth(result, expectedPrevMonth)).toBeTruthy();
      });
    });
  });