/** @jsxImportSource nativewind */ import { Button, Text, View } from "react-native"; import { act, fireEvent, screen } from "@testing-library/react-native"; import { colorScheme, render, useColorScheme } from "../test"; const testID = "react-native-css-interop"; test("darkMode: media", async () => { await render(, { config: { darkMode: "media", }, }); const component = screen.getByTestId(testID); expect(component).toHaveStyle(undefined); act(() => colorScheme.set("dark")); expect(component).toHaveStyle({ color: "#000000" }); }); test("darkMode: media variable switching", async () => { await render( , { css: ` @tailwind base; @tailwind components; @tailwind utilities; @layer base { :root { --color: 255 115 179; } @media (prefers-color-scheme: dark) { :root { --color: 155 100 255; } } }`, }, ); const component = screen.getByTestId(testID); expect(component).toHaveStyle({ color: "rgb(255, 115, 179)" }); // You cannot manually set the color scheme when using media queries, so we fake it act(() => colorScheme.set("dark")); expect(component).toHaveStyle({ color: "rgb(155, 100, 255)" }); }); test("darkMode: class", async () => { await render(, { config: { darkMode: "class", }, }); const component = screen.getByTestId(testID); expect(component).toHaveStyle(undefined); act(() => colorScheme.set("dark")); expect(component).toHaveStyle({ color: "#000000" }); }); test("darkMode: class - on custom prop", async () => { await render(, { config: { darkMode: "class", }, }); const component = screen.getByTestId(testID); expect(component).toHaveStyle(undefined); expect(component.props).not.toHaveProperty("fill"); act(() => colorScheme.set("dark")); expect(component).toHaveStyle(undefined); expect(component.props.fill).toEqual("#000000"); }); test("darkMode: class variable switching", async () => { await render( , { css: ` @tailwind base; @tailwind components; @tailwind utilities; @layer base { :root { --color: 255 115 179; } .dark:root { --color: 155 100 255; } } `, config: { darkMode: "class", }, }, ); const component = screen.getByTestId(testID); expect(component).toHaveStyle({ color: "rgb(255, 115, 179)" }); act(() => colorScheme.set("dark")); expect(component).toHaveStyle({ color: "rgb(155, 100, 255)" }); }); test("useColorScheme().setColorScheme() with darkMode: class", async () => { const testIds = { TEXT: "useColorScheme", DARK_BUTTON: "dark_button", LIGHT_BUTTON: "light_button", SYSTEM_BUTTON: "system_button", }; function UseColorScheme() { const { colorScheme, setColorScheme } = useColorScheme(); return ( {colorScheme}