This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
url.test.tsx
119 lines (111 loc) · 4.48 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import assert from 'assert';
import {getSiteURLFromWindowObject, getRelativeChannelURL, validateChannelUrl} 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);
}));
});
describe('validateChannelUrl', () => {
const testCases = [
{
description: 'Called with a 1 character url',
url: 'a',
expectedErrors: ['change_url.longer'],
},
{
description: 'Called with a url starting with a dash',
url: '-Url',
expectedErrors: ['change_url.startWithLetter'],
},
{
description: 'Called with a url starting with an underscore',
url: '_URL',
expectedErrors: ['change_url.startWithLetter'],
},
{
description: 'Called with a url starting and ending with an underscore',
url: '_a_',
expectedErrors: ['change_url.startAndEndWithLetter'],
},
{
description: 'Called with a url starting and ending with an dash',
url: '-a-',
expectedErrors: ['change_url.startAndEndWithLetter'],
},
{
description: 'Called with a url ending with an dash',
url: 'a----',
expectedErrors: ['change_url.endWithLetter'],
},
{
description: 'Called with a url containing two underscores',
url: 'foo__bar',
expectedErrors: [],
},
{
description: 'Called with a url resembling a direct message url',
url: 'uzsfmtmniifsjgesce4u7yznyh__uzsfmtmniifsjgesce4u7yznyh',
expectedErrors: ['change_url.invalidDirectMessage'],
},
{
description: 'Called with a containing two dashes',
url: 'foo--bar',
expectedErrors: [],
},
{
description: 'Called with a capital letters two dashes',
url: 'Foo--bar',
expectedErrors: ['change_url.invalidUrl'],
},
];
testCases.forEach((testCase) => it(testCase.description, () => {
const returnedErrors = validateChannelUrl(testCase.url).map((component) => component.key);
assert.deepEqual(
returnedErrors.sort(),
testCase.expectedErrors.sort(),
);
}));
});
});