forked from camptocamp/ogc-client
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathurl-utils.spec.ts
More file actions
66 lines (65 loc) · 2.31 KB
/
url-utils.spec.ts
File metadata and controls
66 lines (65 loc) · 2.31 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
import { getChildPath, getParentPath, getBaseUrl } from './url-utils.js';
describe('link utils', () => {
describe('getBaseUrl', () => {
it('should return the base url', () => {
expect(getBaseUrl().toString()).toBe('http://localhost/');
expect(getBaseUrl('http://example.com').toString()).toBe(
'http://example.com/'
);
});
});
describe('getParentPath', () => {
it('should return null if no parent path', () => {
expect(getParentPath('http://example.com')).toBeNull();
});
it('should return null if parent path is /', () => {
expect(getParentPath('http://example.com/foo')).toBeNull();
});
it('should return root path correctly if a trailing slash is present', () => {
expect(getParentPath('http://example.com/foo/')).toBe(
'http://example.com/'
);
});
it('should return the parent path', () => {
expect(getParentPath('http://example.com/foo/bar/baz')).toBe(
'http://example.com/foo/bar'
);
});
it('should return the parent path (including a trailing slash if on the app context part', () => {
expect(getParentPath('http://example.com/foo/bar')).toBe(
'http://example.com/foo/'
);
});
it('should ignore a trailing slash', () => {
expect(getParentPath('http://example.com/foo/bar/baz/')).toBe(
'http://example.com/foo/bar'
);
});
it('should keep query params', () => {
expect(getParentPath('http://example.com/foo/bar?aa=bb')).toBe(
'http://example.com/foo/?aa=bb'
);
expect(getParentPath('http://example.com/foo/bar?')).toBe(
'http://example.com/foo/?'
);
expect(getParentPath('http://example.com/foo/bar/baz?aa=bb')).toBe(
'http://example.com/foo/bar?aa=bb'
);
expect(getParentPath('http://example.com/foo/bar/baz?')).toBe(
'http://example.com/foo/bar?'
);
});
});
describe('getChildPath', () => {
it('should append a child fragment to the path', () => {
expect(getChildPath('http://example.com/foo/', 'bar/')).toBe(
'http://example.com/foo/bar/'
);
});
it('should append a child fragment to the path with a slash in-between', () => {
expect(getChildPath('http://example.com/foo', 'bar')).toBe(
'http://example.com/foo/bar'
);
});
});
});