Blame view

天文台pc/tianwentai-ui/node_modules/react-day-picker/src/contexts/Modifiers/utils/getActiveModifiers.test.ts 1.43 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
  import { addMonths } from 'date-fns';
  
  import {
    InternalModifier,
    InternalModifiers,
    Modifiers
  } from 'types/Modifiers';
  
  import { getActiveModifiers } from './getActiveModifiers';
  
  const day = new Date();
  
  const internalModifiers: InternalModifiers = {
    [InternalModifier.Outside]: [],
    [InternalModifier.Disabled]: [],
    [InternalModifier.Selected]: [],
    [InternalModifier.Hidden]: [],
    [InternalModifier.Today]: [],
    [InternalModifier.RangeStart]: [],
    [InternalModifier.RangeEnd]: [],
    [InternalModifier.RangeMiddle]: []
  };
  describe('when the day matches a modifier', () => {
    const modifiers: Modifiers = {
      ...internalModifiers,
      foo: [day]
    };
    const result = getActiveModifiers(day, modifiers);
    test('should return the modifier as active', () => {
      expect(result.foo).toBe(true);
    });
  });
  describe('when the day does not match a modifier', () => {
    const modifiers: Modifiers = {
      ...internalModifiers,
      foo: []
    };
    const result = getActiveModifiers(day, modifiers);
    test('should not return the modifier as active', () => {
      expect(result.foo).toBeUndefined();
    });
  });
  
  describe('when the day is not in the same display month', () => {
    const modifiers: Modifiers = {
      ...internalModifiers
    };
    const displayMonth = addMonths(day, 1);
    const result = getActiveModifiers(day, modifiers, displayMonth);
    test('should not return the modifier as active', () => {
      expect(result.outside).toBe(true);
    });
  });