fix(editor): prevent duplicate lasso toolbar item (#11286)
This commit is contained in:
committed by
GitHub
parent
d992c10bc1
commit
b2b2815954
@@ -119,15 +119,12 @@ export const SHAPES = [
|
||||
export const getToolbarTools = (app: AppClassProperties) => {
|
||||
return app.state.preferredSelectionTool.type === "lasso"
|
||||
? ([
|
||||
SHAPES[0],
|
||||
{
|
||||
...SHAPES[1],
|
||||
value: "lasso",
|
||||
icon: SelectionIcon,
|
||||
key: KEYS.V,
|
||||
numericKey: KEYS["1"],
|
||||
fillable: true,
|
||||
toolbar: true,
|
||||
},
|
||||
...SHAPES.slice(1),
|
||||
...SHAPES.slice(2),
|
||||
] as const)
|
||||
: SHAPES;
|
||||
};
|
||||
|
||||
@@ -4,10 +4,12 @@ import { resolvablePromise } from "@excalidraw/common";
|
||||
|
||||
import { Excalidraw } from "../index";
|
||||
|
||||
import { getToolbarTools } from "../components/shapes";
|
||||
|
||||
import { Pointer } from "./helpers/ui";
|
||||
import { act, render } from "./test-utils";
|
||||
|
||||
import type { ExcalidrawImperativeAPI } from "../types";
|
||||
import type { AppClassProperties, ExcalidrawImperativeAPI } from "../types";
|
||||
|
||||
describe("setActiveTool()", () => {
|
||||
const h = window.h;
|
||||
@@ -66,3 +68,27 @@ describe("setActiveTool()", () => {
|
||||
expect(h.state.activeTool.customType).toBe("comment");
|
||||
});
|
||||
});
|
||||
describe("getToolbarTools()", () => {
|
||||
const getToolValues = (preferredSelectionTool: "selection" | "lasso") =>
|
||||
getToolbarTools({
|
||||
state: {
|
||||
preferredSelectionTool: {
|
||||
type: preferredSelectionTool,
|
||||
},
|
||||
},
|
||||
} as AppClassProperties).map((tool) => tool.value);
|
||||
|
||||
it("does not include lasso when selection is preferred", () => {
|
||||
const toolValues = getToolValues("selection");
|
||||
|
||||
expect(toolValues.filter((value) => value === "selection")).toHaveLength(1);
|
||||
expect(toolValues.filter((value) => value === "lasso")).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("replaces selection with lasso when lasso is preferred", () => {
|
||||
const toolValues = getToolValues("lasso");
|
||||
|
||||
expect(toolValues.filter((value) => value === "lasso")).toHaveLength(1);
|
||||
expect(toolValues.filter((value) => value === "selection")).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user