parent
9253134612
commit
fe46802aed
4 changed files with 37 additions and 0 deletions
|
|
@ -26,6 +26,8 @@ export default class MarkdownLink extends PureComponent {
|
|||
|
||||
static defaultProps = {
|
||||
onPermalinkPress: () => true,
|
||||
serverURL: '',
|
||||
siteURL: '',
|
||||
};
|
||||
|
||||
static contextTypes = {
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ export default class PostListBase extends PureComponent {
|
|||
onLoadMoreUp: () => true,
|
||||
renderFooter: () => null,
|
||||
refreshing: false,
|
||||
serverURL: '',
|
||||
siteURL: '',
|
||||
};
|
||||
|
||||
componentWillMount() {
|
||||
|
|
|
|||
|
|
@ -97,6 +97,10 @@ export function getScheme(url) {
|
|||
}
|
||||
|
||||
export function matchPermalink(link, rootURL) {
|
||||
if (!link || !rootURL) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new RegExp('^' + escapeRegex(rootURL) + '\\/([^\\/]+)\\/pl\\/(\\w+)').exec(link);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import assert from 'assert';
|
||||
|
||||
import * as UrlUtils from 'app/utils/url';
|
||||
|
||||
/* eslint-disable max-nested-callbacks */
|
||||
|
|
@ -86,4 +88,31 @@ describe('UrlUtils', () => {
|
|||
expect(UrlUtils.stripTrailingSlashes(url)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('matchPermalink', () => {
|
||||
const ROOT_URL = 'http://localhost:8065';
|
||||
|
||||
const tests = [
|
||||
{name: 'should return null if all inputs are empty', input: {link: '', rootURL: ''}, expected: null},
|
||||
{name: 'should return null if any of the inputs is null', input: {link: '', rootURL: null}, expected: null},
|
||||
{name: 'should return null if any of the inputs is null', input: {link: null, rootURL: ''}, expected: null},
|
||||
{name: 'should return null for not supported link', input: {link: 'https://mattermost.com', rootURL: ROOT_URL}, expected: null},
|
||||
{name: 'should match permalink', input: {link: ROOT_URL + '/ad-1/pl/qe93kkfd7783iqwuwfcwcxbsgy', rootURL: ROOT_URL}, expected: ['http://localhost:8065/ad-1/pl/qe93kkfd7783iqwuwfcwcxbsgy', 'ad-1', 'qe93kkfd7783iqwuwfcwcxbsgy']},
|
||||
];
|
||||
|
||||
for (const test of tests) {
|
||||
const {name, input, expected} = test;
|
||||
|
||||
it(name, () => {
|
||||
const actual = UrlUtils.matchPermalink(input.link, input.rootURL);
|
||||
if (actual) {
|
||||
assert.equal(actual[0], expected[0]);
|
||||
assert.equal(actual[1], expected[1]);
|
||||
assert.equal(actual[2], expected[2]);
|
||||
} else {
|
||||
assert.equal(actual, expected);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue