mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-23 10:55:31 -06:00
test: remove duplicate tab reorder coverage (#122128)
This commit is contained in:
@@ -15,15 +15,6 @@ const TAB: PanelTabStripTab = {
|
||||
closeLabel: "Close tab: First tab",
|
||||
};
|
||||
|
||||
type RenderedTab = HTMLElement & {
|
||||
active: boolean;
|
||||
panel: string;
|
||||
};
|
||||
|
||||
type RenderedTabGroup = HTMLElement & {
|
||||
active: string;
|
||||
};
|
||||
|
||||
function renderStrip(options: {
|
||||
tabs?: PanelTabStripTab[];
|
||||
activeId?: string | null;
|
||||
@@ -48,18 +39,6 @@ function renderStrip(options: {
|
||||
return container;
|
||||
}
|
||||
|
||||
function readTabStrip(container: ParentNode): {
|
||||
group: RenderedTabGroup;
|
||||
tabs: RenderedTab[];
|
||||
} {
|
||||
const group = container.querySelector<RenderedTabGroup>("wa-tab-group");
|
||||
if (!group) {
|
||||
throw new Error("expected rendered tab group");
|
||||
}
|
||||
const tabs = [...container.querySelectorAll<RenderedTab>("wa-tab")];
|
||||
return { group, tabs };
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
document.body.replaceChildren();
|
||||
});
|
||||
@@ -104,65 +83,4 @@ describe("renderPanelTabStrip", () => {
|
||||
container.querySelector("wa-tab")?.dispatchEvent(new MouseEvent("auxclick", { button: 1 }));
|
||||
expect(onClose).toHaveBeenCalledWith(TAB.id);
|
||||
});
|
||||
|
||||
it("keeps the controlled active tab coherent when stateful tab elements reorder", async () => {
|
||||
const first: PanelTabStripTab = {
|
||||
...TAB,
|
||||
id: "a",
|
||||
domId: "test-tab-a",
|
||||
label: "Alpha",
|
||||
title: "https://example.com/a",
|
||||
};
|
||||
const second: PanelTabStripTab = {
|
||||
...TAB,
|
||||
id: "b",
|
||||
domId: "test-tab-b",
|
||||
label: "Beta",
|
||||
title: "https://example.com/b",
|
||||
};
|
||||
const container = renderStrip({ tabs: [first, second], activeId: first.id });
|
||||
document.body.append(container);
|
||||
const initial = readTabStrip(container);
|
||||
const firstElement = initial.tabs.find((tab) => tab.panel === first.id);
|
||||
const secondElement = initial.tabs.find((tab) => tab.panel === second.id);
|
||||
if (!firstElement || !secondElement) {
|
||||
throw new Error("expected initial active tab");
|
||||
}
|
||||
firstElement.active = true;
|
||||
firstElement.setAttribute("active", "");
|
||||
firstElement.setAttribute("aria-selected", "true");
|
||||
firstElement.tabIndex = 0;
|
||||
secondElement.active = false;
|
||||
secondElement.removeAttribute("active");
|
||||
secondElement.setAttribute("aria-selected", "false");
|
||||
secondElement.tabIndex = -1;
|
||||
|
||||
renderStrip({
|
||||
container,
|
||||
tabs: [
|
||||
{ ...second, label: "Beta navigated", title: "https://example.com/b/next" },
|
||||
{ ...first, label: "Alpha navigated", title: "https://example.com/a/next" },
|
||||
],
|
||||
activeId: first.id,
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
const reordered = readTabStrip(container);
|
||||
const active = reordered.tabs.filter(
|
||||
(tab) =>
|
||||
tab.active || tab.hasAttribute("active") || tab.getAttribute("aria-selected") === "true",
|
||||
);
|
||||
const reorderedFirst = reordered.tabs.find((tab) => tab.panel === first.id);
|
||||
|
||||
expect(reorderedFirst).toBe(firstElement);
|
||||
expect(reordered.group.active).toBe(first.id);
|
||||
expect(active).toEqual([firstElement]);
|
||||
expect(firstElement.getAttribute("aria-selected")).toBe("true");
|
||||
expect(firstElement.tabIndex).toBe(0);
|
||||
expect(reordered.tabs.find((tab) => tab.panel === second.id)).toMatchObject({
|
||||
active: false,
|
||||
tabIndex: -1,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user