import * as React from "react"; import { render, screen, fireEvent, cleanup } from "@testing-library/react"; import IconSelector from "./IconSelector"; import { treat } from "./IconSelector"; import { IconTypes } from "@sc/plugins/webcomponents/v2/Icon"; import { IconSelectorProps } from "./types"; const icons = Object.keys(IconTypes).filter( (itm) => itm.indexOf("Outlined") === -1 && itm.indexOf("Rounded") === -1 && itm.indexOf("Sharp") === -1 && itm.indexOf("TwoTone") === -1 ); const props: IconSelectorProps = {}; describe(" Rendering >", () => { afterEach(cleanup); it(`Should render the component in the dom`, () => { render(); expect(screen.queryByTestId("Properties-IconSelector")).toBeTruthy(); }); it(`Should display a large list of material icons in the dom`, () => { render(); expect(screen.queryAllByTestId("Properties-IconSelector-icon").length).toBe( icons.length ); }); }); describe(" Actions", () => { afterEach(cleanup); it("It should let me search and filter this list", () => { const searchString = "file"; render(); fireEvent.change(screen.getByPlaceholderText("Search for an icon..."), { target: { value: searchString }, }); expect(screen.queryAllByTestId("Properties-IconSelector-icon").length).toBe( icons.filter( (itm) => itm.toUpperCase().indexOf(searchString.toUpperCase()) > -1 || itm.toUpperCase().indexOf(treat(searchString).toUpperCase()) > -1 ).length ); }); }); describe(" Events", () => { afterEach(cleanup); it("Should trigger the onChange() event when an icon is selected", () => { const onChange = jest.fn(); // Render the Icon Selector render(); // Pick any of the icons const iconToClick = Math.floor(Math.random() * icons.length); // Click it fireEvent.click( screen.queryAllByTestId("Properties-IconSelector-icon")[iconToClick] ); expect(onChange).toBeCalled(); }); }); describe(" Hooks", () => { afterEach(cleanup); test.skip("Should trigger the _onIconSelect_ plugin hook when an icon is selected", () => { expect(true).toBe(true); }); test.skip("Should trigger the _onIconSelectorRender_ plugin hook when the component is being rendered", () => { expect(true).toBe(true); }); });