-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathhtml.test.ts
140 lines (124 loc) · 4.08 KB
/
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { Description, Field, InputValue, SchemaType } from "../interface";
import { split, HTML } from "./html";
import { data } from "../../test/empty.schema.json";
test("utility/html.split", () => {
const LOREM_IPSU = `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.`;
expect(split("", 0)).toEqual([""]);
expect(split(LOREM_IPSU, 1)).toEqual(LOREM_IPSU.split(" "));
expect(split(LOREM_IPSU, 10)).toEqual([
"Lorem Ipsum",
"is simply dummy",
"text of the",
"printing and",
"typesetting",
"industry. Lorem",
"Ipsum has been",
"the industry's",
"standard dummy",
"text ever since",
"the 1500s,",
"when an unknown",
"printer took",
"a galley of",
"type and scrambled",
"it to make",
"a type specimen",
"book.",
]);
expect(split(LOREM_IPSU, 100)).toEqual([
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's",
"standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled",
"it to make a type specimen book.",
]);
});
describe("lib/utility/html#HTML", () => {
test(".code", () => {
const html = new HTML();
expect(html.code("CODE")).toBe(
'<code class="highlight"><table class="code"><tbody>CODE</tbody></table></code>'
);
});
test(".highlight", () => {
const html = new HTML();
expect(html.highlight("CODE")).toBe("<strong>CODE</strong>");
});
test(".sup", () => {
const html = new HTML();
expect(html.sup("CODE")).toBe(" <sup>CODE</sup>");
});
test(".line", () => {
const html = new HTML();
expect(html.index).toBe(1);
expect(html.line("CODE")).toBe(
'<tr class="row"><td id="L1" class="td-index">1</td><td id="LC1" class="td-code">CODE</td></tr>'
);
expect(html.index).toBe(2);
});
test(".tab", () => {
const html = new HTML();
expect(html.tab("CODE")).toBe('<span class="tab">CODE</span>');
});
test(".keyword", () => {
const html = new HTML();
expect(html.keyword("CODE")).toBe(
'<span class="keyword operator ts">CODE</span>'
);
});
test(".comment", () => {
const html = new HTML();
expect(html.comment("CODE")).toBe(
'<span class="comment line"># CODE</span>'
);
});
test(".identifier", () => {
const html = new HTML();
const type = data.__schema.types.find((t) => t.name === "Query");
expect(html.identifier(type as Description)).toBe(
'<span class="identifier">Query</span>'
);
});
test(".parameter", () => {
const html = new HTML();
const input: InputValue = data.__schema.types.find(
(t) => t.name === "AddCommentInput"
) as any;
expect(html.parameter(input)).toBe(
'<span class="variable parameter">AddCommentInput</span>'
);
});
test(".property", () => {
const html = new HTML();
expect(html.property("PROPERTY")).toBe(
'<span class="meta">PROPERTY</span>'
);
});
test(".useIdentifier", () => {
const html = new HTML();
const schema: SchemaType = data.__schema.types.find(
(t) => t.name === "__Schema"
) as any;
const field: Field = (schema.fields || []).find(
(f) => f.name === "types"
) as any;
expect(html.useIdentifier(field.type, "HREF")).toBe(
'[<a class="support type" href="HREF">__Type</a>!]!'
);
});
test(".useIdentifierLength", () => {
const html = new HTML();
const schema: SchemaType = data.__schema.types.find(
(t) => t.name === "__Schema"
) as any;
const field: Field = (schema.fields || []).find(
(f) => f.name === "types"
) as any;
expect(html.useIdentifierLength(field.type)).toBe(10);
});
test(".value", () => {
const html = new HTML();
expect(html.value('"STRING"')).toBe('<span class="string">"STRING"</span>');
expect(html.value("NUMBER")).toBe(
'<span class="constant numeric">NUMBER</span>'
);
});
});