Skip to content

Commit e2c0d89

Browse files
committed
test(tailwind): drop the hover platform setup main's answer makes moot
With main's answer to every hover comparison kept, hover: and group-hover: apply whatever the platform, so the Mac Catalyst mock around those tests changed nothing, and the touchscreen tests repeated them on the iOS preset. The tests go back to main's layout, keeping the author's assertions that the colour is absent. The setup moves to the hover patch, where the platform decides the answer.
1 parent d83c80c commit e2c0d89

2 files changed

Lines changed: 57 additions & 110 deletions

File tree

‎src/__tests__/vendor/tailwind/groups.test.tsx‎

Lines changed: 32 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Platform } from "react-native";
2-
31
import { fireEvent, screen } from "@testing-library/react-native";
42
import { View } from "react-native-css/components";
53

@@ -9,75 +7,49 @@ const grandparentID = "grandparentID";
97
const parentID = "parent";
108
const childID = "child";
119

12-
describe("on a primary input that hovers", () => {
13-
beforeEach(() => {
14-
if (Platform.OS !== "ios") {
15-
throw new Error("the suite runs on the iOS preset");
16-
}
17-
jest.spyOn(Platform, "isMacCatalyst", "get").mockReturnValue(true);
18-
});
19-
20-
afterEach(() => {
21-
jest.restoreAllMocks();
22-
});
23-
24-
test("Styling based on parent state (group-{modifier})", async () => {
25-
await render(
26-
<View testID={parentID} className="group">
27-
<View testID={childID} className="group-hover:text-white" />
28-
</View>,
29-
);
30-
31-
const parent = screen.getByTestId(parentID);
32-
const child = screen.getByTestId(childID);
33-
34-
expect(parent).not.toHaveStyle({ color: "#fff" });
35-
expect(child).not.toHaveStyle({ color: "#fff" });
36-
37-
fireEvent(parent, "hoverIn");
38-
39-
expect(child).toHaveStyle({ color: "#fff" });
40-
});
41-
42-
test("Differentiating nested groups", async () => {
43-
await render(
44-
<View testID={grandparentID} className="group/grandparent">
45-
<View testID={parentID} className="group/parent">
46-
<View className="group-hover/grandparent:text-white" />
47-
<View testID={childID} className="group-hover/parent:text-white" />
48-
</View>
49-
</View>,
50-
);
51-
52-
const grandparent = screen.getByTestId(grandparentID);
53-
const parent = screen.getByTestId(parentID);
54-
const child = screen.getByTestId(childID);
55-
56-
expect(grandparent).not.toHaveStyle({ color: "#fff" });
57-
expect(parent).not.toHaveStyle({ color: "#fff" });
58-
expect(child).not.toHaveStyle({ color: "#fff" });
10+
test("Styling based on parent state (group-{modifier})", async () => {
11+
await render(
12+
<View testID={parentID} className="group">
13+
<View testID={childID} className="group-hover:text-white" />
14+
</View>,
15+
);
5916

60-
fireEvent(grandparent, "hoverIn");
17+
const parent = screen.getByTestId(parentID);
18+
const child = screen.getByTestId(childID);
6119

62-
expect(child).not.toHaveStyle({ color: "#fff" });
20+
expect(parent).not.toHaveStyle({ color: "#fff" });
21+
expect(child).not.toHaveStyle({ color: "#fff" });
6322

64-
fireEvent(parent, "hoverIn");
23+
fireEvent(parent, "hoverIn");
6524

66-
expect(child).toHaveStyle({ color: "#fff" });
67-
});
25+
expect(child).toHaveStyle({ color: "#fff" });
6826
});
6927

70-
// Every hover comparison holds, as on main, so Tailwind's group-hover: applies on a touchscreen's platform too, as in Nativewind v4
71-
test("group-hover applies on a touchscreen's platform", async () => {
28+
test("Differentiating nested groups", async () => {
7229
await render(
73-
<View testID={parentID} className="group">
74-
<View testID={childID} className="group-hover:text-white" />
30+
<View testID={grandparentID} className="group/grandparent">
31+
<View testID={parentID} className="group/parent">
32+
<View className="group-hover/grandparent:text-white" />
33+
<View testID={childID} className="group-hover/parent:text-white" />
34+
</View>
7535
</View>,
7636
);
7737

78-
fireEvent(screen.getByTestId(parentID), "hoverIn");
38+
const grandparent = screen.getByTestId(grandparentID);
39+
const parent = screen.getByTestId(parentID);
40+
const child = screen.getByTestId(childID);
41+
42+
expect(grandparent).not.toHaveStyle({ color: "#fff" });
43+
expect(parent).not.toHaveStyle({ color: "#fff" });
44+
expect(child).not.toHaveStyle({ color: "#fff" });
45+
46+
fireEvent(grandparent, "hoverIn");
7947

80-
expect(screen.getByTestId(childID)).toHaveStyle({ color: "#fff" });
48+
expect(child).not.toHaveStyle({ color: "#fff" });
49+
50+
fireEvent(parent, "hoverIn");
51+
52+
expect(child).toHaveStyle({ color: "#fff" });
8153
});
8254

8355
test("arbitrary groups - single className", async () => {

‎src/__tests__/vendor/tailwind/states.test.tsx‎

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Platform } from "react-native";
2-
31
import { fireEvent, screen } from "@testing-library/react-native";
42
import type { StyleRule } from "react-native-css/compiler";
53
import { Switch, TextInput, View } from "react-native-css/components";
@@ -12,59 +10,18 @@ import { render } from "./_tailwind";
1210

1311
const testID = "component";
1412

15-
describe("on a primary input that hovers", () => {
16-
beforeEach(() => {
17-
if (Platform.OS !== "ios") {
18-
throw new Error("the suite runs on the iOS preset");
19-
}
20-
jest.spyOn(Platform, "isMacCatalyst", "get").mockReturnValue(true);
21-
});
22-
23-
afterEach(() => {
24-
jest.restoreAllMocks();
25-
});
26-
27-
test("hover", async () => {
28-
await render(<TextInput testID={testID} className="hover:text-white" />);
29-
30-
const component = screen.getByTestId(testID);
31-
32-
expect(component).not.toHaveStyle({ color: "#fff" });
33-
34-
fireEvent(component, "hoverIn");
35-
expect(component).toHaveStyle({ color: "#fff" });
36-
37-
fireEvent(component, "hoverOut");
38-
expect(component).not.toHaveStyle({ color: "#fff" });
39-
});
40-
41-
test("mixed", async () => {
42-
await render(
43-
<TextInput testID={testID} className="active:hover:focus:text-white" />,
44-
);
45-
46-
const component = screen.getByTestId(testID);
47-
expect(component).not.toHaveStyle({ color: "#fff" });
48-
49-
fireEvent(component, "pressIn");
50-
expect(component).not.toHaveStyle({ color: "#fff" });
51-
52-
fireEvent(component, "hoverIn");
53-
expect(component).not.toHaveStyle({ color: "#fff" });
54-
55-
fireEvent(component, "focus");
56-
expect(component).toHaveStyle({ color: "#fff" });
57-
});
58-
});
59-
60-
// Every hover comparison holds, as on main, so Tailwind's hover: applies on a touchscreen's platform too, as in Nativewind v4
61-
test("hover applies on a touchscreen's platform", async () => {
13+
test("hover", async () => {
6214
await render(<TextInput testID={testID} className="hover:text-white" />);
6315

6416
const component = screen.getByTestId(testID);
65-
fireEvent(component, "hoverIn");
6617

18+
expect(component).not.toHaveStyle({ color: "#fff" });
19+
20+
fireEvent(component, "hoverIn");
6721
expect(component).toHaveStyle({ color: "#fff" });
22+
23+
fireEvent(component, "hoverOut");
24+
expect(component).not.toHaveStyle({ color: "#fff" });
6825
});
6926

7027
test("focus", async () => {
@@ -95,6 +52,24 @@ test("active", async () => {
9552
expect(component).not.toHaveStyle({ color: "#fff" });
9653
});
9754

55+
test("mixed", async () => {
56+
await render(
57+
<TextInput testID={testID} className="active:hover:focus:text-white" />,
58+
);
59+
60+
const component = screen.getByTestId(testID);
61+
expect(component).not.toHaveStyle({ color: "#fff" });
62+
63+
fireEvent(component, "pressIn");
64+
expect(component).not.toHaveStyle({ color: "#fff" });
65+
66+
fireEvent(component, "hoverIn");
67+
expect(component).not.toHaveStyle({ color: "#fff" });
68+
69+
fireEvent(component, "focus");
70+
expect(component).toHaveStyle({ color: "#fff" });
71+
});
72+
9873
test("selection", async () => {
9974
await render(<TextInput testID={testID} className="selection:text-black" />);
10075

0 commit comments

Comments
 (0)