forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
url.test.tsx
54 lines (49 loc) · 2.1 KB
/
url.test.tsx
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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {getSiteURLFromWindowObject, getRelativeChannelURL} from 'utils/url';
describe('Utils.URL', () => {
test('getRelativeChannelURL', () => {
expect(getRelativeChannelURL('teamName', 'channelName')).toEqual('/teamName/channels/channelName');
});
describe('getSiteURL', () => {
const testCases = [
{
description: 'origin',
location: {origin: 'http:https://example.com:8065', protocol: '', hostname: '', port: ''},
basename: '',
expectedSiteURL: 'http:https://example.com:8065',
},
{
description: 'origin, trailing slash',
location: {origin: 'http:https://example.com:8065/', protocol: '', hostname: '', port: ''},
basename: '',
expectedSiteURL: 'http:https://example.com:8065',
},
{
description: 'origin, with basename',
location: {origin: 'http:https://example.com:8065', protocol: '', hostname: '', port: ''},
basename: '/subpath',
expectedSiteURL: 'http:https://example.com:8065/subpath',
},
{
description: 'no origin',
location: {origin: '', protocol: 'http:', hostname: 'example.com', port: '8065'},
basename: '',
expectedSiteURL: 'http:https://example.com:8065',
},
{
description: 'no origin, with basename',
location: {origin: '', protocol: 'http:', hostname: 'example.com', port: '8065'},
basename: '/subpath',
expectedSiteURL: 'http:https://example.com:8065/subpath',
},
];
testCases.forEach((testCase) => it(testCase.description, () => {
const obj = {
location: testCase.location,
basename: testCase.basename,
};
expect(getSiteURLFromWindowObject(obj)).toEqual(testCase.expectedSiteURL);
}));
});
});