mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
96 lines
3.0 KiB
JavaScript
96 lines
3.0 KiB
JavaScript
import React from "react";
|
|
|
|
import { mount } from "enzyme";
|
|
|
|
import { AlertStore } from "Stores/AlertStore";
|
|
import { OverviewModal } from ".";
|
|
|
|
let alertStore;
|
|
|
|
beforeAll(() => {
|
|
jest.useFakeTimers();
|
|
});
|
|
|
|
beforeEach(() => {
|
|
alertStore = new AlertStore([]);
|
|
});
|
|
|
|
const MountedOverviewModal = () => {
|
|
return mount(<OverviewModal alertStore={alertStore} />);
|
|
};
|
|
|
|
describe("<OverviewModal />", () => {
|
|
it("only renders the counter when modal is not shown", () => {
|
|
const tree = MountedOverviewModal();
|
|
expect(tree.text()).toBe("0");
|
|
expect(tree.find("OverviewModalContent")).toHaveLength(0);
|
|
});
|
|
|
|
it("renders a spinner placeholder while modal content is loading", () => {
|
|
const tree = MountedOverviewModal();
|
|
const toggle = tree.find("div.navbar-brand");
|
|
toggle.simulate("click");
|
|
expect(tree.find("OverviewModalContent")).toHaveLength(0);
|
|
expect(tree.find(".modal-content").find("svg.fa-spinner")).toHaveLength(1);
|
|
});
|
|
|
|
it("renders modal content if fallback is not used", () => {
|
|
const tree = MountedOverviewModal();
|
|
const toggle = tree.find("div.navbar-brand");
|
|
toggle.simulate("click");
|
|
expect(tree.find(".modal-title").text()).toBe("Overview");
|
|
expect(tree.find(".modal-content").find("svg.fa-spinner")).toHaveLength(0);
|
|
});
|
|
|
|
it("hides the modal when toggle() is called twice", () => {
|
|
const tree = MountedOverviewModal();
|
|
const toggle = tree.find("div.navbar-brand");
|
|
|
|
toggle.simulate("click");
|
|
jest.runOnlyPendingTimers();
|
|
tree.update();
|
|
expect(tree.find(".modal-title").text()).toBe("Overview");
|
|
|
|
toggle.simulate("click");
|
|
jest.runOnlyPendingTimers();
|
|
tree.update();
|
|
expect(tree.find(".modal-title")).toHaveLength(0);
|
|
});
|
|
|
|
it("hides the modal when button.close is clicked", () => {
|
|
const tree = MountedOverviewModal();
|
|
const toggle = tree.find("div.navbar-brand");
|
|
|
|
toggle.simulate("click");
|
|
expect(tree.find(".modal-title").text()).toBe("Overview");
|
|
|
|
tree.find("button.close").simulate("click");
|
|
jest.runOnlyPendingTimers();
|
|
tree.update();
|
|
expect(tree.find("OverviewModalContent")).toHaveLength(0);
|
|
});
|
|
|
|
it("'modal-open' class is appended to body node when modal is visible", () => {
|
|
const tree = MountedOverviewModal();
|
|
const toggle = tree.find("div.navbar-brand");
|
|
toggle.simulate("click");
|
|
expect(document.body.className.split(" ")).toContain("modal-open");
|
|
});
|
|
|
|
it("'modal-open' class is removed from body node after modal is hidden", () => {
|
|
const tree = MountedOverviewModal();
|
|
const toggle = tree.find("div.navbar-brand");
|
|
toggle.simulate("click");
|
|
toggle.simulate("click");
|
|
expect(document.body.className.split(" ")).not.toContain("modal-open");
|
|
});
|
|
|
|
it("'modal-open' class is removed from body node after modal is unmounted", () => {
|
|
const tree = MountedOverviewModal();
|
|
const toggle = tree.find("div.navbar-brand");
|
|
toggle.simulate("click");
|
|
tree.unmount();
|
|
expect(document.body.className.split(" ")).not.toContain("modal-open");
|
|
});
|
|
});
|