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
1 changed files with 64 additions and 55 deletions

View File

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