-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathbuild-reference.test.ts
More file actions
118 lines (107 loc) · 3.42 KB
/
build-reference.test.ts
File metadata and controls
118 lines (107 loc) · 3.42 KB
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
import { beforeEach, describe, expect, test } from "vitest";
import { testingExports } from "../../src/scripts/builders/reference";
const {
addDocToModulePathTree,
modulePathTree,
addMemberMethodPreviewsToClassDocs,
memberMethodPreviews,
correctRelativeLinksInDescription,
} = testingExports;
const defaultDoc = {
name: "exampleMethod",
class: "ExampleClass",
module: "TestModule",
file: "path/to/file",
line: 1,
type: "method",
itemtype: "method" as "method" | "property",
submodule: "",
description: "example description",
chainable: 1,
};
let doc = { ...defaultDoc };
const path = "expected/path/to";
describe("modulePathTree", () => {
beforeEach(() => {
modulePathTree.modules = {};
modulePathTree.classes = {};
doc = { ...defaultDoc };
});
test("should add a class item correctly", () => {
const expectedPath = `${path}/exampleClass`;
doc.name = "exampleClass";
addDocToModulePathTree(doc, path);
expect(modulePathTree.classes["ExampleClass"]["exampleClass"]).toBe(
expectedPath,
);
});
test("should add a global item correctly", () => {
const expectedPath = `${path}/exampleMethod`;
doc.class = "p5";
addDocToModulePathTree(doc, path);
expect(modulePathTree.modules["TestModule"]["exampleMethod"]).toBe(
expectedPath,
);
});
test("should add a submodule item correctly", () => {
const expectedPath = `${path}/exampleMethod`;
doc.submodule = "TestSubmodule";
doc.class = "p5";
addDocToModulePathTree(doc, path);
expect(
(
modulePathTree.modules["TestModule"]["TestSubmodule"] as Record<
string,
string
>
)["exampleMethod"],
).toBe(expectedPath);
});
});
describe("modulePathTree with method previews", () => {
beforeEach(() => {
modulePathTree.modules = {};
modulePathTree.classes = {};
doc = { ...defaultDoc };
});
test("should add a method preview correctly", () => {
doc.class = "p5.TestClass";
doc.name = "exampleClassMethod";
doc.itemtype = "method";
doc.description = "test method description";
const expectedPath = `${path}/exampleClassMethod`;
addDocToModulePathTree(doc, path);
addMemberMethodPreviewsToClassDocs(doc);
expect(
memberMethodPreviews["p5.TestClass"].methods?.["exampleClassMethod"]
.description,
).toBe("test method description");
expect(
memberMethodPreviews["p5.TestClass"].methods?.["exampleClassMethod"].path,
).toBe(expectedPath);
});
test("should add a property preview correctly", () => {
doc.class = "p5.TestClass";
doc.name = "exampleClassProperty";
doc.itemtype = "property";
doc.description = "test property description";
const expectedPath = `${path}/exampleClassProperty`;
addDocToModulePathTree(doc, path);
addMemberMethodPreviewsToClassDocs(doc);
expect(
memberMethodPreviews["p5.TestClass"].properties?.["exampleClassProperty"]
.description,
).toBe("test property description");
expect(
memberMethodPreviews["p5.TestClass"].properties?.["exampleClassProperty"]
.path,
).toBe(expectedPath);
});
});
describe("correctRelativeLinksInDescription", () => {
test("should not add trailing slash to external URLs in descriptions", () => {
const input =
'<p><a href="https://en.wikipedia.org/wiki/Animation">Animation</a></p>';
expect(correctRelativeLinksInDescription(input)).toEqual(input);
});
});