1import type { MenuAction } from "@react-native-menu/menu";
2import { describe, expect, it } from "vite-plus/test";
3
4import { withMenuActionIconColors } from "./menu-action-colors";
5
6describe("withMenuActionIconColors", () => {
7 it.each(["#111111", "#eeeeee"])(
8 "gives icons a visible color at every menu depth for the %s theme",
9 (icon) => {
10 const actions: MenuAction[] = [
11 { id: "photos", title: "Photos", image: "photo" },
12 {
13 title: "Thread",
14 subactions: [
15 {
16 title: "Pinned thread",
17 image: "pin",
18 subactions: [{ title: "Move up", image: "arrow.up" }],
19 },
20 ],
21 },
22 ];
23
24 const result = withMenuActionIconColors(actions, { icon, destructiveIcon: "#ff0000" });
25
26 expect(result[0]?.imageColor).toBe(icon);
27 expect(result[1]).not.toHaveProperty("imageColor");
28 expect(result[1]?.subactions?.[0]?.imageColor).toBe(icon);
29 expect(result[1]?.subactions?.[0]?.subactions?.[0]?.imageColor).toBe(icon);
30 expect(actions[0]).not.toHaveProperty("imageColor");
31 expect(actions[1]?.subactions?.[0]).not.toHaveProperty("imageColor");
32 },
33 );
34
35 it("uses the destructive color while retaining action state and attributes", () => {
36 const action: MenuAction = {
37 id: "delete",
38 title: "Delete",
39 image: "trash",
40 state: "off",
41 attributes: { destructive: true, disabled: true },
42 };
43
44 expect(
45 withMenuActionIconColors([action], {
46 icon: "#111111",
47 destructiveIcon: "#cc0000",
48 }),
49 ).toEqual([{ ...action, imageColor: "#cc0000" }]);
50 });
51
52 it.each(["#123456", "transparent", 0])("preserves explicit icon color %s", (imageColor) => {
53 const action: MenuAction = {
54 title: "Delete",
55 image: "trash",
56 imageColor,
57 attributes: { destructive: true },
58 };
59
60 expect(
61 withMenuActionIconColors([action], {
62 icon: "#111111",
63 destructiveIcon: "#cc0000",
64 }),
65 ).toEqual([action]);
66 });
67});