generated from kawarimidoll/deno-dev-template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
render_html_test.ts
104 lines (96 loc) · 2.35 KB
/
render_html_test.ts
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
import { AMP, assertEquals, assertThrows, GT, LT, QUOT } from "./deps.ts";
import { DENOTE_LOGO, icongram, loadConfig, sanitize } from "./render_html.ts";
import { ConfigObject } from "./types.ts";
Deno.test("sanitize", () => {
assertEquals(sanitize(""), "");
assertEquals(sanitize("normal text"), "normal text");
assertEquals(sanitize("<chevron>"), LT + "chevron" + GT);
assertEquals(
sanitize(`and & "quotes"`),
"and " + AMP + " " + QUOT + "quotes" + QUOT,
);
});
Deno.test("loadConfig", () => {
const config: Partial<ConfigObject> = {
description: "<description>",
twitter: "twitter",
list: {
id1: {
icon: "feather/github",
items: [
{
icon: "feather/github",
link: "http://github.com",
},
],
},
id2: {
icon: "devicons/gitlab",
items: [
{
text: "gitlab",
},
],
},
},
};
const processed: ConfigObject = {
name: "Your name will be here",
disable: [],
description: "<description>",
image: "",
favicon: DENOTE_LOGO,
twitter: "@twitter",
list: {
id1: {
icon: "feather/github",
items: [
{
icon: "feather/github",
text: "",
link: "http://github.com",
},
],
},
id2: {
icon: "devicons/gitlab",
items: [
{
icon: undefined,
text: "gitlab",
link: "",
},
],
},
},
};
assertEquals(loadConfig(config), processed);
assertThrows(() => {
loadConfig({
name: "",
disable: [],
twitter: "",
description: "",
image: "",
favicon: "",
list: {},
});
});
});
Deno.test("icongram", () => {
assertEquals(
icongram("clarity/github"),
`<img src="https://icongr.am/clarity/github.svg?size=20&color=f0ffff" alt="clarity/github">`,
);
assertEquals(
icongram("jam/flower", 30),
`<img src="https://icongr.am/jam/flower.svg?size=30&color=f0ffff" alt="jam/flower">`,
);
assertEquals(
icongram("feather/external-link", 12, { class: "ex-link" }),
`<img src="https://icongr.am/feather/external-link.svg?size=12&color=f0ffff" alt="feather/external-link" class="ex-link">`,
);
assertThrows(() => {
icongram("foo");
});
});