test: modified code as per given comments

This commit is contained in:
Dinesh Katariya 2023-07-21 11:31:33 +05:30
parent 68db9a32ba
commit 04011ccfdd

View file

@ -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();
}); });
});
describe("colorPickerHotkeyBindings", () => { it("returns color name and null when matching single color is found", () => {
it("should contain all the expected hotkey bindings", () => { const palette: ColorPaletteCustom = {
const testBindingKeys = [ red: "#FF0000",
["q", "w", "e", "r", "t"], orange: "#FFA500",
["a", "s", "d", "f", "g"], yellow: "#FFFF00",
["z", "x", "c", "v", "b"], green: "#008000",
].flat(); blue: "#0000FF",
indigo: "#4B0082",
violet: "#EE82EE",
pink: "#FFC0CB",
brown: "#A52A2A",
black: "#000000",
white: "#FFFFFF",
gray: "#808080",
};
expect(testBindingKeys).toEqual(colorPickerHotkeyBindings); const color = "#FF0000";
const result = getColorNameAndShadeFromColor({ palette, color });
expect(result).toEqual({colorName: "red", shade: null});
});
it("returns color name and shade index when matching array of colors is found", () => {
const palette: ColorPaletteCustom = {
red: ["#FF0000", "#FF6666"],
green: ["#00FF00"],
};
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", () => {