forked from NullVoxPopuli/limber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmocks.ts
94 lines (77 loc) · 1.99 KB
/
mocks.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
import Service from '@ember/service';
/**
* Build the structure used by the docs service for mocking.
*/
function makeDocsTree(treeData: [string, string[]][]) {
const pages = [];
for (const [groupName, tutorialNames] of treeData) {
const groupPath = groupName
.toLowerCase()
.replace(/ /g, '-')
.replace(/[^a-z0-9-]/g, '');
const groupPages = [];
for (const tutorialName of tutorialNames) {
const tutorialPath = tutorialName
.toLowerCase()
.replace(/ /g, '-')
.replace(/[^a-z0-9-]/g, '');
const prosePath = `/${groupPath}/${tutorialPath}/prose.md`;
const page = {
path: tutorialPath,
name: tutorialName,
cleanedName: tutorialName.replace(/-/g, ' '),
pages: [
{
path: prosePath,
name: 'prose',
groupName: tutorialName.replace(/-/g, ' '),
cleanedName: 'prose',
},
],
first: prosePath,
};
groupPages.push(page);
}
const group = {
path: groupPath,
name: groupName,
cleanedName: groupName.replace(/-/g, ' '),
pages: groupPages,
first: `/${groupPath}/${groupPages[0]?.path}/prose.md`,
};
pages.push(group);
}
return {
name: 'root',
pages,
path: 'root',
first: `/${pages[0]?.path}/${pages[0]?.pages[0]?.path}/prose.md`,
};
}
export class MockDocsService extends Service {
#groupsTree = {};
#currentPath = '/';
get grouped() {
return this.#groupsTree;
}
get currentPath() {
return this.#currentPath;
}
// Test extension
_setGroupsData(treeData: [string, string[]][]) {
this.#groupsTree = makeDocsTree(treeData);
}
_setCurrentPath(path: string) {
this.#currentPath = path;
}
}
export class MockRouterService extends Service {
transitionTo(newRoute: string) {
this._assert.step(`transition to: ${newRoute}`);
}
// Test extension
_assert!: Assert;
_setAssert(assert: Assert) {
this._assert = assert;
}
}