2022-03-09 10:59:44 +01:00
|
|
|
import ExcalidrawApp from "../excalidraw-app";
|
|
|
|
import { CODES } from "../keys";
|
|
|
|
import { API } from "../tests/helpers/api";
|
|
|
|
import { Keyboard, Pointer, UI } from "../tests/helpers/ui";
|
2023-05-18 16:06:27 +02:00
|
|
|
import {
|
|
|
|
act,
|
|
|
|
fireEvent,
|
|
|
|
render,
|
|
|
|
screen,
|
|
|
|
togglePopover,
|
|
|
|
} from "../tests/test-utils";
|
2022-03-09 10:59:44 +01:00
|
|
|
import { copiedStyles } from "./actionStyles";
|
|
|
|
|
|
|
|
const { h } = window;
|
|
|
|
|
|
|
|
const mouse = new Pointer("mouse");
|
|
|
|
|
|
|
|
describe("actionStyles", () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
await render(<ExcalidrawApp />);
|
|
|
|
});
|
2023-05-18 16:06:27 +02:00
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
// https://github.com/floating-ui/floating-ui/issues/1908#issuecomment-1301553793
|
|
|
|
// affects node v16+
|
|
|
|
await act(async () => {});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should copy & paste styles via keyboard", async () => {
|
2022-03-09 10:59:44 +01:00
|
|
|
UI.clickTool("rectangle");
|
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
|
|
|
UI.clickTool("rectangle");
|
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
|
|
|
// Change some styles of second rectangle
|
2023-05-18 16:06:27 +02:00
|
|
|
togglePopover("Stroke");
|
|
|
|
UI.clickOnTestId("color-red");
|
|
|
|
togglePopover("Background");
|
|
|
|
UI.clickOnTestId("color-blue");
|
2022-03-09 10:59:44 +01:00
|
|
|
// Fill style
|
|
|
|
fireEvent.click(screen.getByTitle("Cross-hatch"));
|
|
|
|
// Stroke width
|
|
|
|
fireEvent.click(screen.getByTitle("Bold"));
|
|
|
|
// Stroke style
|
|
|
|
fireEvent.click(screen.getByTitle("Dotted"));
|
|
|
|
// Roughness
|
|
|
|
fireEvent.click(screen.getByTitle("Cartoonist"));
|
|
|
|
// Opacity
|
|
|
|
fireEvent.change(screen.getByLabelText("Opacity"), {
|
|
|
|
target: { value: "60" },
|
|
|
|
});
|
|
|
|
|
|
|
|
mouse.reset();
|
|
|
|
|
|
|
|
API.setSelectedElements([h.elements[1]]);
|
|
|
|
|
|
|
|
Keyboard.withModifierKeys({ ctrl: true, alt: true }, () => {
|
|
|
|
Keyboard.codeDown(CODES.C);
|
|
|
|
});
|
2022-06-14 19:42:49 +05:30
|
|
|
const secondRect = JSON.parse(copiedStyles)[0];
|
2022-03-09 10:59:44 +01:00
|
|
|
expect(secondRect.id).toBe(h.elements[1].id);
|
|
|
|
|
|
|
|
mouse.reset();
|
|
|
|
// Paste styles to first rectangle
|
|
|
|
API.setSelectedElements([h.elements[0]]);
|
|
|
|
Keyboard.withModifierKeys({ ctrl: true, alt: true }, () => {
|
|
|
|
Keyboard.codeDown(CODES.V);
|
|
|
|
});
|
|
|
|
|
|
|
|
const firstRect = API.getSelectedElement();
|
|
|
|
expect(firstRect.id).toBe(h.elements[0].id);
|
2023-05-18 16:06:27 +02:00
|
|
|
expect(firstRect.strokeColor).toBe("#e03131");
|
|
|
|
expect(firstRect.backgroundColor).toBe("#a5d8ff");
|
2022-03-09 10:59:44 +01:00
|
|
|
expect(firstRect.fillStyle).toBe("cross-hatch");
|
|
|
|
expect(firstRect.strokeWidth).toBe(2); // Bold: 2
|
|
|
|
expect(firstRect.strokeStyle).toBe("dotted");
|
|
|
|
expect(firstRect.roughness).toBe(2); // Cartoonist: 2
|
|
|
|
expect(firstRect.opacity).toBe(60);
|
|
|
|
});
|
|
|
|
});
|