import * as React from "react";
import { render, screen, fireEvent, cleanup } from "@testing-library/react";
import { EditorObjectState } from "@sc/modules/v2/Editor/components/EditorObject/types";
import { PageSectionCategory } from "@sc/plugins/misc/v2/blocks/weblayouts/types";
import { IconTypes } from "@sc/plugins/webcomponents/v2/Icon";
import { faWindowMaximize } from "@fortawesome/free-solid-svg-icons";
import SectionItem from "./SectionItem";
const testId = "Blocks-SectionsLegend-SectionItem";
describe("Rendering > Tests", () => {
afterEach(cleanup);
it(`Should render in the dom`, () => {
render();
expect(screen.queryByTestId(testId)).toBeTruthy();
});
it(`Should render the component in a state (hovered, normal, active)
that matches the state passed along in the settings prop`, () => {
// ACTIVE STATE
const { rerender } = render(
);
expect(screen.getByTestId(testId).style.backgroundColor).toBe(
"rgb(238, 238, 238)"
);
// HOVER STATE
rerender(
);
expect(screen.getByTestId(testId).style.backgroundColor).toBe(
"rgb(244, 244, 244)"
);
// NORMAL STATE
rerender(
);
expect(screen.getByTestId(testId).style.borderBottomColor).toBe("#DDD");
});
it(`Should display an icon based on the section type`, () => {
render();
expect(
screen
.getByTestId(testId)
.querySelector("svg")
.getAttribute("data-icon")
).toBe("window-maximize");
});
it(`Should show a label that represents the text provided in the label prop`, () => {
const label = "TESTING";
render();
expect(screen.queryByText(label)).toBeTruthy();
});
});
describe("Events > Tests", () => {
afterEach(cleanup);
it(`Should trigger the onClick event when it is clicked on`, () => {
const onClick = jest.fn();
render();
fireEvent.click(screen.getByTestId(testId));
expect(onClick).toBeCalled();
});
it(`Should trigger the onMouseEnter event when the user double-clicks on the section item`, () => {
const onMouseEnter = jest.fn();
render();
fireEvent.mouseEnter(screen.getByTestId(testId));
expect(onMouseEnter).toBeCalled();
});
it(`Should trigger the onMouseLeave event when the user's mouse leaves the section item`, () => {
const onMouseLeave = jest.fn();
render();
fireEvent.mouseLeave(screen.getByTestId(testId));
expect(onMouseLeave).toBeCalled();
});
it(`Should trigger the onDoubleClick event when it is double-clicked on`, () => {
const onDoubleClick = jest.fn();
render();
fireEvent.doubleClick(screen.getByTestId(testId));
expect(onDoubleClick).toBeCalled();
});
});