forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
url.spec.ts
98 lines (74 loc) · 2.55 KB
/
url.spec.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
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import {
expect
} from 'chai';
import {
URLExt
} from '@jupyterlab/coreutils';
describe('@jupyterlab/coreutils', () => {
describe('URLExt', () => {
describe('.parse()', () => {
it('should parse a url into a URLExt object', () => {
let obj = URLExt.parse('http://www.example.com');
expect(obj.href).to.equal('http://www.example.com/');
expect(obj.protocol).to.equal('http:');
expect(obj.host).to.equal('www.example.com');
expect(obj.hostname).to.equal('www.example.com');
expect(obj.pathname).to.equal('/');
});
it('should handle query and hash', () => {
let url = 'http://example.com/path?that\'s#all, folks';
let obj = URLExt.parse(url);
try {
expect(obj.href).to.equal(
'http://example.com/path?that%27s#all,%20folks'
);
} catch (e) {
// Chrome
expect(obj.href).to.equal(
'http://example.com/path?that%27s#all, folks'
);
}
expect(obj.protocol).to.equal('http:');
expect(obj.host).to.equal('example.com');
expect(obj.hostname).to.equal('example.com');
expect(obj.search).to.equal('?that%27s');
expect(obj.pathname).to.equal('/path');
try {
expect(obj.hash).to.equal('#all,%20folks');
} catch (e) {
// Chrome
expect(obj.hash).to.equal('#all, folks');
}
});
});
describe('.join()', () => {
it('should join a sequence of url components', () => {
expect(URLExt.join('/foo/', 'bar/')).to.equal('/foo/bar/');
});
});
describe('.encodeParts()', () => {
it('should encode and join a sequence of url components', () => {
expect(URLExt.encodeParts('>/>')).to.equal('%3E/%3E');
});
});
describe('objectToQueryString()', () => {
it('should return a serialized object string suitable for a query', () => {
let obj = {
name: 'foo',
id: 'baz'
};
expect(URLExt.objectToQueryString(obj)).to.equal('?name=foo&id=baz');
});
});
describe('.isLocal()', () => {
it('should test whether the url is a local url', () => {
expect(URLExt.isLocal('//foo')).to.equal(false);
expect(URLExt.isLocal('http://foo')).to.equal(false);
expect(URLExt.isLocal('/foo/bar')).to.equal(true);
expect(URLExt.isLocal('foo.txt')).to.equal(true);
});
});
});
});