File size: 2,784 Bytes
1e92f2d |
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 |
// @flow
import getMentions from '../get-mentions';
it('should return a mention', () => {
expect(getMentions('Hey @mxstbr whassup')).toEqual(['mxstbr']);
});
it('should return multiple mentions', () => {
expect(getMentions('Hey @mxstbr @bryn whassup')).toEqual(['mxstbr', 'bryn']);
});
it('should remove duplicate mentions', () => {
expect(getMentions('Hey @mxstbr @bryn @mxstbr whassup')).toEqual([
'mxstbr',
'bryn',
]);
});
it('should work at the beginning of a string', () => {
expect(getMentions('@mxstbr whassup')).toEqual(['mxstbr']);
});
it('should work at the end of a string', () => {
expect(getMentions('Hey @bryn')).toEqual(['bryn']);
});
it('should ignore commas after mentions', () => {
expect(getMentions('Hey @bryn, whassup?')).toEqual(['bryn']);
});
it('should match underscores', () => {
expect(getMentions('Hey @brian_lovin whassup')).toEqual(['brian_lovin']);
});
it('should match minusses', () => {
expect(getMentions('Hey @brian-lovin whassup')).toEqual(['brian-lovin']);
});
it('should ignore parenthesis before mentions', () => {
expect(getMentions('It is Bryn! (@bryn look)')).toEqual(['bryn']);
});
it('should match mention in Japanese', () => {
expect(getMentions('の@mxstbrに到着を待っている')).toEqual(['mxstbr']);
});
it('should extract mention before newline', () => {
expect(getMentions('@mxstbr\n@bryn')).toEqual(['mxstbr', 'bryn']);
});
it('should not extract username from medium link with @', () => {
expect(
getMentions(
'https://medium.com/@probablyup/introducing-buttermilk-fc0b8c6d92af'
)
).toEqual([]);
});
it('should extract username after link ending in /', () => {
expect(
getMentions(
'https://medium.com/@probablyup/introducing-buttermilk-fc0b8c6d92af/ @bryn'
)
).toEqual(['bryn']);
});
describe.skip('failing tests', () => {
it('should not extract username preceded by !', () => {
expect(getMentions('f!@kn')).toEqual([]);
});
it('should not extract username preceded by @', () => {
expect(getMentions('f@@kn')).toEqual([]);
});
it('should not extract username preceded by #', () => {
expect(getMentions('f#@kn')).toEqual([]);
});
it('should not extract username preceded by $', () => {
expect(getMentions('f$@kn')).toEqual([]);
});
it('should not extract username preceded by %', () => {
expect(getMentions('f%@kn')).toEqual([]);
});
it('should not extract username preceded by &', () => {
expect(getMentions('f&@kn')).toEqual([]);
});
it('should not extract username preceded by *', () => {
expect(getMentions('f*@kn')).toEqual([]);
});
it('should not extract username ending in @', () => {
expect(getMentions('Current Status: @_@ (cc: @bryn)')).toEqual(['bryn']);
});
});
|