test : resolved comments & modified code

This commit is contained in:
Dinesh Katariya 2023-06-07 21:27:15 +05:30
parent 451f8034c7
commit 4e454b41d1
2 changed files with 32 additions and 34 deletions

View file

@ -0,0 +1,32 @@
import { ColorPaletteCustom } from "../../colors";
import {
getColorNameAndShadeFromColor,
colorPickerHotkeyBindings,
} from "./colorPickerUtils";
describe("getColorNameAndShadeFromColor", () => {
it("returns null when no matching color is found", () => {
const palette: ColorPaletteCustom = {
green: "#00FF00",
orange: "#E07C24",
};
const color = "#FF6666";
const result = getColorNameAndShadeFromColor({ palette, color });
expect(result).toBeNull();
});
});
describe("colorPickerHotkeyBindings", () => {
it("should contain all the expected hotkey bindings", () => {
const testBindingKeys = [
["q", "w", "e", "r", "t"],
["a", "s", "d", "f", "g"],
["z", "x", "c", "v", "b"],
].flat();
expect(testBindingKeys).toEqual(colorPickerHotkeyBindings);
});
});

View file

@ -1,34 +0,0 @@
import { ColorPaletteCustom } from "../../colors";
import {
getColorNameAndShadeFromColor,
colorPickerHotkeyBindings,
} from "./colorPickerUtils";
import { render, screen } from "@testing-library/react";
test("getColorNameAndShadeFromColor returns null when no matching color is found", () => {
const palette: ColorPaletteCustom = {
green: "#00FF00",
orange: "#E07C24",
};
const color = "#FF6666";
const result = getColorNameAndShadeFromColor({ palette, color });
expect(result).toBeNull();
});
describe('colorPickerHotkeyBindings', () => {
test('renders all hotkey bindings', () => {
render(
<div>
<h1>{colorPickerHotkeyBindings.join(',')}</h1>
</div>
);
colorPickerHotkeyBindings.forEach((hotkey) => {
const hotkeyElement = screen.getByText(hotkey);
expect(hotkeyElement).toBeInTheDocument();
});
});
});