Skip to content

Commit

Permalink
Fix/use "new" to construct a new instance of Color (#227)
Browse files Browse the repository at this point in the history
* Add new

* Add tests

* Add tests
  • Loading branch information
schoinh authored Nov 8, 2021
1 parent bb1e0c7 commit b04cb56
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/simularium/VisGeometry/color-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
23 changes: 23 additions & 0 deletions src/test/color-utils.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});
});

0 comments on commit b04cb56

Please sign in to comment.