1 | import type { CSSProperties } from "react";
|
2 |
|
3 |
|
4 | import type { Modifiers, ModifiersStyles } from "../types";
|
5 |
|
6 | import { getStyleForModifiers } from "./getStyleForModifiers";
|
7 |
|
8 | const defaultModifiers: Modifiers = {
|
9 | disabled: false,
|
10 | hidden: false,
|
11 | outside: false,
|
12 | range_end: false,
|
13 | range_middle: false,
|
14 | range_start: false,
|
15 | selected: false,
|
16 | focusable: false,
|
17 | focused: false,
|
18 | today: false
|
19 | };
|
20 |
|
21 | test("applies modifier styles to the base style", () => {
|
22 | const dayModifiers: Modifiers = {
|
23 | ...defaultModifiers,
|
24 | selected: true,
|
25 | disabled: false
|
26 | };
|
27 | const modifiersStyles: Partial<ModifiersStyles> = {
|
28 | selected: { backgroundColor: "blue", color: "white" }
|
29 | };
|
30 | const expectedStyle: CSSProperties = {
|
31 | ...modifiersStyles.selected
|
32 | };
|
33 |
|
34 | const style = getStyleForModifiers(dayModifiers, {}, modifiersStyles);
|
35 |
|
36 | expect(style).toEqual(expectedStyle);
|
37 | });
|
38 |
|
39 | test("ignores modifiers that are not active", () => {
|
40 | const dayModifiers: Modifiers = {
|
41 | ...defaultModifiers,
|
42 | selected: false,
|
43 | disabled: true
|
44 | };
|
45 | const modifiersStyles: Partial<ModifiersStyles> = {
|
46 | disabled: { opacity: 0.5 }
|
47 | };
|
48 |
|
49 | const style = getStyleForModifiers(dayModifiers, {}, modifiersStyles);
|
50 |
|
51 | expect(style).toEqual({ opacity: 0.5 });
|
52 | });
|
53 |
|
54 | test("combines multiple active modifier styles", () => {
|
55 | const dayModifiers: Modifiers = {
|
56 | ...defaultModifiers,
|
57 | selected: true,
|
58 | highlighted: true
|
59 | };
|
60 | const modifiersStyles: Partial<ModifiersStyles> = {
|
61 | selected: { backgroundColor: "blue" },
|
62 | highlighted: { borderColor: "yellow" }
|
63 | };
|
64 | const expectedStyle: CSSProperties = {
|
65 | ...modifiersStyles.selected,
|
66 | ...modifiersStyles.highlighted
|
67 | };
|
68 |
|
69 | const style = getStyleForModifiers(dayModifiers, {}, modifiersStyles);
|
70 |
|
71 | expect(style).toEqual(expectedStyle);
|
72 | });
|
73 |
|
74 | test("applies the most recent modifier style when there are conflicts", () => {
|
75 | const dayModifiers: Modifiers = {
|
76 | ...defaultModifiers,
|
77 | selected: true,
|
78 | highlighted: true
|
79 | };
|
80 | const modifiersStyles: Partial<ModifiersStyles> = {
|
81 | selected: { backgroundColor: "blue", color: "red" },
|
82 | highlighted: { backgroundColor: "yellow", color: "green" }
|
83 | };
|
84 | const expectedStyle: CSSProperties = {
|
85 | backgroundColor: "yellow",
|
86 | color: "green"
|
87 | };
|
88 |
|
89 | const style = getStyleForModifiers(dayModifiers, {}, modifiersStyles);
|
90 |
|
91 | expect(style).toEqual(expectedStyle);
|
92 | });
|