mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
test: modified code as per given comments
This commit is contained in:
parent
68db9a32ba
commit
04011ccfdd
1 changed files with 34 additions and 11 deletions
|
@ -2,7 +2,6 @@ import { ColorPaletteCustom } from "../../colors";
|
||||||
import { ExcalidrawElement } from "../../element/types";
|
import { ExcalidrawElement } from "../../element/types";
|
||||||
import {
|
import {
|
||||||
getColorNameAndShadeFromColor,
|
getColorNameAndShadeFromColor,
|
||||||
colorPickerHotkeyBindings,
|
|
||||||
isCustomColor,
|
isCustomColor,
|
||||||
getMostUsedCustomColors,
|
getMostUsedCustomColors,
|
||||||
} from "./colorPickerUtils";
|
} from "./colorPickerUtils";
|
||||||
|
@ -19,17 +18,41 @@ describe("getColorNameAndShadeFromColor", () => {
|
||||||
|
|
||||||
expect(result).toBeNull();
|
expect(result).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("returns color name and null when matching single color is found", () => {
|
||||||
|
const palette: ColorPaletteCustom = {
|
||||||
|
red: "#FF0000",
|
||||||
|
orange: "#FFA500",
|
||||||
|
yellow: "#FFFF00",
|
||||||
|
green: "#008000",
|
||||||
|
blue: "#0000FF",
|
||||||
|
indigo: "#4B0082",
|
||||||
|
violet: "#EE82EE",
|
||||||
|
pink: "#FFC0CB",
|
||||||
|
brown: "#A52A2A",
|
||||||
|
black: "#000000",
|
||||||
|
white: "#FFFFFF",
|
||||||
|
gray: "#808080",
|
||||||
|
};
|
||||||
|
|
||||||
|
const color = "#FF0000";
|
||||||
|
|
||||||
|
const result = getColorNameAndShadeFromColor({ palette, color });
|
||||||
|
|
||||||
|
expect(result).toEqual({colorName: "red", shade: null});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("colorPickerHotkeyBindings", () => {
|
it("returns color name and shade index when matching array of colors is found", () => {
|
||||||
it("should contain all the expected hotkey bindings", () => {
|
const palette: ColorPaletteCustom = {
|
||||||
const testBindingKeys = [
|
red: ["#FF0000", "#FF6666"],
|
||||||
["q", "w", "e", "r", "t"],
|
green: ["#00FF00"],
|
||||||
["a", "s", "d", "f", "g"],
|
};
|
||||||
["z", "x", "c", "v", "b"],
|
|
||||||
].flat();
|
|
||||||
|
|
||||||
expect(testBindingKeys).toEqual(colorPickerHotkeyBindings);
|
const color = "#FF6666";
|
||||||
|
|
||||||
|
const result = getColorNameAndShadeFromColor({ palette, color });
|
||||||
|
|
||||||
|
expect(result).toEqual({colorName: "red", shade: 1});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -119,7 +142,7 @@ describe("getMostUsedCustomColors", () => {
|
||||||
|
|
||||||
const result = getMostUsedCustomColors(elements, type, palette);
|
const result = getMostUsedCustomColors(elements, type, palette);
|
||||||
|
|
||||||
expect(result).toEqual(["#00FF00"]);
|
expect(result).toEqual(["#00FF00", "#0000FF"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle empty elements correctly", () => {
|
it("should handle empty elements correctly", () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue