-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathbox-shadow.test.tsx
More file actions
207 lines (183 loc) · 4.78 KB
/
box-shadow.test.tsx
File metadata and controls
207 lines (183 loc) · 4.78 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import { render, screen } from "@testing-library/react-native";
import { View } from "react-native-css/components/View";
import { registerCSS, testID } from "react-native-css/jest";
test("shadow values - single nested variables", () => {
registerCSS(`
:root {
--color: #fb2c36;
--my-var: 0 20px 25px -5px var(--color);
}
.test { box-shadow: var(--my-var); }
`);
render(<View testID={testID} className="test" />);
const component = screen.getByTestId(testID);
expect(component.props.style).toStrictEqual({
boxShadow: [
{
blurRadius: 25,
color: "#fb2c36",
offsetX: 0,
offsetY: 20,
spreadDistance: -5,
},
],
});
});
test("shadow values - multiple nested variables", () => {
registerCSS(`
:root {
--my-var: 0 20px 0 0 red, 0 30px 0 0 green;
--my-var-2: var(--my-var), 0 40px 0 0 purple;
--my-var-3: 0 50px 0 0 yellow, 0 60px 0 0 orange;
--my-var-4: var(--my-var-3), 0 70px 0 0 gray;
}
.test {
box-shadow: var(--my-var-2), var(--my-var-4);
}
`);
render(<View testID={testID} className="test" />);
const component = screen.getByTestId(testID);
expect(component.props.style).toStrictEqual({
boxShadow: [
{
blurRadius: 0,
color: "#f00",
offsetX: 0,
offsetY: 20,
spreadDistance: 0,
},
{
blurRadius: 0,
color: "#008000",
offsetX: 0,
offsetY: 30,
spreadDistance: 0,
},
{
blurRadius: 0,
color: "#800080",
offsetX: 0,
offsetY: 40,
spreadDistance: 0,
},
{
blurRadius: 0,
color: "#ff0",
offsetX: 0,
offsetY: 50,
spreadDistance: 0,
},
{
blurRadius: 0,
color: "#ffa500",
offsetX: 0,
offsetY: 60,
spreadDistance: 0,
},
{
blurRadius: 0,
color: "#808080",
offsetX: 0,
offsetY: 70,
spreadDistance: 0,
},
],
});
});
test("inset shadow - basic", () => {
registerCSS(`
.test { box-shadow: inset 0 2px 4px 0 #000; }
`);
render(<View testID={testID} className="test" />);
const component = screen.getByTestId(testID);
expect(component.props.style).toStrictEqual({
boxShadow: [
{
inset: true,
offsetX: 0,
offsetY: 2,
blurRadius: 4,
spreadDistance: 0,
color: "#000",
},
],
});
});
test("inset shadow - with color first", () => {
registerCSS(`
.test { box-shadow: inset #fb2c36 0 0 24px 0; }
`);
render(<View testID={testID} className="test" />);
const component = screen.getByTestId(testID);
expect(component.props.style).toStrictEqual({
boxShadow: [
{
inset: true,
color: "#fb2c36",
offsetX: 0,
offsetY: 0,
blurRadius: 24,
spreadDistance: 0,
},
],
});
});
test("inset shadow - without color inherits default", () => {
registerCSS(`
.test { box-shadow: inset 0 0 10px 5px; }
`);
render(<View testID={testID} className="test" />);
const component = screen.getByTestId(testID);
// Shadows without explicit color inherit the default text color (__rn-css-color)
expect(component.props.style.boxShadow).toHaveLength(1);
expect(component.props.style.boxShadow[0]).toMatchObject({
inset: true,
offsetX: 0,
offsetY: 0,
blurRadius: 10,
spreadDistance: 5,
});
// Color is inherited from platform default (PlatformColor)
expect(component.props.style.boxShadow[0].color).toBeDefined();
});
test("mixed inset and regular shadows", () => {
registerCSS(`
.test { box-shadow: 0 4px 6px -1px #000, inset 0 2px 4px 0 #fff; }
`);
render(<View testID={testID} className="test" />);
const component = screen.getByTestId(testID);
expect(component.props.style).toStrictEqual({
boxShadow: [
{
offsetX: 0,
offsetY: 4,
blurRadius: 6,
spreadDistance: -1,
color: "#000",
},
{
inset: true,
offsetX: 0,
offsetY: 2,
blurRadius: 4,
spreadDistance: 0,
color: "#fff",
},
],
});
});
test("Tailwind v4 shadow variables - transparent color #0000", () => {
// Tailwind v4 uses --tw-shadow etc with @property initial-value of transparent
registerCSS(`
:root {
--tw-shadow: 0 0 0 0 #0000;
}
.test { box-shadow: var(--tw-shadow); }
`);
render(<View testID={testID} className="test" />);
const component = screen.getByTestId(testID);
// The shadow is parsed correctly with #0000 color
// Note: filtering of transparent shadows happens in omitTransparentShadows
// which checks for exact "#0000" or "transparent" strings
expect(component.props.style.boxShadow).toBeDefined();
});