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
109
110
111
112
|
import request from "../services/request";
import mlConfig from "../utils/aoml";
const networkRequest = `
c0 = 247, 247, 247
c0_name = White
c0_talking = 1
c2 = 247, 0, 57
c2_name = Red
c2_start = ~
c2_end = ~
c2_remove = 1
c2_talking = 1
c4 = 107, 198, 247
c4_name = Blue
c4_start = (
c4_end = )
c4_remove = 0
c4_talking = 0
c5 = 107, 198, 247
c5_name = Blue
c5_start = [
c5_end = ]
c5_remove = 1
c5_talking = 0
c6 = 107, 198, 247
c6_name = Blue
c6_start = |
c6_end = |
c6_remove = 0
c6_talking = 0
`;
// Mock the request module properly
jest.mock("../services/request", () => ({
__esModule: true,
default: jest.fn().mockResolvedValue(networkRequest),
request: jest.fn().mockResolvedValue(networkRequest)
}));
describe("mlConfig", () => {
beforeEach(() => {
// Clear all instances and calls to constructor and all methods:
jest.clearAllMocks();
});
it("Should make a network request", () => {
mlConfig("/");
expect(request).toHaveBeenCalledTimes(1);
});
});
describe("applyMarkdown", () => {
const config = mlConfig("/");
beforeEach(() => {
// Clear all instances and calls to constructor and all methods:
jest.clearAllMocks();
});
it("Should create an array of spans containing letters", async () => {
const word = `hello`;
const actual = await config.applyMarkdown(`hello`, `blue`);
let index = 0;
for (const element of actual) {
expect(element.innerHTML).toBe(word[index]);
index++;
}
});
it("Should add colors based on settings", async () => {
const config = mlConfig("/");
const actual = await config.applyMarkdown(`(heya)`, `blue`);
expect(actual[0].getAttribute("style")).toBe("color: rgb(107, 198, 247);");
});
it("Should keep a letter if remove = 0", async () => {
const config = mlConfig("/");
const actual = await config.applyMarkdown(`(What())Hey!`, `white`);
const expected = `(`;
expect(actual[5].innerHTML).toBe(expected);
});
it("Should remove a letter if remove = 1", async () => {
const config = mlConfig("/");
const actual = await config.applyMarkdown(`~What~()Hey!`, `white`);
const expected = ``;
expect(actual[0].innerHTML).toBe(expected);
});
it("Should remove a letter if remove = 1", async () => {
const config = mlConfig("/");
const actual = await config.applyMarkdown(`~What~()Hey!`, `white`);
const expected = ``;
expect(actual[0].innerHTML).toBe(expected);
});
it("Should keep a closing letter if remove = 0", async () => {
const config = mlConfig("/");
const actual = await config.applyMarkdown(`~NO[]~!`, `white`);
const expected = ``;
expect(actual[4].innerHTML).toBe(expected);
});
it("Should remove a closing letter if remove = 1", async () => {
const config = mlConfig("/");
const actual = await config.applyMarkdown(`~NO||~!`, `white`);
const expected = ``;
expect(actual[5].innerHTML).toBe(expected);
});
});
|