|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
const { assert } = require('chai');
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
findLinks,
|
|
|
|
|
getTitleMetaTag,
|
|
|
|
|
getImageMetaTag,
|
|
|
|
|
isLinkInWhitelist,
|
|
|
|
@ -228,4 +229,80 @@ describe('Link previews', () => {
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('#findLinks', () => {
|
|
|
|
|
it('returns all links if no caretLocation is provided', () => {
|
|
|
|
|
const text =
|
|
|
|
|
'Check out this link: https://github.com/signalapp/Signal-Desktop\nAnd this one too: https://github.com/signalapp/Signal-Android';
|
|
|
|
|
|
|
|
|
|
const expected = [
|
|
|
|
|
'https://github.com/signalapp/Signal-Desktop',
|
|
|
|
|
'https://github.com/signalapp/Signal-Android',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const actual = findLinks(text);
|
|
|
|
|
assert.deepEqual(expected, actual);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('includes all links if cursor is not in a link', () => {
|
|
|
|
|
const text =
|
|
|
|
|
'Check out this link: https://github.com/signalapp/Signal-Desktop\nAnd this one too: https://github.com/signalapp/Signal-Android';
|
|
|
|
|
const caretLocation = 10;
|
|
|
|
|
|
|
|
|
|
const expected = [
|
|
|
|
|
'https://github.com/signalapp/Signal-Desktop',
|
|
|
|
|
'https://github.com/signalapp/Signal-Android',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const actual = findLinks(text, caretLocation);
|
|
|
|
|
assert.deepEqual(expected, actual);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('excludes a link not at the end if the caret is inside of it', () => {
|
|
|
|
|
const text =
|
|
|
|
|
'Check out this link: https://github.com/signalapp/Signal-Desktop\nAnd this one too: https://github.com/signalapp/Signal-Android';
|
|
|
|
|
const caretLocation = 30;
|
|
|
|
|
|
|
|
|
|
const expected = ['https://github.com/signalapp/Signal-Android'];
|
|
|
|
|
|
|
|
|
|
const actual = findLinks(text, caretLocation);
|
|
|
|
|
assert.deepEqual(expected, actual);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('excludes a link not at the end if the caret is at its end', () => {
|
|
|
|
|
const text =
|
|
|
|
|
'Check out this link: https://github.com/signalapp/Signal-Desktop\nAnd this one too: https://github.com/signalapp/Signal-Android';
|
|
|
|
|
const caretLocation = 64;
|
|
|
|
|
|
|
|
|
|
const expected = ['https://github.com/signalapp/Signal-Android'];
|
|
|
|
|
|
|
|
|
|
const actual = findLinks(text, caretLocation);
|
|
|
|
|
assert.deepEqual(expected, actual);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('excludes a link at the end of the caret is inside of it', () => {
|
|
|
|
|
const text =
|
|
|
|
|
'Check out this link: https://github.com/signalapp/Signal-Desktop\nAnd this one too: https://github.com/signalapp/Signal-Android';
|
|
|
|
|
const caretLocation = 100;
|
|
|
|
|
|
|
|
|
|
const expected = ['https://github.com/signalapp/Signal-Desktop'];
|
|
|
|
|
|
|
|
|
|
const actual = findLinks(text, caretLocation);
|
|
|
|
|
assert.deepEqual(expected, actual);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('includes link at the end if cursor is at its end', () => {
|
|
|
|
|
const text =
|
|
|
|
|
'Check out this link: https://github.com/signalapp/Signal-Desktop\nAnd this one too: https://github.com/signalapp/Signal-Android';
|
|
|
|
|
const caretLocation = text.length;
|
|
|
|
|
|
|
|
|
|
const expected = [
|
|
|
|
|
'https://github.com/signalapp/Signal-Desktop',
|
|
|
|
|
'https://github.com/signalapp/Signal-Android',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const actual = findLinks(text, caretLocation);
|
|
|
|
|
assert.deepEqual(expected, actual);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|