Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(menu-item): add token theming tests #9420

Merged
merged 7 commits into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { newE2EPage } from "@stencil/core/testing";
import { html } from "../../../support/formatting";
import { accessible, focusable, hidden, reflects, renders, t9n } from "../../tests/commonTests";
import { accessible, focusable, hidden, reflects, renders, t9n, themed } from "../../tests/commonTests";
import { getFocusedElementProp } from "../../tests/utils";
import { ComponentTestTokens } from "../../tests/commonTests/themed";
import { CSS } from "./resources";

describe("calcite-menu-item", () => {
describe("renders", () => {
Expand Down Expand Up @@ -116,3 +118,89 @@ describe("calcite-menu-item", () => {
expect(eventSpy).toHaveReceivedEventTimes(2);
});
});

describe("theme", () => {
const menuItemHtml = html`
<calcite-menu layout="vertical">
<calcite-menu-item text="Example submenu item 2" text-enabled href="https://esri.com">
<calcite-menu-item slot="submenu-item" text="Example submenu item 1" text-enabled></calcite-menu-item>
</calcite-menu-item>
</calcite-menu>
`;
const dropdownMenuItems = html`
<calcite-menu layout="horizontal">
<calcite-menu-item text="Example item" text-enabled icon-start="layer" icon-end="layer" breadcrumb open>
<calcite-menu-item slot="submenu-item" text="Example submenu item 1" text-enabled></calcite-menu-item>
<calcite-menu-item slot="submenu-item" text="Example submenu item 2" text-enabled href="https://esri.com">
<calcite-menu-item slot="submenu-item" text="Example submenu item 1" text-enabled></calcite-menu-item>
</calcite-menu-item>
</calcite-menu-item>
</calcite-menu>
`;
describe("default", () => {
const tokens: ComponentTestTokens = {
"--calcite-menu-item-action-background-color-active": {
shadowSelector: "calcite-action",
targetProp: "--calcite-action-background-color",
state: { press: { attribute: "class", value: CSS.dropdownAction } },
},
"--calcite-menu-item-action-background-color-hover": {
shadowSelector: "calcite-action",
targetProp: "--calcite-action-background-color",
state: "hover",
},
"--calcite-menu-item-action-background-color": {
shadowSelector: `calcite-action`,
targetProp: "--calcite-action-background-color",
},
"--calcite-menu-item-sub-menu-corner-radius": {
shadowSelector: `.dropdown--vertical`,
targetProp: "borderRadius",
},
"--calcite-menu-item-background-color": {
shadowSelector: `.${CSS.content}`,
targetProp: "backgroundColor",
},
"--calcite-menu-item-border-color": {
shadowSelector: `.${CSS.content}`,
targetProp: "borderColor",
},
};
themed(async () => {
const page = await newE2EPage();
await page.setContent(menuItemHtml);
await page.waitForChanges();
return { tag: "calcite-menu-item", page };
}, tokens);
});

describe("dropdownMenuItems", () => {
const tokens: ComponentTestTokens = {
"--calcite-menu-item-background-color": {
shadowSelector: `.${CSS.dropdownMenuItems}`,
targetProp: "backgroundColor",
},
"--calcite-menu-item-icon-color": {
shadowSelector: `.${CSS.container} .${CSS.icon}`,
targetProp: "--calcite-icon-color",
},
"--calcite-menu-item-text-color": {
shadowSelector: `.${CSS.content}`,
targetProp: "color",
},
"--calcite-menu-item-sub-menu-border-color": {
shadowSelector: `.${CSS.dropdownMenuItems}`,
targetProp: "borderColor",
},
};
themed(async () => {
const page = await newE2EPage();
await page.setContent(dropdownMenuItems);
const menuItem = await page.find("calcite-menu-item");
await menuItem.click();
await page.waitForChanges();
menuItem.setProperty("open", true);
return { tag: "calcite-menu-item", page };
}, tokens);
});
});