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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* global it, describe, expect, test */
import { emailFromCreatedBy, toArray, getUrl, isString, isStringEmpty, isStringJSON, toTimeString } from "../utilities";
 
describe("Helper function emailFromCreatedBy", () => {
  expect(emailFromCreatedBy("abc@def.com, 12")).toBe("abc@def.com");
  // empty username, not a rare case
  expect(emailFromCreatedBy(" abc@def.com, 12")).toBe("abc@def.com");
  expect(emailFromCreatedBy("usrnm abc@def.com, 12")).toBe("abc@def.com");
  // first and last name
  expect(emailFromCreatedBy("Abc Def ab.c+12@def.com.pt, 12")).toBe("ab.c+12@def.com.pt");
  // complex case
  expect(emailFromCreatedBy("Ab.C D@E.F ab.c+12@def.com.pt, 12")).toBe("ab.c+12@def.com.pt");
  // just a email, should not be a real case though
  expect(emailFromCreatedBy("ab.c+12@def.com.pt")).toBe("ab.c+12@def.com.pt");
});
 
describe("Helper function toArray, converting any value to array, skipping undefined values", () => {
  test("Empty", () => {
    expect(toArray()).toEqual([]);
  });
 
  test("Single value", () => {
    expect(toArray("value")).toEqual(["value"]);
  });
 
  test("Zero", () => {
    expect(toArray(0)).toEqual([0]);
  });
 
  test("Array", () => {
    expect(toArray(["value"])).toEqual(["value"]);
  });
});
 
/**
 * isString
 */
it("Function isString works", () => {
  expect(isString("value")).toBeTruthy();
});
 
/**
 * isStringEmpty
 */
describe("Helper function isStringEmpty", () => {
  test("Empty", () => {
    expect(isStringEmpty("")).toBeTruthy();
  });
 
  test("Not string", () => {
    expect(isStringEmpty(123)).toBeFalsy();
  });
 
  test("Not empty", () => {
    expect(isStringEmpty("value")).toBeFalsy();
  });
});
 
/**
 * isStringJSON
 */
describe("Helper function isStrinJSON", () => {
  test("JSON", () => {
    expect(isStringJSON('{"test": "value"}')).toBeTruthy();
  });
 
  test("String isn't JSON", () => {
    expect(isStringJSON("value")).toBeFalsy();
  });
 
  test("Number", () => {
    expect(isStringJSON(1)).toBeFalsy();
  });
 
  test("Null", () => {
    expect(isStringJSON(null)).toBeFalsy();
  });
});
 
/**
 * getUrl
 */
describe("Helper function getUrl", () => {
  test("Correct https", () => {
    expect(getUrl(0, "https://heartex.net testing value")).toBe("https://heartex.net");
  });
 
  test("Correct http", () => {
    expect(getUrl(0, "http://heartex.net testing value")).toBe("http://heartex.net");
  });
 
  test("Correct wwww", () => {
    expect(getUrl(0, "www.heartex.net testing value")).toBe("www.heartex.net");
  });
 
  test("Not correct", () => {
    expect(getUrl(2, "https://heartex.net testing value")).toBe("");
  });
});
 
/**
 * toTimeString
 */
describe("Helper function toTimeString", () => {
  test("Correct", () => {
    expect(toTimeString(5000)).toBe("00:00:05");
  });
});