mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
There is no need to have a different name scheme to shorten stimulus controller name. It's now inline with the other components
47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
/**
|
|
* @jest-environment jsdom
|
|
*/
|
|
|
|
import { Application } from "stimulus";
|
|
import vertical_ellipsis_menu_controller from "../../../app/components/vertical_ellipsis_menu_component/vertical_ellipsis_menu_controller";
|
|
|
|
describe("VerticalEllipsisMenuController test", () => {
|
|
beforeAll(() => {
|
|
const application = Application.start();
|
|
application.register("vertical-ellipsis-menu", vertical_ellipsis_menu_controller);
|
|
});
|
|
|
|
beforeEach(() => {
|
|
document.body.innerHTML = `
|
|
<div data-controller="vertical-ellipsis-menu" id="root">
|
|
<div data-action="click->vertical-ellipsis-menu#toggle" id="button">...</div>
|
|
<div data-vertical-ellipsis-menu-target="content" id="content">
|
|
|
|
</div>
|
|
</div>
|
|
`;
|
|
const button = document.getElementById("button");
|
|
const content = document.getElementById("content");
|
|
});
|
|
|
|
it("add show class to content when toggle is called", () => {
|
|
expect(content.classList.contains("show")).toBe(false);
|
|
button.click();
|
|
expect(content.classList.contains("show")).toBe(true);
|
|
});
|
|
|
|
it("remove show class from content when clicking button", () => {
|
|
button.click();
|
|
expect(content.classList.contains("show")).toBe(true);
|
|
button.click();
|
|
expect(content.classList.contains("show")).toBe(false);
|
|
});
|
|
|
|
it("remove show class from content when clicking outside", () => {
|
|
button.click();
|
|
expect(content.classList.contains("show")).toBe(true);
|
|
document.body.click();
|
|
expect(content.classList.contains("show")).toBe(false);
|
|
});
|
|
});
|