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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* MM-15749 Allow channel links in brackets * Use toBe instead of toEqual
- Loading branch information
Showing
3 changed files
with
52 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,95 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import assert from 'assert'; | ||
|
||
import * as TextFormatting from 'utils/text_formatting.jsx'; | ||
|
||
describe('TextFormatting.ChannelLinks', () => { | ||
it('Not channel links', (done) => { | ||
assert.equal( | ||
TextFormatting.formatText('~123').trim(), | ||
test('Not channel links', () => { | ||
expect( | ||
TextFormatting.formatText('~123').trim() | ||
).toBe( | ||
'<p>~123</p>' | ||
); | ||
|
||
assert.equal( | ||
TextFormatting.formatText('~town-square').trim(), | ||
expect( | ||
TextFormatting.formatText('~town-square').trim() | ||
).toBe( | ||
'<p>~town-square</p>' | ||
); | ||
|
||
done(); | ||
}); | ||
|
||
describe('Channel links', () => { | ||
afterEach(() => { | ||
delete window.basename; | ||
}); | ||
|
||
it('should link ~town-square', () => { | ||
assert.equal( | ||
test('should link ~town-square', () => { | ||
expect( | ||
TextFormatting.formatText('~town-square', { | ||
channelNamesMap: {'town-square': {display_name: 'Town Square'}}, | ||
team: {name: 'myteam'}, | ||
}).trim(), | ||
}).trim() | ||
).toBe( | ||
'<p><a class="mention-link" href="/myteam/channels/town-square" data-channel-mention="town-square">~Town Square</a></p>' | ||
); | ||
}); | ||
|
||
it('should link ~town-square followed by a period', () => { | ||
assert.equal( | ||
test('should link ~town-square followed by a period', () => { | ||
expect( | ||
TextFormatting.formatText('~town-square.', { | ||
channelNamesMap: {'town-square': {display_name: 'Town Square'}}, | ||
team: {name: 'myteam'}, | ||
}).trim(), | ||
}).trim() | ||
).toBe( | ||
'<p><a class="mention-link" href="/myteam/channels/town-square" data-channel-mention="town-square">~Town Square</a>.</p>' | ||
); | ||
}); | ||
|
||
it('should link ~town-square, with display_name an HTML string', () => { | ||
assert.equal( | ||
test('should link ~town-square, with display_name an HTML string', () => { | ||
expect( | ||
TextFormatting.formatText('~town-square', { | ||
channelNamesMap: {'town-square': {display_name: '<b>Reception</b>'}}, | ||
team: {name: 'myteam'}, | ||
}).trim(), | ||
}).trim() | ||
).toBe( | ||
'<p><a class="mention-link" href="/myteam/channels/town-square" data-channel-mention="town-square">~<b>Reception</b></a></p>' | ||
); | ||
}); | ||
|
||
it('should link ~town-square, with a basename defined', () => { | ||
test('should link ~town-square, with a basename defined', () => { | ||
window.basename = '/subpath'; | ||
assert.equal( | ||
expect( | ||
TextFormatting.formatText('~town-square', { | ||
channelNamesMap: {'town-square': {display_name: '<b>Reception</b>'}}, | ||
team: {name: 'myteam'}, | ||
}).trim(), | ||
}).trim() | ||
).toBe( | ||
'<p><a class="mention-link" href="/subpath/myteam/channels/town-square" data-channel-mention="town-square">~<b>Reception</b></a></p>' | ||
); | ||
}); | ||
|
||
test('should link in brackets', () => { | ||
expect( | ||
TextFormatting.formatText('(~town-square)', { | ||
channelNamesMap: {'town-square': {display_name: 'Town Square'}}, | ||
team: {name: 'myteam'}, | ||
}).trim() | ||
).toBe( | ||
'<p>(<a class="mention-link" href="/myteam/channels/town-square" data-channel-mention="town-square">~Town Square</a>)</p>' | ||
); | ||
}); | ||
}); | ||
|
||
describe('invalid channel links', () => { | ||
test('should not link when a ~ is in the middle of a word', () => { | ||
expect( | ||
TextFormatting.formatText('aa~town-square', { | ||
channelNamesMap: {'town-square': {display_name: 'Town Square'}}, | ||
team: {name: 'myteam'}, | ||
}).trim() | ||
).toBe( | ||
'<p>aa~town-square</p>' | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters