From b04cb569d96ed582af76fd937b8547b293985005 Mon Sep 17 00:00:00 2001 From: Na Hyung Choi Date: Mon, 8 Nov 2021 13:51:05 -0800 Subject: [PATCH] Fix/use "new" to construct a new instance of Color (#227) * Add new * Add tests * Add tests --- src/simularium/VisGeometry/color-utils.ts | 2 +- src/test/color-utils.test.ts | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/test/color-utils.test.ts diff --git a/src/simularium/VisGeometry/color-utils.ts b/src/simularium/VisGeometry/color-utils.ts index 24a96a61..89fbafea 100644 --- a/src/simularium/VisGeometry/color-utils.ts +++ b/src/simularium/VisGeometry/color-utils.ts @@ -11,5 +11,5 @@ export function convertColorNumberToString(color: number | string): string { if (typeof color === "string") { return color; } - return "#" + Color(color).getHexString(); + return "#" + new Color(color).getHexString(); } diff --git a/src/test/color-utils.test.ts b/src/test/color-utils.test.ts new file mode 100644 index 00000000..0badbac7 --- /dev/null +++ b/src/test/color-utils.test.ts @@ -0,0 +1,23 @@ +import { + convertColorStringToNumber, + convertColorNumberToString, +} from "../simularium/VisGeometry/color-utils"; + +describe("VisGeometry color-utils", () => { + describe("convertColorStringToNumber", () => { + test("returns a color number as is", () => { + expect(convertColorStringToNumber(16777215)).toEqual(16777215); + }); + test("converts a hex color string to a base-16 number", () => { + expect(convertColorStringToNumber("#ffffff")).toEqual(16777215); + }); + }); + describe("convertColorNumberToString", () => { + test("returns a color string as is", () => { + expect(convertColorNumberToString("#ffffff")).toEqual("#ffffff"); + }); + test("converts a base-16 color number to a hex color string", () => { + expect(convertColorNumberToString(16777215)).toEqual("#ffffff"); + }); + }); +});