tests: Expand the tests in urls_become_clickable.js

This commit is contained in:
Richard Hansen 2020-12-13 19:04:38 -05:00 committed by John McLear
parent 1c388ca66e
commit 66d0eb9a1f

View file

@ -1,67 +1,76 @@
'use strict';
describe('urls', function () { describe('urls', function () {
// create a new pad before each test run // Returns the first text element. Note that any change to the text element will result in the
beforeEach(function (cb) { // element being replaced with another object.
helper.newPad(cb); const txt = () => helper.padInner$('div').first();
before(async function () {
this.timeout(60000); this.timeout(60000);
await new Promise((resolve, reject) => helper.newPad((err) => {
if (err != null) return reject(err);
resolve();
}));
}); });
it('when you enter an url, it becomes clickable', function (done) { beforeEach(async function () {
const inner$ = helper.padInner$; await helper.clearPad();
const chrome$ = helper.padChrome$;
// get the first text element out of the inner iframe
const firstTextElement = inner$('div').first();
// simulate key presses to delete content
firstTextElement.sendkeys('{selectall}'); // select all
firstTextElement.sendkeys('{del}'); // clear the first line
firstTextElement.sendkeys('https://etherpad.org'); // insert a URL
helper.waitFor(() => inner$('div').first().find('a').length === 1, 2000).done(done);
}); });
it('when you enter a url containing a !, it becomes clickable and contains the whole URL', function (done) { describe('entering a URL makes a link', function () {
const inner$ = helper.padInner$; for (const url of ['https://etherpad.org', 'www.etherpad.org']) {
const chrome$ = helper.padChrome$; it(url, async function () {
const url = 'https://etherpad.org';
// get the first text element out of the inner iframe await helper.edit(url);
const firstTextElement = inner$('div').first(); await helper.waitForPromise(() => txt().find('a').length === 1, 2000);
const url = 'https://etherpad.org/!foo'; const link = txt().find('a');
expect(link.attr('href')).to.be(url);
// simulate key presses to delete content expect(link.text()).to.be(url);
firstTextElement.sendkeys('{selectall}'); // select all });
firstTextElement.sendkeys('{del}'); // clear the first line }
firstTextElement.sendkeys(url); // insert a URL
helper.waitFor(() => {
if (inner$('div').first().find('a').length === 1) { // if it contains an A link
if (inner$('div').first().find('a')[0].href === url) {
return true;
}
}
}, 2000).done(done);
}); });
it('when you enter a url followed by a ], the ] is not included in the URL', function (done) { describe('special characters inside URL', function () {
const inner$ = helper.padInner$; for (const char of '-:@_.,~%+/?=&#!;()$') {
const chrome$ = helper.padChrome$; const url = `https://etherpad.org/${char}foo`;
it(url, async function () {
await helper.edit(url);
await helper.waitForPromise(() => txt().find('a').length === 1);
const link = txt().find('a');
expect(link.attr('href')).to.be(url);
expect(link.text()).to.be(url);
});
}
});
// get the first text element out of the inner iframe describe('punctuation after URL is ignored', function () {
const firstTextElement = inner$('div').first(); for (const char of ':.,;]') {
const url = 'https://etherpad.org/'; const want = 'https://etherpad.org';
const input = want + char;
it(input, async function () {
await helper.edit(input);
await helper.waitForPromise(() => txt().find('a').length === 1);
const link = txt().find('a');
expect(link.attr('href')).to.be(want);
expect(link.text()).to.be(want);
});
}
});
// simulate key presses to delete content // Square brackets are in the RFC3986 reserved set so they can legally appear in URIs, but they
firstTextElement.sendkeys('{selectall}'); // select all // are explicitly excluded from linkification because including them is usually not desired (e.g.,
firstTextElement.sendkeys('{del}'); // clear the first line // it can interfere with wiki/markdown link syntax).
firstTextElement.sendkeys(url); // insert a URL describe('square brackets are excluded from linkified URLs', function () {
firstTextElement.sendkeys(']'); // put a ] after it for (const char of '[]') {
const want = 'https://etherpad.org/';
helper.waitFor(() => { const input = `${want}${char}foo`;
if (inner$('div').first().find('a').length === 1) { // if it contains an A link it(input, async function () {
if (inner$('div').first().find('a')[0].href === url) { await helper.edit(input);
return true; await helper.waitForPromise(() => txt().find('a').length === 1);
} const link = txt().find('a');
} expect(link.attr('href')).to.be(want);
}, 2000).done(done); expect(link.text()).to.be(want);
});
}
}); });
}); });