Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* global describe, test, expect, it */
import { colorToRGBA, convertToRGBA, hexToRGBA, stringToColor } from "../colors";
 
const defaultRGBA = "rgba(255, 255, 255, 0.1)";
const defaultHEX = {
  short: "#fff",
  long: "#ffffff",
  alpha: 0.1,
};
const randomString = {
  str: "white",
  value: "#29ccbd",
};
 
describe("Helper function hexToRGBA", () => {
  test("3 dig", () => {
    expect(hexToRGBA(defaultHEX.short, defaultHEX.alpha)).toBe(defaultRGBA);
  });
 
  test("6 dig", () => {
    expect(hexToRGBA(defaultHEX.long, defaultHEX.alpha)).toBe(defaultRGBA);
  });
});
 
describe("Helper function convertToRGBA", () => {
  test("Convert to RGBA, color", () => {
    expect(convertToRGBA(randomString.str, defaultHEX.alpha)).toBe(defaultRGBA);
  });
 
  test("Convert to RGBA, HEX", () => {
    expect(convertToRGBA(defaultHEX.short, defaultHEX.alpha)).toBe(defaultRGBA);
    expect(convertToRGBA(defaultHEX.long, defaultHEX.alpha)).toBe(defaultRGBA);
  });
});
 
describe("Helper function colorToRGBA", () => {
  test("Good", () => {
    expect(colorToRGBA(randomString.str, defaultHEX.alpha)).toBe(defaultRGBA);
  });
 
  test("Undefind", () => {
    expect(colorToRGBA(undefined, defaultHEX.alpha)).toBeUndefined();
  });
 
  test("Random string", () => {
    expect(colorToRGBA("RANDOM", defaultHEX.alpha)).toBe("rgba(0, 0, 0, 0.1)");
  });
});
 
it("Helper function stringToColor", () => {
  expect(stringToColor(randomString.str)).toBe(randomString.value);
});