-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathcontainer-queries.test.tsx
More file actions
115 lines (95 loc) · 2.28 KB
/
container-queries.test.tsx
File metadata and controls
115 lines (95 loc) · 2.28 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
import { fireEvent, render, screen } from "@testing-library/react-native";
import { View } from "react-native-css/components/View";
import { registerCSS } from "react-native-css/jest";
const parentID = "parent";
const childID = "child";
test("Unnamed containers", () => {
registerCSS(`
:root, :host {
--color-white: #fff;
}
.\\@container {
container-type: inline-size;
}
.\\@sm\\:text-white {
@container (width >= 24rem) {
color: var(--color-white);
}
}
`);
render(
<View testID={parentID} className="@container">
<View testID={childID} className="@sm:text-white" />
</View>,
);
const parent = screen.getByTestId(parentID);
const child = screen.getByTestId(childID);
expect(child).toHaveStyle(undefined);
// Jest does not fire layout events, so we need to manually
fireEvent(parent, "layout", {
nativeEvent: {
layout: {
width: 500,
height: 200,
},
},
});
expect(child).toHaveStyle({ color: "#fff" });
});
test("container query width", () => {
registerCSS(`
.container {
container-name: my-container;
width: 200px;
}
.child {
color: red;
}
@container (width > 400px) {
.child {
color: blue;
}
}
`);
render(
<View testID={parentID} className="container">
<View testID={childID} className="child" />
</View>,
);
const parent = screen.getByTestId(parentID);
const child = screen.getByTestId(childID);
expect(parent.props.style).toStrictEqual({
width: 200,
});
expect(child.props.style).toStrictEqual({
color: "#f00",
});
fireEvent(parent, "layout", {
nativeEvent: {
layout: {
width: 200,
height: 200,
},
},
});
expect(child.props.style).toStrictEqual({
color: "#f00",
});
screen.rerender(
<View testID={parentID} className="container" style={{ width: 500 }}>
<View testID={childID} className="child" />
</View>,
);
fireEvent(parent, "layout", {
nativeEvent: {
layout: {
width: 500,
height: 200,
},
},
});
expect(parent.props.style).toStrictEqual([{ width: 200 }, { width: 500 }]);
expect(child.props.style).toStrictEqual({
color: "#00f",
});
});