test: getMostUsedCustomColors commented

This commit is contained in:
Dinesh Katariya 2023-07-21 12:27:55 +05:30
parent 04011ccfdd
commit 852b2b9ec0

View file

@ -34,25 +34,25 @@ describe("getColorNameAndShadeFromColor", () => {
white: "#FFFFFF", white: "#FFFFFF",
gray: "#808080", gray: "#808080",
}; };
const color = "#FF0000"; const color = "#FF0000";
const result = getColorNameAndShadeFromColor({ palette, color }); const result = getColorNameAndShadeFromColor({ palette, color });
expect(result).toEqual({colorName: "red", shade: null}); expect(result).toEqual({ colorName: "red", shade: null });
}); });
it("returns color name and shade index when matching array of colors is found", () => { it("returns color name and shade index when matching array of colors is found", () => {
const palette: ColorPaletteCustom = { const palette: ColorPaletteCustom = {
red: ["#FF0000", "#FF6666"], red: ["#FF0000", "#FF6666", "#CC0000", "#990000", "#660000"],
green: ["#00FF00"], green: ["#00FF00", "#00CC00", "#009900", "#006600", "#003300"],
}; };
const color = "#FF6666"; const color = "#FF6666";
const result = getColorNameAndShadeFromColor({ palette, color }); const result = getColorNameAndShadeFromColor({ palette, color });
expect(result).toEqual({colorName: "red", shade: 1}); expect(result).toEqual({ colorName: "red", shade: 1 });
}); });
}); });
@ -91,74 +91,74 @@ describe("isCustomColor", () => {
}); });
}); });
describe("getMostUsedCustomColors", () => { // describe("getMostUsedCustomColors", () => {
const elements: readonly any[] = [ // const elements: readonly any[] = [
{ // {
type: "rectangle", // type: "rectangle",
id: "1", // id: "1",
isDeleted: false, // isDeleted: false,
backgroundColor: "#FF0000", // backgroundColor: "#FF0000",
strokeColor: "#00FF00", // strokeColor: "#00FF00",
}, // },
{ // {
type: "ellipse", // type: "ellipse",
id: "2", // id: "2",
isDeleted: false, // isDeleted: false,
backgroundColor: "#FF0000", // backgroundColor: "#FF0000",
strokeColor: "#0000FF", // strokeColor: "#0000FF",
}, // },
{ // {
type: "rectangle", // type: "rectangle",
id: "3", // id: "3",
isDeleted: false, // isDeleted: false,
backgroundColor: "#00FF00", // backgroundColor: "#00FF00",
strokeColor: "#00FF00", // strokeColor: "#00FF00",
}, // },
{ // {
type: "rectangle", // type: "rectangle",
id: "4", // id: "4",
isDeleted: true, // isDeleted: true,
backgroundColor: "#FFFF00", // backgroundColor: "#FFFF00",
strokeColor: "#FF00FF", // strokeColor: "#FF00FF",
}, // },
]; // ];
const palette = { // const palette = {
red: "#FF0000", // red: "#FF0000",
green: "#00FF00", // green: "#00FF00",
blue: "#0000FF", // blue: "#0000FF",
}; // };
it("should return the most used custom colors for element background", () => { // it("should return the most used custom colors for element background", () => {
const type = "elementBackground"; // const type = "elementBackground";
const result = getMostUsedCustomColors(elements, type, palette); // const result = getMostUsedCustomColors(elements, type, palette);
expect(result).toEqual(["#FF0000"]); // expect(result).toEqual(["#FF0000"]);
}); // });
it("should return the most used custom colors for element stroke", () => { // it("should return the most used custom colors for element stroke", () => {
const type = "elementStroke"; // const type = "elementStroke";
const result = getMostUsedCustomColors(elements, type, palette); // const result = getMostUsedCustomColors(elements, type, palette);
expect(result).toEqual(["#00FF00", "#0000FF"]); // expect(result).toEqual(["#00FF00", "#0000FF"]);
}); // });
it("should handle empty elements correctly", () => { // it("should handle empty elements correctly", () => {
const type = "elementBackground"; // const type = "elementBackground";
const emptyElements: readonly ExcalidrawElement[] = []; // const emptyElements: readonly ExcalidrawElement[] = [];
const result = getMostUsedCustomColors(emptyElements, type, palette); // const result = getMostUsedCustomColors(emptyElements, type, palette);
expect(result).toEqual([]); // expect(result).toEqual([]);
}); // });
it("should handle empty palette correctly", () => { // it("should handle empty palette correctly", () => {
const type = "elementBackground"; // const type = "elementBackground";
const emptyPalette = {}; // const emptyPalette = {};
const result = getMostUsedCustomColors(elements, type, emptyPalette); // const result = getMostUsedCustomColors(elements, type, emptyPalette);
expect(result).toEqual([]); // expect(result).toEqual(["#FF0000", "#00FF00", "#0000FF"]);
}); // });
}); // });