2021-02-06 21:22:28 +05:30
|
|
|
import React from "react";
|
|
|
|
import { fireEvent, GlobalTestState, render } from "./test-utils";
|
|
|
|
import Excalidraw from "../packages/excalidraw/index";
|
2021-03-15 11:33:46 -07:00
|
|
|
import { queryByText, queryByTestId } from "@testing-library/react";
|
2021-02-06 21:22:28 +05:30
|
|
|
import { GRID_SIZE } from "../constants";
|
|
|
|
|
|
|
|
const { h } = window;
|
|
|
|
|
|
|
|
describe("<Excalidraw/>", () => {
|
|
|
|
describe("Test zenModeEnabled prop", () => {
|
|
|
|
it('should show exit zen mode button when zen mode is set and zen mode option in context menu when zenModeEnabled is "undefined"', async () => {
|
|
|
|
const { container } = await render(<Excalidraw />);
|
|
|
|
expect(
|
|
|
|
container.getElementsByClassName("disable-zen-mode--visible").length,
|
|
|
|
).toBe(0);
|
|
|
|
expect(h.state.zenModeEnabled).toBe(false);
|
|
|
|
|
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 1,
|
|
|
|
clientY: 1,
|
|
|
|
});
|
|
|
|
const contextMenu = document.querySelector(".context-menu");
|
|
|
|
fireEvent.click(queryByText(contextMenu as HTMLElement, "Zen mode")!);
|
|
|
|
expect(h.state.zenModeEnabled).toBe(true);
|
|
|
|
expect(
|
|
|
|
container.getElementsByClassName("disable-zen-mode--visible").length,
|
|
|
|
).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not show exit zen mode button and zen mode option in context menu when zenModeEnabled is set", async () => {
|
|
|
|
const { container } = await render(<Excalidraw zenModeEnabled={true} />);
|
|
|
|
expect(
|
|
|
|
container.getElementsByClassName("disable-zen-mode--visible").length,
|
|
|
|
).toBe(0);
|
|
|
|
expect(h.state.zenModeEnabled).toBe(true);
|
|
|
|
|
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 1,
|
|
|
|
clientY: 1,
|
|
|
|
});
|
|
|
|
const contextMenu = document.querySelector(".context-menu");
|
|
|
|
expect(queryByText(contextMenu as HTMLElement, "Zen mode")).toBe(null);
|
|
|
|
expect(h.state.zenModeEnabled).toBe(true);
|
|
|
|
expect(
|
|
|
|
container.getElementsByClassName("disable-zen-mode--visible").length,
|
|
|
|
).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Test gridModeEnabled prop", () => {
|
|
|
|
it('should show grid mode in context menu when gridModeEnabled is "undefined"', async () => {
|
|
|
|
const { container } = await render(<Excalidraw />);
|
|
|
|
expect(h.state.gridSize).toBe(null);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
container.getElementsByClassName("disable-zen-mode--visible").length,
|
|
|
|
).toBe(0);
|
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 1,
|
|
|
|
clientY: 1,
|
|
|
|
});
|
|
|
|
const contextMenu = document.querySelector(".context-menu");
|
|
|
|
fireEvent.click(queryByText(contextMenu as HTMLElement, "Show grid")!);
|
|
|
|
expect(h.state.gridSize).toBe(GRID_SIZE);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not show grid mode in context menu when gridModeEnabled is not "undefined"', async () => {
|
|
|
|
const { container } = await render(
|
|
|
|
<Excalidraw gridModeEnabled={false} />,
|
|
|
|
);
|
|
|
|
expect(h.state.gridSize).toBe(null);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
container.getElementsByClassName("disable-zen-mode--visible").length,
|
|
|
|
).toBe(0);
|
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 1,
|
|
|
|
clientY: 1,
|
|
|
|
});
|
|
|
|
const contextMenu = document.querySelector(".context-menu");
|
|
|
|
expect(queryByText(contextMenu as HTMLElement, "Show grid")).toBe(null);
|
|
|
|
expect(h.state.gridSize).toBe(null);
|
|
|
|
});
|
|
|
|
});
|
2021-03-15 11:33:46 -07:00
|
|
|
|
|
|
|
describe("Test theme prop", () => {
|
|
|
|
it('should show the dark mode toggle when the theme prop is "undefined"', async () => {
|
|
|
|
const { container } = await render(<Excalidraw />);
|
|
|
|
expect(h.state.theme).toBe("light");
|
|
|
|
|
|
|
|
const darkModeToggle = queryByTestId(container, "toggle-dark-mode");
|
|
|
|
|
|
|
|
expect(darkModeToggle).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not show the dark mode toggle when the theme prop is not "undefined"', async () => {
|
|
|
|
const { container } = await render(<Excalidraw theme="dark" />);
|
|
|
|
expect(h.state.theme).toBe("dark");
|
|
|
|
|
|
|
|
expect(queryByTestId(container, "toggle-dark-mode")).toBe(null);
|
|
|
|
});
|
|
|
|
});
|
2021-02-06 21:22:28 +05:30
|
|
|
});
|