-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
/
Copy pathrouter-history-base.test.js
100 lines (80 loc) · 3 KB
/
router-history-base.test.js
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
import { History } from '../../src/core/router/history/base.js';
class MockHistory extends History {
parse(path) {
return { path };
}
}
// Suite
// -----------------------------------------------------------------------------
describe('router/history/base', () => {
// Setup & Teardown
// ---------------------------------------------------------------------------
let history;
// resolvePath: true
// ---------------------------------------------------------------------------
describe('relativePath: true', () => {
// Setup & Teardown
// -------------------------------------------------------------------------
beforeEach(() => {
history = new MockHistory({ relativePath: true });
});
// Tests
// -------------------------------------------------------------------------
test('toURL', () => {
const url = history.toURL('guide.md', {}, '/zh-ch/');
expect(url).toBe('/zh-ch/guide');
});
test('toURL with double dot', () => {
const url = history.toURL('../README.md', {}, '/zh-ch/');
expect(url).toBe('/README');
});
test('toURL child path', () => {
const url = history.toURL('config/example.md', {}, '/zh-ch/');
expect(url).toBe('/zh-ch/config/example');
});
test('toURL absolute path', () => {
const url = history.toURL('/README', {}, '/zh-ch/');
expect(url).toBe('/README');
});
});
// resolvePath: false
// ---------------------------------------------------------------------------
describe('relativePath: false', () => {
// Setup & Teardown
// -------------------------------------------------------------------------
beforeEach(() => {
history = new MockHistory({ relativePath: false });
});
// Tests
// -------------------------------------------------------------------------
test('toURL', () => {
const url = history.toURL('README', {}, '/zh-ch/');
expect(url).toBe('/README');
});
});
// getFile test
// ---------------------------------------------------------------------------
describe('getFile', () => {
// Tests
// -------------------------------------------------------------------------
test('path is url', () => {
const file = history.getFile('https://some/raw/url/README.md');
expect(file).toBe('https://some/raw/url/README.md');
});
test('path is url, but ext is .html', () => {
const file = history.getFile('https://foo.com/index.html');
expect(file).toBe('https://foo.com/index.html');
});
test('path is url, but with parameters', () => {
const file = history.getFile(
'https://some/raw/url/README.md?token=Mytoken',
);
expect(file).toBe('https://some/raw/url/README.md?token=Mytoken');
});
test('path is url, but ext is different', () => {
history = new MockHistory({ ext: '.ext' });
const file = history.getFile('https://some/raw/url/README.md');
expect(file).toBe('https://some/raw/url/README.md.ext');
});
});
});