Merge branch 'develop' of github.com:ether/etherpad-lite into 3227-tests

This commit is contained in:
John McLear 2021-02-02 22:51:03 +00:00
commit 4682460b00
150 changed files with 6320 additions and 6944 deletions

View file

@ -50,10 +50,10 @@ exports.init = async function () {
after(async function () {
webaccess.authnFailureDelayMs = backups.authnFailureDelayMs;
await server.stop();
// Note: This does not unset settings that were added.
Object.assign(settings, backups.settings);
log4js.setGlobalLogLevel(logLevel);
await server.exit();
});
return exports.agent;

View file

@ -1,3 +1,5 @@
'use strict';
/*
* This file is copied & modified from <basedir>/tests/backend/specs/api/pad.js
*

View file

@ -6,151 +6,148 @@
* TODO: unify those two files, and merge in a single one.
*/
/* eslint-disable max-len */
const common = require('../../common');
const supertest = require(`${__dirname}/../../../../src/node_modules/supertest`);
const settings = require(`${__dirname}/../../../../tests/container/loadSettings.js`).loadSettings();
const api = supertest(`http://${settings.ip}:${settings.port}`);
const settings = require('../../../container/loadSettings.js').loadSettings();
const supertest = require('ep_etherpad-lite/node_modules/supertest');
const api = supertest(`http://${settings.ip}:${settings.port}`);
const apiKey = common.apiKey;
const apiVersion = 1;
const testImports = {
'malformed': {
input: '<html><body><li>wtf</ul></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>wtf<br><br></body></html>',
expectedText: 'wtf\n\n',
wantHTML: '<!DOCTYPE HTML><html><body>wtf<br><br></body></html>',
wantText: 'wtf\n\n',
disabled: true,
},
'nonelistiteminlist #3620': {
input: '<html><body><ul>test<li>FOO</li></ul></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body><ul class="bullet">test<li>FOO</ul><br></body></html>',
expectedText: '\ttest\n\t* FOO\n\n',
wantHTML: '<!DOCTYPE HTML><html><body><ul class="bullet">test<li>FOO</ul><br></body></html>',
wantText: '\ttest\n\t* FOO\n\n',
disabled: true,
},
'whitespaceinlist #3620': {
input: '<html><body><ul> <li>FOO</li></ul></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body><ul class="bullet"><li>FOO</ul><br></body></html>',
expectedText: '\t* FOO\n\n',
disabled: true,
wantHTML: '<!DOCTYPE HTML><html><body><ul class="bullet"><li>FOO</ul><br></body></html>',
wantText: '\t* FOO\n\n',
},
'prefixcorrectlinenumber': {
input: '<html><body><ol><li>should be 1</li><li>should be 2</li></ol></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body><ol start="1" class="number"><li>should be 1</li><li>should be 2</ol><br></body></html>',
expectedText: '\t1. should be 1\n\t2. should be 2\n\n',
wantHTML: '<!DOCTYPE HTML><html><body><ol start="1" class="number"><li>should be 1</li><li>should be 2</ol><br></body></html>',
wantText: '\t1. should be 1\n\t2. should be 2\n\n',
},
'prefixcorrectlinenumbernested': {
input: '<html><body><ol><li>should be 1</li><ol><li>foo</li></ol><li>should be 2</li></ol></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body><ol start="1" class="number"><li>should be 1<ol start="2" class="number"><li>foo</ol><li>should be 2</ol><br></body></html>',
expectedText: '\t1. should be 1\n\t\t1.1. foo\n\t2. should be 2\n\n',
wantHTML: '<!DOCTYPE HTML><html><body><ol start="1" class="number"><li>should be 1<ol start="2" class="number"><li>foo</ol><li>should be 2</ol><br></body></html>',
wantText: '\t1. should be 1\n\t\t1.1. foo\n\t2. should be 2\n\n',
},
/*
"prefixcorrectlinenumber when introduced none list item - currently not supported see #3450":{
"prefixcorrectlinenumber when introduced none list item - currently not supported see #3450": {
input: '<html><body><ol><li>should be 1</li>test<li>should be 2</li></ol></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body><ol start="1" class="number"><li>should be 1</li>test<li>should be 2</li></ol><br></body></html>',
expectedText: '\t1. should be 1\n\ttest\n\t2. should be 2\n\n'
wantHTML: '<!DOCTYPE HTML><html><body><ol start="1" class="number"><li>should be 1</li>test<li>should be 2</li></ol><br></body></html>',
wantText: '\t1. should be 1\n\ttest\n\t2. should be 2\n\n',
}
,
"newlinesshouldntresetlinenumber #2194":{
"newlinesshouldntresetlinenumber #2194": {
input: '<html><body><ol><li>should be 1</li>test<li>should be 2</li></ol></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body><ol class="number"><li>should be 1</li>test<li>should be 2</li></ol><br></body></html>',
expectedText: '\t1. should be 1\n\ttest\n\t2. should be 2\n\n'
wantHTML: '<!DOCTYPE HTML><html><body><ol class="number"><li>should be 1</li>test<li>should be 2</li></ol><br></body></html>',
wantText: '\t1. should be 1\n\ttest\n\t2. should be 2\n\n',
}
*/
'ignoreAnyTagsOutsideBody': {
description: 'Content outside body should be ignored',
input: '<html><head><title>title</title><style></style></head><body>empty<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>empty<br><br></body></html>',
expectedText: 'empty\n\n',
wantHTML: '<!DOCTYPE HTML><html><body>empty<br><br></body></html>',
wantText: 'empty\n\n',
},
'indentedListsAreNotBullets': {
description: 'Indented lists are represented with tabs and without bullets',
input: '<html><body><ul class="indent"><li>indent</li><li>indent</ul></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body><ul class="indent"><li>indent</li><li>indent</ul><br></body></html>',
expectedText: '\tindent\n\tindent\n\n'
wantHTML: '<!DOCTYPE HTML><html><body><ul class="indent"><li>indent</li><li>indent</ul><br></body></html>',
wantText: '\tindent\n\tindent\n\n',
},
lineWithMultipleSpaces: {
'lineWithMultipleSpaces': {
description: 'Multiple spaces should be collapsed',
input: '<html><body>Text with more than one space.<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>Text with more than one space.<br><br></body></html>',
expectedText: 'Text with more than one space.\n\n'
wantHTML: '<!DOCTYPE HTML><html><body>Text with more than one space.<br><br></body></html>',
wantText: 'Text with more than one space.\n\n',
},
lineWithMultipleNonBreakingAndNormalSpaces: {
'lineWithMultipleNonBreakingAndNormalSpaces': {
// XXX the HTML between "than" and "one" looks strange
description: 'non-breaking space should be preserved, but can be replaced when it',
input: '<html><body>Text&nbsp;with&nbsp; more&nbsp;&nbsp;&nbsp;than &nbsp;one space.<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>Text with&nbsp; more&nbsp;&nbsp; than&nbsp; one space.<br><br></body></html>',
expectedText: 'Text with more than one space.\n\n'
wantHTML: '<!DOCTYPE HTML><html><body>Text with&nbsp; more&nbsp;&nbsp; than&nbsp; one space.<br><br></body></html>',
wantText: 'Text with more than one space.\n\n',
},
multiplenbsp: {
'multiplenbsp': {
description: 'Multiple non-breaking space should be preserved',
input: '<html><body>&nbsp;&nbsp;<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>&nbsp;&nbsp;<br><br></body></html>',
expectedText: ' \n\n'
wantHTML: '<!DOCTYPE HTML><html><body>&nbsp;&nbsp;<br><br></body></html>',
wantText: ' \n\n',
},
multipleNonBreakingSpaceBetweenWords: {
'multipleNonBreakingSpaceBetweenWords': {
description: 'A normal space is always inserted before a word',
input: '<html><body>&nbsp;&nbsp;word1&nbsp;&nbsp;word2&nbsp;&nbsp;&nbsp;word3<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>&nbsp; word1&nbsp; word2&nbsp;&nbsp; word3<br><br></body></html>',
expectedText: ' word1 word2 word3\n\n'
wantHTML: '<!DOCTYPE HTML><html><body>&nbsp; word1&nbsp; word2&nbsp;&nbsp; word3<br><br></body></html>',
wantText: ' word1 word2 word3\n\n',
},
nonBreakingSpacePreceededBySpaceBetweenWords: {
'nonBreakingSpacePreceededBySpaceBetweenWords': {
description: 'A non-breaking space preceeded by a normal space',
input: '<html><body> &nbsp;word1 &nbsp;word2 &nbsp;word3<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>&nbsp;word1&nbsp; word2&nbsp; word3<br><br></body></html>',
expectedText: ' word1 word2 word3\n\n'
wantHTML: '<!DOCTYPE HTML><html><body>&nbsp;word1&nbsp; word2&nbsp; word3<br><br></body></html>',
wantText: ' word1 word2 word3\n\n',
},
nonBreakingSpaceFollowededBySpaceBetweenWords: {
'nonBreakingSpaceFollowededBySpaceBetweenWords': {
description: 'A non-breaking space followed by a normal space',
input: '<html><body>&nbsp; word1&nbsp; word2&nbsp; word3<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>&nbsp; word1&nbsp; word2&nbsp; word3<br><br></body></html>',
expectedText: ' word1 word2 word3\n\n'
wantHTML: '<!DOCTYPE HTML><html><body>&nbsp; word1&nbsp; word2&nbsp; word3<br><br></body></html>',
wantText: ' word1 word2 word3\n\n',
},
spacesAfterNewline: {
'spacesAfterNewline': {
description: 'Collapse spaces that follow a newline',
input:'<!doctype html><html><body>something<br> something<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>something<br>something<br><br></body></html>',
expectedText: 'something\nsomething\n\n'
input: '<!doctype html><html><body>something<br> something<br></body></html>',
wantHTML: '<!DOCTYPE HTML><html><body>something<br>something<br><br></body></html>',
wantText: 'something\nsomething\n\n',
},
spacesAfterNewlineP: {
'spacesAfterNewlineP': {
description: 'Collapse spaces that follow a paragraph',
input:'<!doctype html><html><body>something<p></p> something<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>something<br><br>something<br><br></body></html>',
expectedText: 'something\n\nsomething\n\n'
input: '<!doctype html><html><body>something<p></p> something<br></body></html>',
wantHTML: '<!DOCTYPE HTML><html><body>something<br><br>something<br><br></body></html>',
wantText: 'something\n\nsomething\n\n',
},
spacesAtEndOfLine: {
'spacesAtEndOfLine': {
description: 'Collapse spaces that preceed/follow a newline',
input:'<html><body>something <br> something<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>something<br>something<br><br></body></html>',
expectedText: 'something\nsomething\n\n'
input: '<html><body>something <br> something<br></body></html>',
wantHTML: '<!DOCTYPE HTML><html><body>something<br>something<br><br></body></html>',
wantText: 'something\nsomething\n\n',
},
spacesAtEndOfLineP: {
'spacesAtEndOfLineP': {
description: 'Collapse spaces that preceed/follow a paragraph',
input:'<html><body>something <p></p> something<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>something<br><br>something<br><br></body></html>',
expectedText: 'something\n\nsomething\n\n'
input: '<html><body>something <p></p> something<br></body></html>',
wantHTML: '<!DOCTYPE HTML><html><body>something<br><br>something<br><br></body></html>',
wantText: 'something\n\nsomething\n\n',
},
nonBreakingSpacesAfterNewlines: {
'nonBreakingSpacesAfterNewlines': {
description: 'Don\'t collapse non-breaking spaces that follow a newline',
input:'<html><body>something<br>&nbsp;&nbsp;&nbsp;something<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>something<br>&nbsp;&nbsp; something<br><br></body></html>',
expectedText: 'something\n something\n\n'
input: '<html><body>something<br>&nbsp;&nbsp;&nbsp;something<br></body></html>',
wantHTML: '<!DOCTYPE HTML><html><body>something<br>&nbsp;&nbsp; something<br><br></body></html>',
wantText: 'something\n something\n\n',
},
nonBreakingSpacesAfterNewlinesP: {
'nonBreakingSpacesAfterNewlinesP': {
description: 'Don\'t collapse non-breaking spaces that follow a paragraph',
input:'<html><body>something<p></p>&nbsp;&nbsp;&nbsp;something<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>something<br><br>&nbsp;&nbsp; something<br><br></body></html>',
expectedText: 'something\n\n something\n\n'
input: '<html><body>something<p></p>&nbsp;&nbsp;&nbsp;something<br></body></html>',
wantHTML: '<!DOCTYPE HTML><html><body>something<br><br>&nbsp;&nbsp; something<br><br></body></html>',
wantText: 'something\n\n something\n\n',
},
collapseSpacesInsideElements: {
'collapseSpacesInsideElements': {
description: 'Preserve only one space when multiple are present',
input: '<html><body>Need <span> more </span> space<i> s </i> !<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>Need more space<em> s </em>!<br><br></body></html>',
expectedText: 'Need more space s !\n\n'
wantHTML: '<!DOCTYPE HTML><html><body>Need more space<em> s </em>!<br><br></body></html>',
wantText: 'Need more space s !\n\n',
},
collapseSpacesAcrossNewlines: {
'collapseSpacesAcrossNewlines': {
description: 'Newlines and multiple spaces across newlines should be collapsed',
input: `
<html><body>Need
@ -158,30 +155,30 @@ const testImports = {
space
<i> s </i>
!<br></body></html>`,
expectedHTML: '<!DOCTYPE HTML><html><body>Need more space <em>s </em>!<br><br></body></html>',
expectedText: 'Need more space s !\n\n'
wantHTML: '<!DOCTYPE HTML><html><body>Need more space <em>s </em>!<br><br></body></html>',
wantText: 'Need more space s !\n\n',
},
multipleNewLinesAtBeginning: {
'multipleNewLinesAtBeginning': {
description: 'Multiple new lines and paragraphs at the beginning should be preserved',
input: '<html><body><br><br><p></p><p></p>first line<br><br>second line<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body><br><br><br><br>first line<br><br>second line<br><br></body></html>',
expectedText: '\n\n\n\nfirst line\n\nsecond line\n\n'
wantHTML: '<!DOCTYPE HTML><html><body><br><br><br><br>first line<br><br>second line<br><br></body></html>',
wantText: '\n\n\n\nfirst line\n\nsecond line\n\n',
},
multiLineParagraph:{
description: "A paragraph with multiple lines should not loose spaces when lines are combined",
input:`<html><body>
'multiLineParagraph': {
description: 'A paragraph with multiple lines should not loose spaces when lines are combined',
input: `<html><body>
<p>
а б в г ґ д е є ж з и і ї й к л м н о
п р с т у ф х ц ч ш щ ю я ь
</p>
</body></html>`,
expectedHTML: '<!DOCTYPE HTML><html><body>&#1072; &#1073; &#1074; &#1075; &#1169; &#1076; &#1077; &#1108; &#1078; &#1079; &#1080; &#1110; &#1111; &#1081; &#1082; &#1083; &#1084; &#1085; &#1086; &#1087; &#1088; &#1089; &#1090; &#1091; &#1092; &#1093; &#1094; &#1095; &#1096; &#1097; &#1102; &#1103; &#1100;<br><br></body></html>',
expectedText: 'а б в г ґ д е є ж з и і ї й к л м н о п р с т у ф х ц ч ш щ ю я ь\n\n'
wantHTML: '<!DOCTYPE HTML><html><body>&#1072; &#1073; &#1074; &#1075; &#1169; &#1076; &#1077; &#1108; &#1078; &#1079; &#1080; &#1110; &#1111; &#1081; &#1082; &#1083; &#1084; &#1085; &#1086; &#1087; &#1088; &#1089; &#1090; &#1091; &#1092; &#1093; &#1094; &#1095; &#1096; &#1097; &#1102; &#1103; &#1100;<br><br></body></html>',
wantText: 'а б в г ґ д е є ж з и і ї й к л м н о п р с т у ф х ц ч ш щ ю я ь\n\n',
},
multiLineParagraphWithPre:{
//XXX why is there &nbsp; before "in"?
description: "lines in preformatted text should be kept intact",
input:`<html><body>
'multiLineParagraphWithPre': {
// XXX why is there &nbsp; before "in"?
description: 'lines in preformatted text should be kept intact',
input: `<html><body>
<p>
а б в г ґ д е є ж з и і ї й к л м н о<pre>multiple
lines
@ -190,55 +187,55 @@ const testImports = {
</pre></p><p>п р с т у ф х ц ч ш щ ю я
ь</p>
</body></html>`,
expectedHTML: '<!DOCTYPE HTML><html><body>&#1072; &#1073; &#1074; &#1075; &#1169; &#1076; &#1077; &#1108; &#1078; &#1079; &#1080; &#1110; &#1111; &#1081; &#1082; &#1083; &#1084; &#1085; &#1086;<br>multiple<br>&nbsp;&nbsp; lines<br>&nbsp;in<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pre<br><br>&#1087; &#1088; &#1089; &#1090; &#1091; &#1092; &#1093; &#1094; &#1095; &#1096; &#1097; &#1102; &#1103; &#1100;<br><br></body></html>',
expectedText: 'а б в г ґ д е є ж з и і ї й к л м н о\nmultiple\n lines\n in\n pre\n\nп р с т у ф х ц ч ш щ ю я ь\n\n'
wantHTML: '<!DOCTYPE HTML><html><body>&#1072; &#1073; &#1074; &#1075; &#1169; &#1076; &#1077; &#1108; &#1078; &#1079; &#1080; &#1110; &#1111; &#1081; &#1082; &#1083; &#1084; &#1085; &#1086;<br>multiple<br>&nbsp;&nbsp; lines<br>&nbsp;in<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pre<br><br>&#1087; &#1088; &#1089; &#1090; &#1091; &#1092; &#1093; &#1094; &#1095; &#1096; &#1097; &#1102; &#1103; &#1100;<br><br></body></html>',
wantText: 'а б в г ґ д е є ж з и і ї й к л м н о\nmultiple\n lines\n in\n pre\n\nп р с т у ф х ц ч ш щ ю я ь\n\n',
},
preIntroducesASpace: {
description: "pre should be on a new line not preceeded by a space",
input:`<html><body><p>
'preIntroducesASpace': {
description: 'pre should be on a new line not preceeded by a space',
input: `<html><body><p>
1
<pre>preline
</pre></p></body></html>`,
expectedHTML: '<!DOCTYPE HTML><html><body>1<br>preline<br><br><br></body></html>',
expectedText: '1\npreline\n\n\n'
wantHTML: '<!DOCTYPE HTML><html><body>1<br>preline<br><br><br></body></html>',
wantText: '1\npreline\n\n\n',
},
dontDeleteSpaceInsideElements: {
'dontDeleteSpaceInsideElements': {
description: 'Preserve spaces inside elements',
input: '<html><body>Need<span> more </span>space<i> s </i>!<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>Need more space<em> s </em>!<br><br></body></html>',
expectedText: 'Need more space s !\n\n'
wantHTML: '<!DOCTYPE HTML><html><body>Need more space<em> s </em>!<br><br></body></html>',
wantText: 'Need more space s !\n\n',
},
dontDeleteSpaceOutsideElements: {
'dontDeleteSpaceOutsideElements': {
description: 'Preserve spaces outside elements',
input: '<html><body>Need <span>more</span> space <i>s</i> !<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>Need more space <em>s</em> !<br><br></body></html>',
expectedText: 'Need more space s !\n\n'
wantHTML: '<!DOCTYPE HTML><html><body>Need more space <em>s</em> !<br><br></body></html>',
wantText: 'Need more space s !\n\n',
},
dontDeleteSpaceAtEndOfElement: {
'dontDeleteSpaceAtEndOfElement': {
description: 'Preserve spaces at the end of an element',
input: '<html><body>Need <span>more </span>space <i>s </i>!<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>Need more space <em>s </em>!<br><br></body></html>',
expectedText: 'Need more space s !\n\n'
wantHTML: '<!DOCTYPE HTML><html><body>Need more space <em>s </em>!<br><br></body></html>',
wantText: 'Need more space s !\n\n',
},
dontDeleteSpaceAtBeginOfElements: {
'dontDeleteSpaceAtBeginOfElements': {
description: 'Preserve spaces at the start of an element',
input: '<html><body>Need<span> more</span> space<i> s</i> !<br></body></html>',
expectedHTML: '<!DOCTYPE HTML><html><body>Need more space<em> s</em> !<br><br></body></html>',
expectedText: 'Need more space s !\n\n'
wantHTML: '<!DOCTYPE HTML><html><body>Need more space<em> s</em> !<br><br></body></html>',
wantText: 'Need more space s !\n\n',
},
};
describe(__filename, function () {
Object.keys(testImports).forEach((testName) => {
const testPadId = makeid();
const test = testImports[testName];
if (test.disabled) {
return xit(`DISABLED: ${testName}`, function (done) {
done();
});
}
describe(`createPad ${testName}`, function () {
it('creates a new Pad', function (done) {
describe(testName, function () {
const testPadId = makeid();
const test = testImports[testName];
if (test.disabled) {
return xit(`DISABLED: ${testName}`, function (done) {
done();
});
}
it('createPad', function (done) {
api.get(`${endPoint('createPad')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to create new Pad');
@ -246,10 +243,8 @@ describe(__filename, function () {
.expect('Content-Type', /json/)
.expect(200, done);
});
});
describe(`setHTML ${testName}`, function () {
it('Sets the HTML', function (done) {
it('setHTML', function (done) {
api.get(`${endPoint('setHTML')}&padID=${testPadId}&html=${encodeURIComponent(test.input)}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error(`Error:${testName}`);
@ -257,23 +252,21 @@ describe(__filename, function () {
.expect('Content-Type', /json/)
.expect(200, done);
});
});
describe(`getHTML ${testName}`, function () {
it('Gets back the HTML of a Pad', function (done) {
it('getHTML', function (done) {
api.get(`${endPoint('getHTML')}&padID=${testPadId}`)
.expect((res) => {
const receivedHtml = res.body.data.html;
if (receivedHtml !== test.expectedHTML) {
const gotHtml = res.body.data.html;
if (gotHtml !== test.wantHTML) {
throw new Error(`HTML received from export is not the one we were expecting.
Test Name:
${testName}
Received:
${JSON.stringify(receivedHtml)}
Got:
${JSON.stringify(gotHtml)}
Expected:
${JSON.stringify(test.expectedHTML)}
Want:
${JSON.stringify(test.wantHTML)}
Which is a different version of the originally imported one:
${test.input}`);
@ -282,23 +275,21 @@ describe(__filename, function () {
.expect('Content-Type', /json/)
.expect(200, done);
});
});
describe(`getText ${testName}`, function () {
it('Gets back the Text of a Pad', function (done) {
it('getText', function (done) {
api.get(`${endPoint('getText')}&padID=${testPadId}`)
.expect((res) => {
const receivedText = res.body.data.text;
if (receivedText !== test.expectedText) {
const gotText = res.body.data.text;
if (gotText !== test.wantText) {
throw new Error(`Text received from export is not the one we were expecting.
Test Name:
${testName}
Received:
${JSON.stringify(receivedText)}
Got:
${JSON.stringify(gotText)}
Expected:
${JSON.stringify(test.expectedText)}
Want:
${JSON.stringify(test.wantText)}
Which is a different version of the originally imported one:
${test.input}`);
@ -315,7 +306,7 @@ describe(__filename, function () {
function endPoint(point, version) {
version = version || apiVersion;
return `/api/${version}/${point}?apikey=${apiKey}`;
};
}
function makeid() {
let text = '';

View file

@ -1,4 +1,4 @@
/* global __dirname, __filename, afterEach, before, beforeEach, describe, it, require */
'use strict';
/*
* Import and Export tests for the /p/whateverPadId/import and /p/whateverPadId/export endpoints.
@ -6,11 +6,11 @@
const assert = require('assert').strict;
const common = require('../../common');
const superagent = require(`${__dirname}/../../../../src/node_modules/superagent`);
const superagent = require('ep_etherpad-lite/node_modules/superagent');
const fs = require('fs');
const settings = require(`${__dirname}/../../../../src/node/utils/Settings`);
const padManager = require(`${__dirname}/../../../../src/node/db/PadManager`);
const plugins = require(`${__dirname}/../../../../src/static/js/pluginfw/plugin_defs`);
const settings = require('ep_etherpad-lite/node/utils/Settings');
const padManager = require('ep_etherpad-lite/node/db/PadManager');
const plugins = require('ep_etherpad-lite/static/js/pluginfw/plugin_defs');
const padText = fs.readFileSync('../tests/backend/specs/api/test.txt');
const etherpadDoc = fs.readFileSync('../tests/backend/specs/api/test.etherpad');
@ -122,7 +122,7 @@ describe(__filename, function () {
describe('Import/Export tests requiring AbiWord/LibreOffice', function () {
before(function () {
before(async function () {
if ((!settings.abiword || settings.abiword.indexOf('/') === -1) &&
(!settings.soffice || settings.soffice.indexOf('/') === -1)) {
this.skip();
@ -149,7 +149,8 @@ describe(__filename, function () {
await agent.post(`/p/${testPadId}/import`)
.attach('file', wordXDoc, {
filename: '/test.docx',
contentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
contentType:
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
})
.expect(200)
.expect(/FrameCall\('undefined', 'ok'\);/);
@ -352,7 +353,7 @@ describe(__filename, function () {
}); // End of tests.
var endPoint = function (point, version) {
const endPoint = (point, version) => {
version = version || apiVersion;
return `/api/${version}/${point}?apikey=${apiKey}`;
};

View file

@ -1,27 +1,26 @@
const assert = require('assert');
os = require('os'),
fs = require('fs'),
path = require('path'),
TidyHtml = null,
Settings = null;
'use strict';
const npm = require('../../../../src/node_modules/npm/lib/npm.js');
const nodeify = require('../../../../src/node_modules/nodeify');
const assert = require('assert');
const os = require('os');
const fs = require('fs');
const path = require('path');
let TidyHtml;
let Settings;
const npm = require('ep_etherpad-lite/node_modules/npm/lib/npm.js');
const nodeify = require('ep_etherpad-lite/node_modules/nodeify');
describe(__filename, function () {
describe('tidyHtml', function () {
before(function (done) {
npm.load({}, (err) => {
assert.ok(!err);
TidyHtml = require('../../../../src/node/utils/TidyHtml');
Settings = require('../../../../src/node/utils/Settings');
TidyHtml = require('ep_etherpad-lite/node/utils/TidyHtml');
Settings = require('ep_etherpad-lite/node/utils/Settings');
return done();
});
});
function tidy(file, callback) {
return nodeify(TidyHtml.tidy(file), callback);
}
const tidy = (file, callback) => nodeify(TidyHtml.tidy(file), callback);
it('Tidies HTML', function (done) {
// If the user hasn't configured Tidy, we skip this tests as it's required for this test
@ -53,7 +52,7 @@ describe(__filename, function () {
'</html>',
].join('\n');
assert.notStrictEqual(cleanedHtml.indexOf(expectedHtml), -1);
return done();
done();
});
});
@ -65,7 +64,7 @@ describe(__filename, function () {
tidy('/some/none/existing/file.html', (err) => {
assert.ok(err);
return done();
done();
});
});
});

View file

@ -1,34 +1,34 @@
'use strict';
/* eslint-disable max-len */
/*
* While importexport tests target the `setHTML` API endpoint, which is nearly identical to what happens
* when a user manually imports a document via the UI, the contentcollector tests here don't use rehype to process
* the document. Rehype removes spaces and newĺines were applicable, so the expected results here can
* differ from importexport.js.
* While importexport tests target the `setHTML` API endpoint, which is nearly identical to what
* happens when a user manually imports a document via the UI, the contentcollector tests here don't
* use rehype to process the document. Rehype removes spaces and newĺines were applicable, so the
* expected results here can differ from importexport.js.
*
* If you add tests here, please also add them to importexport.js
*/
const contentcollector = require('../../../src/static/js/contentcollector');
const AttributePool = require('../../../src/static/js/AttributePool');
const cheerio = require('../../../src/node_modules/cheerio');
const AttributePool = require('ep_etherpad-lite/static/js/AttributePool');
const assert = require('assert').strict;
const cheerio = require('ep_etherpad-lite/node_modules/cheerio');
const contentcollector = require('ep_etherpad-lite/static/js/contentcollector');
const tests = {
nestedLi: {
description: 'Complex nested Li',
html: '<!doctype html><html><body><ol><li>one</li><li><ol><li>1.1</li></ol></li><li>two</li></ol></body></html>',
expectedLineAttribs: [
wantLineAttribs: [
'*0*1*2*3+1+3', '*0*4*2*5+1+3', '*0*1*2*5+1+3',
],
expectedText: [
wantText: [
'*one', '*1.1', '*two',
],
},
complexNest: {
description: 'Complex list of different types',
html: '<!doctype html><html><body><ul class="bullet"><li>one</li><li>two</li><li>0</li><li>1</li><li>2<ul class="bullet"><li>3</li><li>4</li></ul></li></ul><ol class="number"><li>item<ol class="number"><li>item1</li><li>item2</li></ol></li></ol></body></html>',
expectedLineAttribs: [
wantLineAttribs: [
'*0*1*2+1+3',
'*0*1*2+1+3',
'*0*1*2+1+1',
@ -40,7 +40,7 @@ const tests = {
'*0*6*2*7+1+5',
'*0*6*2*7+1+5',
],
expectedText: [
wantText: [
'*one',
'*two',
'*0',
@ -56,148 +56,142 @@ const tests = {
ul: {
description: 'Tests if uls properly get attributes',
html: '<html><body><ul><li>a</li><li>b</li></ul><div>div</div><p>foo</p></body></html>',
expectedLineAttribs: ['*0*1*2+1+1', '*0*1*2+1+1', '+3', '+3'],
expectedText: ['*a', '*b', 'div', 'foo'],
wantLineAttribs: ['*0*1*2+1+1', '*0*1*2+1+1', '+3', '+3'],
wantText: ['*a', '*b', 'div', 'foo'],
},
ulIndented: {
description: 'Tests if indented uls properly get attributes',
html: '<html><body><ul><li>a</li><ul><li>b</li></ul><li>a</li></ul><p>foo</p></body></html>',
expectedLineAttribs: ['*0*1*2+1+1', '*0*3*2+1+1', '*0*1*2+1+1', '+3'],
expectedText: ['*a', '*b', '*a', 'foo'],
wantLineAttribs: ['*0*1*2+1+1', '*0*3*2+1+1', '*0*1*2+1+1', '+3'],
wantText: ['*a', '*b', '*a', 'foo'],
},
ol: {
description: 'Tests if ols properly get line numbers when in a normal OL',
html: '<html><body><ol><li>a</li><li>b</li><li>c</li></ol><p>test</p></body></html>',
expectedLineAttribs: ['*0*1*2*3+1+1', '*0*1*2*3+1+1', '*0*1*2*3+1+1', '+4'],
expectedText: ['*a', '*b', '*c', 'test'],
wantLineAttribs: ['*0*1*2*3+1+1', '*0*1*2*3+1+1', '*0*1*2*3+1+1', '+4'],
wantText: ['*a', '*b', '*c', 'test'],
noteToSelf: 'Ensure empty P does not induce line attribute marker, wont this break the editor?',
},
lineDoBreakInOl: {
description: 'A single completely empty line break within an ol should reset count if OL is closed off..',
html: '<html><body><ol><li>should be 1</li></ol><p>hello</p><ol><li>should be 1</li><li>should be 2</li></ol><p></p></body></html>',
expectedLineAttribs: ['*0*1*2*3+1+b', '+5', '*0*1*2*4+1+b', '*0*1*2*4+1+b', ''],
expectedText: ['*should be 1', 'hello', '*should be 1', '*should be 2', ''],
wantLineAttribs: ['*0*1*2*3+1+b', '+5', '*0*1*2*4+1+b', '*0*1*2*4+1+b', ''],
wantText: ['*should be 1', 'hello', '*should be 1', '*should be 2', ''],
noteToSelf: "Shouldn't include attribute marker in the <p> line",
},
bulletListInOL: {
description: 'A bullet within an OL should not change numbering..',
html: '<html><body><ol><li>should be 1</li><ul><li>should be a bullet</li></ul><li>should be 2</li></ol><p></p></body></html>',
expectedLineAttribs: ['*0*1*2*3+1+b', '*0*4*2*3+1+i', '*0*1*2*5+1+b', ''],
expectedText: ['*should be 1', '*should be a bullet', '*should be 2', ''],
},
testP: {
description: 'A single <p></p> should create a new line',
html: '<html><body><p></p><p></p></body></html>',
expectedLineAttribs: ['', ''],
expectedText: ['', ''],
wantLineAttribs: ['', ''],
wantText: ['', ''],
noteToSelf: '<p></p>should create a line break but not break numbering',
},
nestedOl: {
description: 'Tests if ols properly get line numbers when in a normal OL',
html: '<html><body>a<ol><li>b<ol><li>c</li></ol></ol>notlist<p>foo</p></body></html>',
expectedLineAttribs: ['+1', '*0*1*2*3+1+1', '*0*4*2*5+1+1', '+7', '+3'],
expectedText: ['a', '*b', '*c', 'notlist', 'foo'],
wantLineAttribs: ['+1', '*0*1*2*3+1+1', '*0*4*2*5+1+1', '+7', '+3'],
wantText: ['a', '*b', '*c', 'notlist', 'foo'],
noteToSelf: 'Ensure empty P does not induce line attribute marker, wont this break the editor?',
},
nestedOl2: {
description: 'First item being an UL then subsequent being OL will fail',
html: '<html><body><ul><li>a<ol><li>b</li><li>c</li></ol></li></ul></body></html>',
expectedLineAttribs: ['+1', '*0*1*2*3+1+1', '*0*4*2*5+1+1'],
expectedText: ['a', '*b', '*c'],
wantLineAttribs: ['+1', '*0*1*2*3+1+1', '*0*4*2*5+1+1'],
wantText: ['a', '*b', '*c'],
noteToSelf: 'Ensure empty P does not induce line attribute marker, wont this break the editor?',
disabled: true,
},
lineDontBreakOL: {
description: 'A single completely empty line break within an ol should NOT reset count',
html: '<html><body><ol><li>should be 1</li><p></p><li>should be 2</li><li>should be 3</li></ol><p></p></body></html>',
expectedLineAttribs: [],
expectedText: ['*should be 1', '*should be 2', '*should be 3'],
wantLineAttribs: [],
wantText: ['*should be 1', '*should be 2', '*should be 3'],
noteToSelf: "<p></p>should create a line break but not break numbering -- This is what I can't get working!",
disabled: true,
},
ignoreAnyTagsOutsideBody: {
description: 'Content outside body should be ignored',
html: '<html><head><title>title</title><style></style></head><body>empty<br></body></html>',
expectedLineAttribs: ['+5'],
expectedText: ['empty'],
wantLineAttribs: ['+5'],
wantText: ['empty'],
},
lineWithMultipleSpaces: {
description: 'Multiple spaces should be preserved',
html: '<html><body>Text with more than one space.<br></body></html>',
expectedLineAttribs: [ '+10' ],
expectedText: ['Text with more than one space.']
wantLineAttribs: ['+10'],
wantText: ['Text with more than one space.'],
},
lineWithMultipleNonBreakingAndNormalSpaces: {
description: 'non-breaking and normal space should be preserved',
html: '<html><body>Text&nbsp;with&nbsp; more&nbsp;&nbsp;&nbsp;than &nbsp;one space.<br></body></html>',
expectedLineAttribs: [ '+10' ],
expectedText: ['Text with more than one space.']
wantLineAttribs: ['+10'],
wantText: ['Text with more than one space.'],
},
multiplenbsp: {
description: 'Multiple nbsp should be preserved',
html: '<html><body>&nbsp;&nbsp;<br></body></html>',
expectedLineAttribs: [ '+2' ],
expectedText: [' ']
wantLineAttribs: ['+2'],
wantText: [' '],
},
multipleNonBreakingSpaceBetweenWords: {
description: 'Multiple nbsp between words ',
html: '<html><body>&nbsp;&nbsp;word1&nbsp;&nbsp;word2&nbsp;&nbsp;&nbsp;word3<br></body></html>',
expectedLineAttribs: [ '+m' ],
expectedText: [' word1 word2 word3']
wantLineAttribs: ['+m'],
wantText: [' word1 word2 word3'],
},
nonBreakingSpacePreceededBySpaceBetweenWords: {
description: 'A non-breaking space preceeded by a normal space',
html: '<html><body> &nbsp;word1 &nbsp;word2 &nbsp;word3<br></body></html>',
expectedLineAttribs: [ '+l' ],
expectedText: [' word1 word2 word3']
wantLineAttribs: ['+l'],
wantText: [' word1 word2 word3'],
},
nonBreakingSpaceFollowededBySpaceBetweenWords: {
description: 'A non-breaking space followed by a normal space',
html: '<html><body>&nbsp; word1&nbsp; word2&nbsp; word3<br></body></html>',
expectedLineAttribs: [ '+l' ],
expectedText: [' word1 word2 word3']
wantLineAttribs: ['+l'],
wantText: [' word1 word2 word3'],
},
spacesAfterNewline: {
description: 'Don\'t collapse spaces that follow a newline',
html:'<!doctype html><html><body>something<br> something<br></body></html>',
expectedLineAttribs: ['+9', '+m'],
expectedText: ['something', ' something']
html: '<!doctype html><html><body>something<br> something<br></body></html>',
wantLineAttribs: ['+9', '+m'],
wantText: ['something', ' something'],
},
spacesAfterNewlineP: {
description: 'Don\'t collapse spaces that follow a empty paragraph',
html:'<!doctype html><html><body>something<p></p> something<br></body></html>',
expectedLineAttribs: ['+9', '', '+m'],
expectedText: ['something', '', ' something']
html: '<!doctype html><html><body>something<p></p> something<br></body></html>',
wantLineAttribs: ['+9', '', '+m'],
wantText: ['something', '', ' something'],
},
spacesAtEndOfLine: {
description: 'Don\'t collapse spaces that preceed/follow a newline',
html:'<html><body>something <br> something<br></body></html>',
expectedLineAttribs: ['+l', '+m'],
expectedText: ['something ', ' something']
html: '<html><body>something <br> something<br></body></html>',
wantLineAttribs: ['+l', '+m'],
wantText: ['something ', ' something'],
},
spacesAtEndOfLineP: {
description: 'Don\'t collapse spaces that preceed/follow a empty paragraph',
html:'<html><body>something <p></p> something<br></body></html>',
expectedLineAttribs: ['+l', '', '+m'],
expectedText: ['something ', '', ' something']
html: '<html><body>something <p></p> something<br></body></html>',
wantLineAttribs: ['+l', '', '+m'],
wantText: ['something ', '', ' something'],
},
nonBreakingSpacesAfterNewlines: {
description: 'Don\'t collapse non-breaking spaces that follow a newline',
html:'<html><body>something<br>&nbsp;&nbsp;&nbsp;something<br></body></html>',
expectedLineAttribs: ['+9', '+c'],
expectedText: ['something', ' something']
html: '<html><body>something<br>&nbsp;&nbsp;&nbsp;something<br></body></html>',
wantLineAttribs: ['+9', '+c'],
wantText: ['something', ' something'],
},
nonBreakingSpacesAfterNewlinesP: {
description: 'Don\'t collapse non-breaking spaces that follow a paragraph',
html:'<html><body>something<p></p>&nbsp;&nbsp;&nbsp;something<br></body></html>',
expectedLineAttribs: ['+9', '', '+c'],
expectedText: ['something', '', ' something']
html: '<html><body>something<p></p>&nbsp;&nbsp;&nbsp;something<br></body></html>',
wantLineAttribs: ['+9', '', '+c'],
wantText: ['something', '', ' something'],
},
preserveSpacesInsideElements: {
description: 'Preserve all spaces when multiple are present',
html: '<html><body>Need <span> more </span> space<i> s </i> !<br></body></html>',
expectedLineAttribs: ['+h*0+4+2'],
expectedText: ['Need more space s !'],
wantLineAttribs: ['+h*0+4+2'],
wantText: ['Need more space s !'],
},
preserveSpacesAcrossNewlines: {
description: 'Newlines and multiple spaces across newlines should be preserved',
@ -207,69 +201,76 @@ const tests = {
space
<i> s </i>
!<br></body></html>`,
expectedLineAttribs: [ '+19*0+4+b' ],
expectedText: [ 'Need more space s !' ]
wantLineAttribs: ['+19*0+4+b'],
wantText: ['Need more space s !'],
},
multipleNewLinesAtBeginning: {
description: 'Multiple new lines at the beginning should be preserved',
html: '<html><body><br><br><p></p><p></p>first line<br><br>second line<br></body></html>',
expectedLineAttribs: ['', '', '', '', '+a', '', '+b'],
expectedText: [ '', '', '', '', 'first line', '', 'second line']
wantLineAttribs: ['', '', '', '', '+a', '', '+b'],
wantText: ['', '', '', '', 'first line', '', 'second line'],
},
multiLineParagraph:{
description: "A paragraph with multiple lines should not loose spaces when lines are combined",
html:`<html><body><p>
multiLineParagraph: {
description: 'A paragraph with multiple lines should not loose spaces when lines are combined',
html: `<html><body><p>
а б в г ґ д е є ж з и і ї й к л м н о
п р с т у ф х ц ч ш щ ю я ь</p>
</body></html>`,
expectedLineAttribs: [ '+1t' ],
expectedText: ["а б в г ґ д е є ж з и і ї й к л м н о п р с т у ф х ц ч ш щ ю я ь"]
wantLineAttribs: ['+1t'],
wantText: ['а б в г ґ д е є ж з и і ї й к л м н о п р с т у ф х ц ч ш щ ю я ь'],
},
multiLineParagraphWithPre:{
description: "lines in preformatted text should be kept intact",
html:`<html><body><p>
а б в г ґ д е є ж з и і ї й к л м н о<pre>multiple
multiLineParagraphWithPre: {
description: 'lines in preformatted text should be kept intact',
html: `<html><body><p>
а б в г ґ д е є ж з и і ї й к л м н о</p><pre>multiple
lines
in
pre
</pre></p><p>п р с т у ф х ц ч ш щ ю я
</pre><p>п р с т у ф х ц ч ш щ ю я
ь</p>
</body></html>`,
expectedLineAttribs: [ '+11', '+8', '+5', '+2', '+3', '+r' ],
expectedText: ['а б в г ґ д е є ж з и і ї й к л м н о', 'multiple', 'lines', 'in', 'pre', 'п р с т у ф х ц ч ш щ ю я ь']
wantLineAttribs: ['+11', '+8', '+5', '+2', '+3', '+r'],
wantText: [
'а б в г ґ д е є ж з и і ї й к л м н о',
'multiple',
'lines',
'in',
'pre',
'п р с т у ф х ц ч ш щ ю я ь',
],
},
preIntroducesASpace: {
description: "pre should be on a new line not preceeded by a space",
html:`<html><body><p>
description: 'pre should be on a new line not preceeded by a space',
html: `<html><body><p>
1
<pre>preline
</pre></p></body></html>`,
expectedLineAttribs: [ '+6', '+7' ],
expectedText: [' 1 ', 'preline']
</p><pre>preline
</pre></body></html>`,
wantLineAttribs: ['+6', '+7'],
wantText: [' 1 ', 'preline'],
},
dontDeleteSpaceInsideElements: {
description: 'Preserve spaces on the beginning and end of a element',
html: '<html><body>Need<span> more </span>space<i> s </i>!<br></body></html>',
expectedLineAttribs: ['+f*0+3+1'],
expectedText: ['Need more space s !']
wantLineAttribs: ['+f*0+3+1'],
wantText: ['Need more space s !'],
},
dontDeleteSpaceOutsideElements: {
description: 'Preserve spaces outside elements',
html: '<html><body>Need <span>more</span> space <i>s</i> !<br></body></html>',
expectedLineAttribs: ['+g*0+1+2'],
expectedText: ['Need more space s !']
wantLineAttribs: ['+g*0+1+2'],
wantText: ['Need more space s !'],
},
dontDeleteSpaceAtEndOfElement: {
description: 'Preserve spaces at the end of an element',
html: '<html><body>Need <span>more </span>space <i>s </i>!<br></body></html>',
expectedLineAttribs: ['+g*0+2+1'],
expectedText: ['Need more space s !']
wantLineAttribs: ['+g*0+2+1'],
wantText: ['Need more space s !'],
},
dontDeleteSpaceAtBeginOfElements: {
description: 'Preserve spaces at the start of an element',
html: '<html><body>Need<span> more</span> space<i> s</i> !<br></body></html>',
expectedLineAttribs: ['+f*0+2+2'],
expectedText: ['Need more space s !']
wantLineAttribs: ['+f*0+2+2'],
wantText: ['Need more space s !'],
},
};
@ -283,7 +284,7 @@ describe(__filename, function () {
});
}
it(testObj.description, function (done) {
it(testObj.description, async function () {
const $ = cheerio.load(testObj.html); // Load HTML into Cheerio
const doc = $('body')[0]; // Creates a dom-like representation of HTML
// Create an empty attribute pool
@ -293,29 +294,13 @@ describe(__filename, function () {
const cc = contentcollector.makeContentCollector(true, null, apool);
cc.collectContent(doc);
const result = cc.finish();
const recievedAttributes = result.lineAttribs;
const expectedAttributes = testObj.expectedLineAttribs;
const recievedText = new Array(result.lines);
const expectedText = testObj.expectedText;
const gotAttributes = result.lineAttribs;
const wantAttributes = testObj.wantLineAttribs;
const gotText = new Array(result.lines);
const wantText = testObj.wantText;
// Check recieved text matches the expected text
if (arraysEqual(recievedText[0], expectedText)) {
// console.log("PASS: Recieved Text did match Expected Text\nRecieved:", recievedText[0], "\nExpected:", testObj.expectedText)
} else {
console.error('FAIL: Recieved Text did not match Expected Text\nRecieved:', recievedText[0], '\nExpected:', testObj.expectedText);
throw new Error();
}
// Check recieved attributes matches the expected attributes
if (arraysEqual(recievedAttributes, expectedAttributes)) {
// console.log("PASS: Recieved Attributes matched Expected Attributes");
done();
} else {
console.error('FAIL', test, testObj.description);
console.error('FAIL: Recieved Attributes did not match Expected Attributes\nRecieved: ', recievedAttributes, '\nExpected: ', expectedAttributes);
console.error('FAILING HTML', testObj.html);
throw new Error();
}
assert.deepEqual(gotText[0], wantText);
assert.deepEqual(gotAttributes, wantAttributes);
});
});
}
@ -325,7 +310,7 @@ describe(__filename, function () {
function arraysEqual(a, b) {
if (a === b) return true;
if (a == null || b == null) return false;
if (a.length != b.length) return false;
if (a.length !== b.length) return false;
// If you don't care about the order of the elements inside
// the array, you should sort both arrays here.

View file

@ -1,14 +1,9 @@
/* global __dirname, __filename, afterEach, beforeEach, describe, it, process, require */
function m(mod) { return `${__dirname}/../../../src/${mod}`; }
'use strict';
const assert = require('assert').strict;
const common = require('../common');
const hooks = require(m('static/js/pluginfw/hooks'));
const plugins = require(m('static/js/pluginfw/plugin_defs'));
const sinon = require(m('node_modules/sinon'));
const logger = common.logger;
const hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
const plugins = require('ep_etherpad-lite/static/js/pluginfw/plugin_defs');
const sinon = require('ep_etherpad-lite/node_modules/sinon');
describe(__filename, function () {
const hookName = 'testHook';
@ -203,7 +198,7 @@ describe(__filename, function () {
// Test various ways a hook might attempt to settle twice. (Examples: call the callback a second
// time, or call the callback and then return a value.)
describe('bad hook function behavior (double settle)', function () {
beforeEach(function () {
beforeEach(async function () {
sinon.stub(console, 'error');
});
@ -394,6 +389,90 @@ describe(__filename, function () {
});
});
describe('hooks.callFirst', function () {
it('no registered hooks (undefined) -> []', async function () {
delete plugins.hooks.testHook;
assert.deepEqual(hooks.callFirst(hookName), []);
});
it('no registered hooks (empty list) -> []', async function () {
testHooks.length = 0;
assert.deepEqual(hooks.callFirst(hookName), []);
});
it('passes hook name => {}', async function () {
hook.hook_fn = (hn) => { assert.equal(hn, hookName); };
hooks.callFirst(hookName);
});
it('undefined context => {}', async function () {
hook.hook_fn = (hn, ctx) => { assert.deepEqual(ctx, {}); };
hooks.callFirst(hookName);
});
it('null context => {}', async function () {
hook.hook_fn = (hn, ctx) => { assert.deepEqual(ctx, {}); };
hooks.callFirst(hookName, null);
});
it('context unmodified', async function () {
const wantContext = {};
hook.hook_fn = (hn, ctx) => { assert.equal(ctx, wantContext); };
hooks.callFirst(hookName, wantContext);
});
it('predicate never satisfied -> calls all in order', async function () {
const gotCalls = [];
testHooks.length = 0;
for (let i = 0; i < 3; i++) {
const hook = makeHook();
hook.hook_fn = () => { gotCalls.push(i); };
testHooks.push(hook);
}
assert.deepEqual(hooks.callFirst(hookName), []);
assert.deepEqual(gotCalls, [0, 1, 2]);
});
it('stops when predicate is satisfied', async function () {
testHooks.length = 0;
testHooks.push(makeHook(), makeHook('val1'), makeHook('val2'));
assert.deepEqual(hooks.callFirst(hookName), ['val1']);
});
it('skips values that do not satisfy predicate (undefined)', async function () {
testHooks.length = 0;
testHooks.push(makeHook(), makeHook('val1'));
assert.deepEqual(hooks.callFirst(hookName), ['val1']);
});
it('skips values that do not satisfy predicate (empty list)', async function () {
testHooks.length = 0;
testHooks.push(makeHook([]), makeHook('val1'));
assert.deepEqual(hooks.callFirst(hookName), ['val1']);
});
it('null satisifes the predicate', async function () {
testHooks.length = 0;
testHooks.push(makeHook(null), makeHook('val1'));
assert.deepEqual(hooks.callFirst(hookName), [null]);
});
it('non-empty arrays are returned unmodified', async function () {
const want = ['val1'];
testHooks.length = 0;
testHooks.push(makeHook(want), makeHook(['val2']));
assert.equal(hooks.callFirst(hookName), want); // Note: *NOT* deepEqual!
});
it('value can be passed via callback', async function () {
const want = {};
hook.hook_fn = (hn, ctx, cb) => { cb(want); };
const got = hooks.callFirst(hookName);
assert.deepEqual(got, [want]);
assert.equal(got[0], want); // Note: *NOT* deepEqual!
});
});
describe('callHookFnAsync', function () {
const callHookFnAsync = hooks.exportedForTestingOnly.callHookFnAsync; // Convenience shorthand.
@ -558,7 +637,7 @@ describe(__filename, function () {
// Test various ways a hook might attempt to settle twice. (Examples: call the callback a second
// time, or call the callback and then return a value.)
describe('bad hook function behavior (double settle)', function () {
beforeEach(function () {
beforeEach(async function () {
sinon.stub(console, 'error');
});
@ -888,4 +967,243 @@ describe(__filename, function () {
});
});
});
describe('hooks.callAllSerial', function () {
describe('basic behavior', function () {
it('calls all asynchronously, serially, in order', async function () {
const gotCalls = [];
testHooks.length = 0;
for (let i = 0; i < 3; i++) {
const hook = makeHook();
hook.hook_fn = async () => {
gotCalls.push(i);
// Check gotCalls asynchronously to ensure that the next hook function does not start
// executing before this hook function has resolved.
return await new Promise((resolve) => {
setImmediate(() => {
assert.deepEqual(gotCalls, [...Array(i + 1).keys()]);
resolve(i);
});
});
};
testHooks.push(hook);
}
assert.deepEqual(await hooks.callAllSerial(hookName), [0, 1, 2]);
assert.deepEqual(gotCalls, [0, 1, 2]);
});
it('passes hook name', async function () {
hook.hook_fn = async (hn) => { assert.equal(hn, hookName); };
await hooks.callAllSerial(hookName);
});
it('undefined context -> {}', async function () {
hook.hook_fn = async (hn, ctx) => { assert.deepEqual(ctx, {}); };
await hooks.callAllSerial(hookName);
});
it('null context -> {}', async function () {
hook.hook_fn = async (hn, ctx) => { assert.deepEqual(ctx, {}); };
await hooks.callAllSerial(hookName, null);
});
it('context unmodified', async function () {
const wantContext = {};
hook.hook_fn = async (hn, ctx) => { assert.equal(ctx, wantContext); };
await hooks.callAllSerial(hookName, wantContext);
});
});
describe('result processing', function () {
it('no registered hooks (undefined) -> []', async function () {
delete plugins.hooks[hookName];
assert.deepEqual(await hooks.callAllSerial(hookName), []);
});
it('no registered hooks (empty list) -> []', async function () {
testHooks.length = 0;
assert.deepEqual(await hooks.callAllSerial(hookName), []);
});
it('flattens one level', async function () {
testHooks.length = 0;
testHooks.push(makeHook(1), makeHook([2]), makeHook([[3]]));
assert.deepEqual(await hooks.callAllSerial(hookName), [1, 2, [3]]);
});
it('filters out undefined', async function () {
testHooks.length = 0;
testHooks.push(makeHook(), makeHook([2]), makeHook([[3]]), makeHook(Promise.resolve()));
assert.deepEqual(await hooks.callAllSerial(hookName), [2, [3]]);
});
it('preserves null', async function () {
testHooks.length = 0;
testHooks.push(makeHook(null), makeHook([2]), makeHook(Promise.resolve(null)));
assert.deepEqual(await hooks.callAllSerial(hookName), [null, 2, null]);
});
it('all undefined -> []', async function () {
testHooks.length = 0;
testHooks.push(makeHook(), makeHook(Promise.resolve()));
assert.deepEqual(await hooks.callAllSerial(hookName), []);
});
});
});
describe('hooks.aCallFirst', function () {
it('no registered hooks (undefined) -> []', async function () {
delete plugins.hooks.testHook;
assert.deepEqual(await hooks.aCallFirst(hookName), []);
});
it('no registered hooks (empty list) -> []', async function () {
testHooks.length = 0;
assert.deepEqual(await hooks.aCallFirst(hookName), []);
});
it('passes hook name => {}', async function () {
hook.hook_fn = (hn) => { assert.equal(hn, hookName); };
await hooks.aCallFirst(hookName);
});
it('undefined context => {}', async function () {
hook.hook_fn = (hn, ctx) => { assert.deepEqual(ctx, {}); };
await hooks.aCallFirst(hookName);
});
it('null context => {}', async function () {
hook.hook_fn = (hn, ctx) => { assert.deepEqual(ctx, {}); };
await hooks.aCallFirst(hookName, null);
});
it('context unmodified', async function () {
const wantContext = {};
hook.hook_fn = (hn, ctx) => { assert.equal(ctx, wantContext); };
await hooks.aCallFirst(hookName, wantContext);
});
it('default predicate: predicate never satisfied -> calls all in order', async function () {
const gotCalls = [];
testHooks.length = 0;
for (let i = 0; i < 3; i++) {
const hook = makeHook();
hook.hook_fn = () => { gotCalls.push(i); };
testHooks.push(hook);
}
assert.deepEqual(await hooks.aCallFirst(hookName), []);
assert.deepEqual(gotCalls, [0, 1, 2]);
});
it('calls hook functions serially', async function () {
const gotCalls = [];
testHooks.length = 0;
for (let i = 0; i < 3; i++) {
const hook = makeHook();
hook.hook_fn = async () => {
gotCalls.push(i);
// Check gotCalls asynchronously to ensure that the next hook function does not start
// executing before this hook function has resolved.
return await new Promise((resolve) => {
setImmediate(() => {
assert.deepEqual(gotCalls, [...Array(i + 1).keys()]);
resolve();
});
});
};
testHooks.push(hook);
}
assert.deepEqual(await hooks.aCallFirst(hookName), []);
assert.deepEqual(gotCalls, [0, 1, 2]);
});
it('default predicate: stops when satisfied', async function () {
testHooks.length = 0;
testHooks.push(makeHook(), makeHook('val1'), makeHook('val2'));
assert.deepEqual(await hooks.aCallFirst(hookName), ['val1']);
});
it('default predicate: skips values that do not satisfy (undefined)', async function () {
testHooks.length = 0;
testHooks.push(makeHook(), makeHook('val1'));
assert.deepEqual(await hooks.aCallFirst(hookName), ['val1']);
});
it('default predicate: skips values that do not satisfy (empty list)', async function () {
testHooks.length = 0;
testHooks.push(makeHook([]), makeHook('val1'));
assert.deepEqual(await hooks.aCallFirst(hookName), ['val1']);
});
it('default predicate: null satisifes', async function () {
testHooks.length = 0;
testHooks.push(makeHook(null), makeHook('val1'));
assert.deepEqual(await hooks.aCallFirst(hookName), [null]);
});
it('custom predicate: called for each hook function', async function () {
testHooks.length = 0;
testHooks.push(makeHook(0), makeHook(1), makeHook(2));
let got = 0;
await hooks.aCallFirst(hookName, null, null, (val) => { ++got; return false; });
assert.equal(got, 3);
});
it('custom predicate: boolean false/true continues/stops iteration', async function () {
testHooks.length = 0;
testHooks.push(makeHook(1), makeHook(2), makeHook(3));
let nCall = 0;
const predicate = (val) => {
assert.deepEqual(val, [++nCall]);
return nCall === 2;
};
assert.deepEqual(await hooks.aCallFirst(hookName, null, null, predicate), [2]);
assert.equal(nCall, 2);
});
it('custom predicate: non-boolean falsy/truthy continues/stops iteration', async function () {
testHooks.length = 0;
testHooks.push(makeHook(1), makeHook(2), makeHook(3));
let nCall = 0;
const predicate = (val) => {
assert.deepEqual(val, [++nCall]);
return nCall === 2 ? {} : null;
};
assert.deepEqual(await hooks.aCallFirst(hookName, null, null, predicate), [2]);
assert.equal(nCall, 2);
});
it('custom predicate: array value passed unmodified to predicate', async function () {
const want = [0];
hook.hook_fn = () => want;
const predicate = (got) => { assert.equal(got, want); }; // Note: *NOT* deepEqual!
await hooks.aCallFirst(hookName, null, null, predicate);
});
it('custom predicate: normalized value passed to predicate (undefined)', async function () {
const predicate = (got) => { assert.deepEqual(got, []); };
await hooks.aCallFirst(hookName, null, null, predicate);
});
it('custom predicate: normalized value passed to predicate (null)', async function () {
hook.hook_fn = () => null;
const predicate = (got) => { assert.deepEqual(got, [null]); };
await hooks.aCallFirst(hookName, null, null, predicate);
});
it('non-empty arrays are returned unmodified', async function () {
const want = ['val1'];
testHooks.length = 0;
testHooks.push(makeHook(want), makeHook(['val2']));
assert.equal(await hooks.aCallFirst(hookName), want); // Note: *NOT* deepEqual!
});
it('value can be passed via callback', async function () {
const want = {};
hook.hook_fn = (hn, ctx, cb) => { cb(want); };
const got = await hooks.aCallFirst(hookName);
assert.deepEqual(got, [want]);
assert.equal(got[0], want); // Note: *NOT* deepEqual!
});
});
});

View file

@ -1,17 +1,22 @@
/* global __dirname, __filename, Buffer, afterEach, before, beforeEach, describe, it, require */
function m(mod) { return `${__dirname}/../../../src/${mod}`; }
'use strict';
const assert = require('assert').strict;
const common = require('../common');
const plugins = require(m('static/js/pluginfw/plugin_defs'));
const settings = require(m('node/utils/Settings'));
const plugins = require('ep_etherpad-lite/static/js/pluginfw/plugin_defs');
const settings = require('ep_etherpad-lite/node/utils/Settings');
describe(__filename, function () {
let agent;
const backups = {};
const authHookNames = ['preAuthorize', 'authenticate', 'authorize'];
const failHookNames = ['preAuthzFailure', 'authnFailure', 'authzFailure', 'authFailure'];
const makeHook = (hookName, hookFn) => ({
hook_fn: hookFn,
hook_fn_name: `fake_plugin/${hookName}`,
hook_name: hookName,
part: {plugin: 'fake_plugin'},
});
before(async function () { agent = await common.init(); });
beforeEach(async function () {
backups.hooks = {};
@ -141,7 +146,10 @@ describe(__filename, function () {
const h0 = new Handler(hookName, '_0');
const h1 = new Handler(hookName, '_1');
handlers[hookName] = [h0, h1];
plugins.hooks[hookName] = [{hook_fn: h0.handle.bind(h0)}, {hook_fn: h1.handle.bind(h1)}];
plugins.hooks[hookName] = [
makeHook(hookName, h0.handle.bind(h0)),
makeHook(hookName, h1.handle.bind(h1)),
];
}
});
@ -197,7 +205,7 @@ describe(__filename, function () {
it('runs preAuthzFailure hook when access is denied', async function () {
handlers.preAuthorize[0].innerHandle = () => [false];
let called = false;
plugins.hooks.preAuthzFailure = [{hook_fn: (hookName, {req, res}, cb) => {
plugins.hooks.preAuthzFailure = [makeHook('preAuthzFailure', (hookName, {req, res}, cb) => {
assert.equal(hookName, 'preAuthzFailure');
assert(req != null);
assert(res != null);
@ -205,7 +213,7 @@ describe(__filename, function () {
called = true;
res.status(200).send('injected');
return cb([true]);
}}];
})];
await agent.get('/admin/').auth('admin', 'admin-password').expect(200, 'injected');
assert(called);
});
@ -402,11 +410,11 @@ describe(__filename, function () {
};
const handlers = {};
beforeEach(function () {
beforeEach(async function () {
failHookNames.forEach((hookName) => {
const handler = new Handler(hookName);
handlers[hookName] = handler;
plugins.hooks[hookName] = [{hook_fn: handler.handle.bind(handler)}];
plugins.hooks[hookName] = [makeHook(hookName, handler.handle.bind(handler))];
});
settings.requireAuthentication = true;
settings.requireAuthorization = true;

View file

@ -1,5 +1,5 @@
'use strict';
const helper = {}; // eslint-disable-line
const helper = {}; // eslint-disable-line no-redeclare
(function () {
let $iframe; const
@ -181,7 +181,7 @@ const helper = {}; // eslint-disable-line
};
helper.waitFor = function (conditionFunc, timeoutTime = 1900, intervalTime = 10) {
const deferred = $.Deferred(); // eslint-disable-line
const deferred = new $.Deferred();
const _fail = deferred.fail.bind(deferred);
let listenForFail = false;

View file

@ -6,12 +6,12 @@
*/
helper.spyOnSocketIO = function () {
helper.contentWindow().pad.socket.on('message', (msg) => {
if (msg.type == 'COLLABROOM') {
if (msg.data.type == 'ACCEPT_COMMIT') {
if (msg.type === 'COLLABROOM') {
if (msg.data.type === 'ACCEPT_COMMIT') {
helper.commits.push(msg);
} else if (msg.data.type == 'USER_NEWINFO') {
} else if (msg.data.type === 'USER_NEWINFO') {
helper.userInfos.push(msg);
} else if (msg.data.type == 'CHAT_MESSAGE') {
} else if (msg.data.type === 'CHAT_MESSAGE') {
helper.chatMessages.push(msg);
}
}

View file

@ -1,3 +1,5 @@
'use strict';
/**
* the contentWindow is either the normal pad or timeslider
*

View file

@ -1,3 +1,5 @@
'use strict';
describe('All the alphabet works n stuff', function () {
const expectedString = 'abcdefghijklmnopqrstuvwxyz';
@ -9,7 +11,6 @@ describe('All the alphabet works n stuff', function () {
it('when you enter any char it appears right', 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();

View file

@ -1,3 +1,5 @@
'use strict';
describe('author of pad edition', function () {
const REGULAR_LINE = 0;
const LINE_WITH_ORDERED_LIST = 1;
@ -5,10 +7,11 @@ describe('author of pad edition', function () {
// author 1 creates a new pad with some content (regular lines and lists)
before(function (done) {
var padId = helper.newPad(() => {
const padId = helper.newPad(() => {
// make sure pad has at least 3 lines
const $firstLine = helper.padInner$('div').first();
const threeLines = ['regular line', 'line with ordered list', 'line with unordered list'].join('<br>');
const threeLines = ['regular line', 'line with ordered list', 'line with unordered list']
.join('<br>');
$firstLine.html(threeLines);
// wait for lines to be processed by Etherpad
@ -43,7 +46,8 @@ describe('author of pad edition', function () {
setTimeout(() => {
// Expire cookie, so author is changed after reloading the pad.
// See https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#Example_4_Reset_the_previous_cookie
helper.padChrome$.document.cookie = 'token=foo;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
helper.padChrome$.document.cookie =
'token=foo;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
helper.newPad(done, padId);
}, 1000);
@ -59,24 +63,22 @@ describe('author of pad edition', function () {
changeLineAndCheckOnlyThatChangeIsFromThisAuthor(REGULAR_LINE, 'x', done);
});
it('marks only the new content as changes of the second user on a line with ordered list', function (done) {
it('marks only the new content as changes of the second user on a ' +
'line with ordered list', function (done) {
changeLineAndCheckOnlyThatChangeIsFromThisAuthor(LINE_WITH_ORDERED_LIST, 'y', done);
});
it('marks only the new content as changes of the second user on a line with unordered list', function (done) {
it('marks only the new content as changes of the second user on ' +
'a line with unordered list', function (done) {
changeLineAndCheckOnlyThatChangeIsFromThisAuthor(LINE_WITH_UNORDERED_LIST, 'z', done);
});
/* ********************** Helper functions ************************ */
var getLine = function (lineNumber) {
return helper.padInner$('div').eq(lineNumber);
};
const getLine = (lineNumber) => helper.padInner$('div').eq(lineNumber);
const getAuthorFromClassList = function (classes) {
return classes.find((cls) => cls.startsWith('author'));
};
const getAuthorFromClassList = (classes) => classes.find((cls) => cls.startsWith('author'));
var changeLineAndCheckOnlyThatChangeIsFromThisAuthor = function (lineNumber, textChange, done) {
const changeLineAndCheckOnlyThatChangeIsFromThisAuthor = (lineNumber, textChange, done) => {
// get original author class
const classes = getLine(lineNumber).find('span').first().attr('class').split(' ');
const originalAuthor = getAuthorFromClassList(classes);

View file

@ -1,3 +1,5 @@
'use strict';
describe('bold button', function () {
// create a new pad before each test run
beforeEach(function (cb) {
@ -19,7 +21,6 @@ describe('bold button', function () {
const $boldButton = chrome$('.buttonicon-bold');
$boldButton.click();
// ace creates a new dom element when you press a button, so just get the first text element again
const $newFirstTextElement = inner$('div').first();
// is there a <b> element now?
@ -36,7 +37,6 @@ describe('bold button', function () {
it('makes text bold on keypress', 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();
@ -44,12 +44,11 @@ describe('bold button', function () {
// select this text element
$firstTextElement.sendkeys('{selectall}');
const e = inner$.Event(helper.evtType);
const e = new inner$.Event(helper.evtType);
e.ctrlKey = true; // Control key
e.which = 66; // b
inner$('#innerdocbody').trigger(e);
// ace creates a new dom element when you press a button, so just get the first text element again
const $newFirstTextElement = inner$('div').first();
// is there a <b> element now?

View file

@ -1,7 +1,9 @@
'use strict';
describe('As the caret is moved is the UI properly updated?', function () {
/*
let padName;
const numberOfRows = 50;
/*
//create a new pad before each test run
beforeEach(function(cb){
@ -16,7 +18,8 @@ describe('As the caret is moved is the UI properly updated?', function () {
*/
/* Tests to do
* Keystroke up (38), down (40), left (37), right (39) with and without special keys IE control / shift
* Keystroke up (38), down (40), left (37), right (39)
* with and without special keys IE control / shift
* Page up (33) / down (34) with and without special keys
* Page up on the first line shouldn't move the viewport
* Down down on the last line shouldn't move the viewport
@ -25,7 +28,9 @@ describe('As the caret is moved is the UI properly updated?', function () {
*/
/* Challenges
* How do we keep the authors focus on a line if the lines above the author are modified? We should only redraw the user to a location if they are typing and make sure shift and arrow keys aren't redrawing the UI else highlight - copy/paste would get broken
* How do we keep the authors focus on a line if the lines above the author are modified?
* We should only redraw the user to a location if they are typing and make sure shift
* and arrow keys aren't redrawing the UI else highlight - copy/paste would get broken
* How can we simulate an edit event in the test framework?
*/
/*
@ -200,7 +205,8 @@ console.log(inner$);
var chrome$ = helper.padChrome$;
var numberOfRows = 50;
//ace creates a new dom element when you press a keystroke, so just get the first text element again
// ace creates a new dom element when you press a keystroke,
// so just get the first text element again
var $newFirstTextElement = inner$("div").first();
var originalDivHeight = inner$("div").first().css("height");
prepareDocument(numberOfRows, $newFirstTextElement); // N lines into the first div as a target
@ -208,28 +214,33 @@ console.log(inner$);
helper.waitFor(function(){ // Wait for the DOM to register the new items
return inner$("div").first().text().length == 6;
}).done(function(){ // Once the DOM has registered the items
inner$("div").each(function(index){ // Randomize the item heights (replicates images / headings etc)
// Randomize the item heights (replicates images / headings etc)
inner$("div").each(function(index){
var random = Math.floor(Math.random() * (50)) + 20;
$(this).css("height", random+"px");
});
console.log(caretPosition(inner$));
var newDivHeight = inner$("div").first().css("height");
var heightHasChanged = originalDivHeight != newDivHeight; // has the new div height changed from the original div height
// has the new div height changed from the original div height
var heightHasChanged = originalDivHeight != newDivHeight;
expect(heightHasChanged).to.be(true); // expect the first line to be blank
});
// Is this Element now visible to the pad user?
helper.waitFor(function(){ // Wait for the DOM to register the new items
return isScrolledIntoView(inner$("div:nth-child("+numberOfRows+")"), inner$); // Wait for the DOM to scroll into place
// Wait for the DOM to scroll into place
return isScrolledIntoView(inner$("div:nth-child("+numberOfRows+")"), inner$);
}).done(function(){ // Once the DOM has registered the items
inner$("div").each(function(index){ // Randomize the item heights (replicates images / headings etc)
// Randomize the item heights (replicates images / headings etc)
inner$("div").each(function(index){
var random = Math.floor(Math.random() * (80 - 20 + 1)) + 20;
$(this).css("height", random+"px");
});
var newDivHeight = inner$("div").first().css("height");
var heightHasChanged = originalDivHeight != newDivHeight; // has the new div height changed from the original div height
// has the new div height changed from the original div height
var heightHasChanged = originalDivHeight != newDivHeight;
expect(heightHasChanged).to.be(true); // expect the first line to be blank
});
var i = 0;
@ -241,7 +252,8 @@ console.log(inner$);
// Does scrolling back up the pad with the up arrow show the correct contents?
helper.waitFor(function(){ // Wait for the new position to be in place
try{
return isScrolledIntoView(inner$("div:nth-child("+numberOfRows+")"), inner$); // Wait for the DOM to scroll into place
// Wait for the DOM to scroll into place
return isScrolledIntoView(inner$("div:nth-child("+numberOfRows+")"), inner$);
}catch(e){
return false;
}
@ -256,7 +268,8 @@ console.log(inner$);
// Does scrolling back up the pad with the up arrow show the correct contents?
helper.waitFor(function(){ // Wait for the new position to be in place
try{
return isScrolledIntoView(inner$("div:nth-child(0)"), inner$); // Wait for the DOM to scroll into place
// Wait for the DOM to scroll into place
return isScrolledIntoView(inner$("div:nth-child(0)"), inner$);
}catch(e){
return false;
}
@ -276,7 +289,8 @@ console.log(inner$);
// Does scrolling back up the pad with the up arrow show the correct contents?
helper.waitFor(function(){ // Wait for the new position to be in place
return isScrolledIntoView(inner$("div:nth-child(1)"), inner$); // Wait for the DOM to scroll into place
// Wait for the DOM to scroll into place
return isScrolledIntoView(inner$("div:nth-child(1)"), inner$);
}).done(function(){ // Once the DOM has registered the items
expect(true).to.be(true);
done();
@ -284,17 +298,19 @@ console.log(inner$);
*/
});
function prepareDocument(n, target) { // generates a random document with random content on n lines
// generates a random document with random content on n lines
const prepareDocument = (n, target) => {
let i = 0;
while (i < n) { // for each line
target.sendkeys(makeStr()); // generate a random string and send that to the editor
target.sendkeys('{enter}'); // generator an enter keypress
i++; // rinse n times
}
}
};
function keyEvent(target, charCode, ctrl, shift) { // sends a charCode to the window
const e = target.Event(helper.evtType);
// sends a charCode to the window
const keyEvent = (target, charCode, ctrl, shift) => {
const e = new target.Event(helper.evtType);
if (ctrl) {
e.ctrlKey = true; // Control key
}
@ -304,30 +320,33 @@ function keyEvent(target, charCode, ctrl, shift) { // sends a charCode to the wi
e.which = charCode;
e.keyCode = charCode;
target('#innerdocbody').trigger(e);
}
};
function makeStr() { // from http://stackoverflow.com/questions/1349404/generate-a-string-of-5-random-characters-in-javascript
// from http://stackoverflow.com/questions/1349404/generate-a-string-of-5-random-characters-in-javascript
const makeStr = () => {
let text = '';
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < 5; i++) text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
};
function isScrolledIntoView(elem, $) { // from http://stackoverflow.com/questions/487073/check-if-element-is-visible-after-scrolling
// from http://stackoverflow.com/questions/487073/check-if-element-is-visible-after-scrolling
const isScrolledIntoView = (elem, $) => {
const docViewTop = $(window).scrollTop();
const docViewBottom = docViewTop + $(window).height();
const elemTop = $(elem).offset().top; // how far the element is from the top of it's container
let elemBottom = elemTop + $(elem).height(); // how far plus the height of the elem.. IE is it all in?
// how far plus the height of the elem.. IE is it all in?
let elemBottom = elemTop + $(elem).height();
elemBottom -= 16; // don't ask, sorry but this is needed..
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}
};
function caretPosition($) {
const caretPosition = ($) => {
const doc = $.window.document;
const pos = doc.getSelection();
pos.y = pos.anchorNode.parentElement.offsetTop;
pos.x = pos.anchorNode.parentElement.offsetLeft;
return pos;
}
};

View file

@ -1,3 +1,5 @@
'use strict';
describe('change user color', function () {
// create a new pad before each test run
beforeEach(function (cb) {
@ -5,7 +7,8 @@ describe('change user color', function () {
this.timeout(60000);
});
it('Color picker matches original color and remembers the user color after a refresh', function (done) {
it('Color picker matches original color and remembers the user color' +
' after a refresh', function (done) {
this.timeout(60000);
const chrome$ = helper.padChrome$;
@ -60,7 +63,6 @@ describe('change user color', function () {
});
it('Own user color is shown when you enter a chat', function (done) {
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;
const $colorOption = helper.padChrome$('#options-colorscheck');
@ -90,13 +92,15 @@ describe('change user color', function () {
$chatButton.click();
const $chatInput = chrome$('#chatinput');
$chatInput.sendkeys('O hi'); // simulate a keypress of typing user
$chatInput.sendkeys('{enter}'); // simulate a keypress of enter actually does evt.which = 10 not 13
// simulate a keypress of enter actually does evt.which = 10 not 13
$chatInput.sendkeys('{enter}');
// check if chat shows up
helper.waitFor(() => chrome$('#chattext').children('p').length !== 0 // wait until the chat message shows up
// wait until the chat message shows up
helper.waitFor(() => chrome$('#chattext').children('p').length !== 0
).done(() => {
const $firstChatMessage = chrome$('#chattext').children('p');
expect($firstChatMessage.css('background-color')).to.be(testColorRGB); // expect the first chat message to be of the user's color
// expect the first chat message to be of the user's color
expect($firstChatMessage.css('background-color')).to.be(testColorRGB);
done();
});
});

View file

@ -1,3 +1,5 @@
'use strict';
describe('change username value', function () {
// create a new pad before each test run
beforeEach(function (cb) {

View file

@ -1,10 +1,13 @@
'use strict';
describe('Chat messages and UI', function () {
// create a new pad before each test run
beforeEach(function (cb) {
helper.newPad(cb);
});
it('opens chat, sends a message, makes sure it exists on the page and hides chat', async function () {
it('opens chat, sends a message, makes sure it exists ' +
'on the page and hides chat', async function () {
const chatValue = 'JohnMcLear';
await helper.showChat();
@ -31,7 +34,8 @@ describe('Chat messages and UI', function () {
await helper.showChat();
await helper.sendChatMessage(`{enter}${chatValue}{enter}`); // simulate a keypress of typing enter, mluto and enter (to send 'mluto')
// simulate a keypress of typing enter, mluto and enter (to send 'mluto')
await helper.sendChatMessage(`{enter}${chatValue}{enter}`);
const chat = helper.chatTextParagraphs();
@ -44,7 +48,8 @@ describe('Chat messages and UI', function () {
expect(chat.text()).to.be(`${username}${time} ${chatValue}`);
});
it('makes chat stick to right side of the screen via settings, remove sticky via settings, close it', async function () {
it('makes chat stick to right side of the screen via settings, ' +
'remove sticky via settings, close it', async function () {
await helper.showSettings();
await helper.enableStickyChatviaSettings();
@ -60,7 +65,8 @@ describe('Chat messages and UI', function () {
expect(helper.isChatboxShown()).to.be(false);
});
it('makes chat stick to right side of the screen via icon on the top right, remove sticky via icon, close it', async function () {
it('makes chat stick to right side of the screen via icon on the top' +
' right, remove sticky via icon, close it', async function () {
await helper.showChat();
await helper.enableStickyChatviaIcon();
@ -76,10 +82,9 @@ describe('Chat messages and UI', function () {
expect(helper.isChatboxShown()).to.be(false);
});
xit('Checks showChat=false URL Parameter hides chat then when removed it shows chat', function (done) {
xit('Checks showChat=false URL Parameter hides chat then' +
' when removed it shows chat', function (done) {
this.timeout(60000);
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;
setTimeout(() => { // give it a second to save the username on the server side
helper.newPad({ // get a new pad, but don't clear the cookies

View file

@ -1,3 +1,5 @@
'use strict';
describe('chat-load-messages', function () {
let padName;
@ -7,7 +9,6 @@ describe('chat-load-messages', function () {
});
it('adds a lot of messages', function (done) {
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;
const chatButton = chrome$('#chaticon');
chatButton.click();
@ -19,12 +20,12 @@ describe('chat-load-messages', function () {
const messages = 140;
for (let i = 1; i <= messages; i++) {
let num = `${i}`;
if (num.length == 1) num = `00${num}`;
if (num.length == 2) num = `0${num}`;
if (num.length === 1) num = `00${num}`;
if (num.length === 2) num = `0${num}`;
chatInput.sendkeys(`msg${num}`);
chatInput.sendkeys('{enter}');
}
helper.waitFor(() => chatText.children('p').length == messages, 60000).always(() => {
helper.waitFor(() => chatText.children('p').length === messages, 60000).always(() => {
expect(chatText.children('p').length).to.be(messages);
helper.newPad(done, padName);
});
@ -38,7 +39,7 @@ describe('chat-load-messages', function () {
const chatButton = chrome$('#chaticon');
chatButton.click();
chatText = chrome$('#chattext');
return chatText.children('p').length == expectedCount;
return chatText.children('p').length === expectedCount;
}).always(() => {
expect(chatText.children('p').length).to.be(expectedCount);
done();
@ -54,7 +55,7 @@ describe('chat-load-messages', function () {
const loadMsgBtn = chrome$('#chatloadmessagesbutton');
loadMsgBtn.click();
helper.waitFor(() => chatText.children('p').length == expectedCount).always(() => {
helper.waitFor(() => chatText.children('p').length === expectedCount).always(() => {
expect(chatText.children('p').length).to.be(expectedCount);
done();
});
@ -65,13 +66,12 @@ describe('chat-load-messages', function () {
const chrome$ = helper.padChrome$;
const chatButton = chrome$('#chaticon');
chatButton.click();
const chatText = chrome$('#chattext');
const loadMsgBtn = chrome$('#chatloadmessagesbutton');
const loadMsgBall = chrome$('#chatloadmessagesball');
loadMsgBtn.click();
helper.waitFor(() => loadMsgBtn.css('display') == expectedDisplay &&
loadMsgBall.css('display') == expectedDisplay).always(() => {
helper.waitFor(() => loadMsgBtn.css('display') === expectedDisplay &&
loadMsgBall.css('display') === expectedDisplay).always(() => {
expect(loadMsgBtn.css('display')).to.be(expectedDisplay);
expect(loadMsgBall.css('display')).to.be(expectedDisplay);
done();

View file

@ -1,3 +1,5 @@
'use strict';
describe('clear authorship colors button', function () {
// create a new pad before each test run
beforeEach(function (cb) {
@ -17,9 +19,6 @@ describe('clear authorship colors button', function () {
// get the first text element out of the inner iframe
const $firstTextElement = inner$('div').first();
// Get the original text
const originalText = inner$('div').first().text();
// Set some new text
const sentText = 'Hello';
@ -28,7 +27,8 @@ describe('clear authorship colors button', function () {
$firstTextElement.sendkeys(sentText);
$firstTextElement.sendkeys('{rightarrow}');
helper.waitFor(() => inner$('div span').first().attr('class').indexOf('author') !== -1 // wait until we have the full value available
// wait until we have the full value available
helper.waitFor(() => inner$('div span').first().attr('class').indexOf('author') !== -1
).done(() => {
// IE hates you if you don't give focus to the inner frame bevore you do a clearAuthorship
inner$('div').first().focus();
@ -37,16 +37,13 @@ describe('clear authorship colors button', function () {
const $clearauthorshipcolorsButton = chrome$('.buttonicon-clearauthorship');
$clearauthorshipcolorsButton.click();
// does the first divs span include an author class?
var hasAuthorClass = inner$('div span').first().attr('class').indexOf('author') !== -1;
// expect(hasAuthorClass).to.be(false);
// does the first div include an author class?
var hasAuthorClass = inner$('div').first().attr('class').indexOf('author') !== -1;
const hasAuthorClass = inner$('div').first().attr('class').indexOf('author') !== -1;
expect(hasAuthorClass).to.be(false);
helper.waitFor(() => {
const disconnectVisible = chrome$('div.disconnected').attr('class').indexOf('visible') === -1;
const disconnectVisible =
chrome$('div.disconnected').attr('class').indexOf('visible') === -1;
return (disconnectVisible === true);
});
@ -69,9 +66,6 @@ describe('clear authorship colors button', function () {
// get the first text element out of the inner iframe
const $firstTextElement = inner$('div').first();
// Get the original text
const originalText = inner$('div').first().text();
// Set some new text
const sentText = 'Hello';
@ -80,7 +74,9 @@ describe('clear authorship colors button', function () {
$firstTextElement.sendkeys(sentText);
$firstTextElement.sendkeys('{rightarrow}');
helper.waitFor(() => inner$('div span').first().attr('class').indexOf('author') !== -1 // wait until we have the full value available
// wait until we have the full value available
helper.waitFor(
() => inner$('div span').first().attr('class').indexOf('author') !== -1
).done(() => {
// IE hates you if you don't give focus to the inner frame bevore you do a clearAuthorship
inner$('div').first().focus();
@ -89,15 +85,11 @@ describe('clear authorship colors button', function () {
const $clearauthorshipcolorsButton = chrome$('.buttonicon-clearauthorship');
$clearauthorshipcolorsButton.click();
// does the first divs span include an author class?
var hasAuthorClass = inner$('div span').first().attr('class').indexOf('author') !== -1;
// expect(hasAuthorClass).to.be(false);
// does the first div include an author class?
var hasAuthorClass = inner$('div').first().attr('class').indexOf('author') !== -1;
let hasAuthorClass = inner$('div').first().attr('class').indexOf('author') !== -1;
expect(hasAuthorClass).to.be(false);
const e = inner$.Event(helper.evtType);
const e = new inner$.Event(helper.evtType);
e.ctrlKey = true; // Control key
e.which = 90; // z
inner$('#innerdocbody').trigger(e); // shouldn't od anything
@ -115,7 +107,8 @@ describe('clear authorship colors button', function () {
expect(hasAuthorClass).to.be(false);
helper.waitFor(() => {
const disconnectVisible = chrome$('div.disconnected').attr('class').indexOf('visible') === -1;
const disconnectVisible =
chrome$('div.disconnected').attr('class').indexOf('visible') === -1;
return (disconnectVisible === true);
});

View file

@ -1,3 +1,5 @@
'use strict';
describe('delete keystroke', function () {
// create a new pad before each test run
beforeEach(function (cb) {
@ -7,7 +9,6 @@ describe('delete keystroke', function () {
it('makes text delete', 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();
@ -15,15 +16,10 @@ describe('delete keystroke', function () {
// get the original length of this element
const elementLength = $firstTextElement.text().length;
// get the original string value minus the last char
const originalTextValue = $firstTextElement.text();
const originalTextValueMinusFirstChar = originalTextValue.substring(1, originalTextValue.length);
// simulate key presses to delete content
$firstTextElement.sendkeys('{leftarrow}'); // simulate a keypress of the left arrow key
$firstTextElement.sendkeys('{del}'); // simulate a keypress of delete
// ace creates a new dom element when you press a keystroke, so just get the first text element again
const $newFirstTextElement = inner$('div').first();
// get the new length of this element

View file

@ -1,4 +1,6 @@
// WARNING: drag and drop is only simulated on these tests, so manual testing might also be necessary
'use strict';
// WARNING: drag and drop is only simulated on these tests, manual testing might also be necessary
describe('drag and drop', function () {
before(function (done) {
helper.newPad(() => {
@ -78,18 +80,19 @@ describe('drag and drop', function () {
});
/* ********************* Helper functions/constants ********************* */
var TARGET_LINE = 2;
var FIRST_SOURCE_LINE = 5;
const TARGET_LINE = 2;
const FIRST_SOURCE_LINE = 5;
var getLine = function (lineNumber) {
const getLine = (lineNumber) => {
const $lines = helper.padInner$('div');
return $lines.slice(lineNumber, lineNumber + 1);
};
var createScriptWithSeveralLines = function (done) {
const createScriptWithSeveralLines = (done) => {
// create some lines to be used on the tests
const $firstLine = helper.padInner$('div').first();
$firstLine.html('...<br>...<br>Target line []<br>...<br>...<br>Source line 1.<br>Source line 2.<br>');
$firstLine.html('...<br>...<br>Target line []<br>...<br>...<br>' +
'Source line 1.<br>Source line 2.<br>');
// wait for lines to be split
helper.waitFor(() => {
@ -98,7 +101,7 @@ describe('drag and drop', function () {
}).done(done);
};
var selectPartOfSourceLine = function () {
const selectPartOfSourceLine = () => {
const $sourceLine = getLine(FIRST_SOURCE_LINE);
// select 'line 1' from 'Source line 1.'
@ -106,14 +109,14 @@ describe('drag and drop', function () {
const end = start + 'line 1'.length;
helper.selectLines($sourceLine, $sourceLine, start, end);
};
var selectMultipleSourceLines = function () {
const selectMultipleSourceLines = () => {
const $firstSourceLine = getLine(FIRST_SOURCE_LINE);
const $lastSourceLine = getLine(FIRST_SOURCE_LINE + 1);
helper.selectLines($firstSourceLine, $lastSourceLine);
};
var dragSelectedTextAndDropItIntoMiddleOfLine = function (targetLineNumber) {
const dragSelectedTextAndDropItIntoMiddleOfLine = (targetLineNumber) => {
// dragstart: start dragging content
triggerEvent('dragstart');
@ -126,7 +129,7 @@ describe('drag and drop', function () {
triggerEvent('dragend');
};
var getHtmlFromSelectedText = function () {
const getHtmlFromSelectedText = () => {
const innerDocument = helper.padInner$.document;
const range = innerDocument.getSelection().getRangeAt(0);
@ -139,12 +142,12 @@ describe('drag and drop', function () {
return draggedHtml;
};
var triggerEvent = function (eventName) {
const event = helper.padInner$.Event(eventName);
const triggerEvent = (eventName) => {
const event = new helper.padInner$.Event(eventName);
helper.padInner$('#innerdocbody').trigger(event);
};
var moveSelectionIntoTarget = function (draggedHtml, targetLineNumber) {
const moveSelectionIntoTarget = (draggedHtml, targetLineNumber) => {
const innerDocument = helper.padInner$.document;
// delete original content

View file

@ -1,3 +1,5 @@
'use strict';
describe('embed links', function () {
const objectify = function (str) {
const hash = {};

View file

@ -1,3 +1,5 @@
'use strict';
describe('enter keystroke', function () {
// create a new pad before each test run
beforeEach(function (cb) {
@ -7,7 +9,6 @@ describe('enter keystroke', function () {
it('creates a new line & puts cursor onto a new line', 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();
@ -18,14 +19,12 @@ describe('enter keystroke', function () {
// simulate key presses to enter content
$firstTextElement.sendkeys('{enter}');
// ace creates a new dom element when you press a keystroke, so just get the first text element again
const $newFirstTextElement = inner$('div').first();
helper.waitFor(() => inner$('div').first().text() === '').done(() => {
const $newSecondLine = inner$('div').first().next();
const newFirstTextElementValue = inner$('div').first().text();
expect(newFirstTextElementValue).to.be(''); // expect the first line to be blank
expect($newSecondLine.text()).to.be(originalTextValue); // expect the second line to be the same as the original first line.
// expect the second line to be the same as the original first line.
expect($newSecondLine.text()).to.be(originalTextValue);
done();
});
});

View file

@ -1,3 +1,5 @@
'use strict';
describe('font select', function () {
// create a new pad before each test run
beforeEach(function (cb) {
@ -15,7 +17,6 @@ describe('font select', function () {
// get the font menu and RobotoMono option
const $viewfontmenu = chrome$('#viewfontmenu');
const $RobotoMonooption = $viewfontmenu.find('[value=RobotoMono]');
// select RobotoMono and fire change event
// $RobotoMonooption.attr('selected','selected');

View file

@ -1,3 +1,5 @@
'use strict';
describe('the test helper', function () {
describe('the newPad method', function () {
xit("doesn't leak memory if you creates iframes over and over again", function (done) {
@ -5,7 +7,7 @@ describe('the test helper', function () {
let times = 10;
var loadPad = function () {
const loadPad = () => {
helper.newPad(() => {
times--;
if (times > 0) {
@ -75,13 +77,14 @@ describe('the test helper', function () {
// Before refreshing, make sure the name is there
expect($usernameInput.val()).to.be('John McLear');
// Now that we have a chrome, we can set a pad cookie, so we can confirm it gets wiped as well
// Now that we have a chrome, we can set a pad cookie
// so we can confirm it gets wiped as well
chrome$.document.cookie = 'prefsHtml=baz;expires=Thu, 01 Jan 3030 00:00:00 GMT';
expect(chrome$.document.cookie).to.contain('prefsHtml=baz');
// Cookies are weird. Because it's attached to chrome$ (as helper.setPadCookies does), AND we
// didn't put path=/, we shouldn't expect it to be visible on window.document.cookie. Let's just
// be sure.
// Cookies are weird. Because it's attached to chrome$ (as helper.setPadCookies does)
// AND we didn't put path=/, we shouldn't expect it to be visible on
// window.document.cookie. Let's just be sure.
expect(window.document.cookie).to.not.contain('prefsHtml=baz');
setTimeout(() => { // give it a second to save the username on the server side
@ -266,7 +269,8 @@ describe('the test helper', function () {
this.timeout(60000);
});
it('changes editor selection to be between startOffset of $startLine and endOffset of $endLine', function (done) {
it('changes editor selection to be between startOffset of $startLine ' +
'and endOffset of $endLine', function (done) {
const inner$ = helper.padInner$;
const startOffset = 2;
@ -313,7 +317,8 @@ describe('the test helper', function () {
* is not consistent between browsers but that's the situation so that's
* how I'm covering it in this test.
*/
expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm, ''))).to.be('ort lines to test');
expect(cleanText(
selection.toString().replace(/(\r\n|\n|\r)/gm, ''))).to.be('ort lines to test');
done();
});
@ -365,12 +370,14 @@ describe('the test helper', function () {
* is not consistent between browsers but that's the situation so that's
* how I'm covering it in this test.
*/
expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm, ''))).to.be('ort lines to test');
expect(cleanText(
selection.toString().replace(/(\r\n|\n|\r)/gm, ''))).to.be('ort lines to test');
done();
});
it('selects all text between beginning of $startLine and end of $endLine when no offset is provided', function (done) {
it('selects all text between beginning of $startLine and end of $endLine ' +
'when no offset is provided', function (done) {
const inner$ = helper.padInner$;
const $lines = inner$('div');
@ -388,7 +395,8 @@ describe('the test helper', function () {
* is not consistent between browsers but that's the situation so that's
* how I'm covering it in this test.
*/
expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm, ''))).to.be('short lines to test');
expect(cleanText(
selection.toString().replace(/(\r\n|\n|\r)/gm, ''))).to.be('short lines to test');
done();
});

View file

@ -1,3 +1,5 @@
'use strict';
describe('import functionality', function () {
beforeEach(function (cb) {
helper.newPad(cb); // creates a new pad
@ -16,7 +18,6 @@ describe('import functionality', function () {
return newtext;
}
function importrequest(data, importurl, type) {
let success;
let error;
const result = $.ajax({
url: importurl,
@ -27,7 +28,17 @@ describe('import functionality', function () {
accepts: {
text: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
},
data: `Content-Type: multipart/form-data; boundary=--boundary\r\n\r\n--boundary\r\nContent-Disposition: form-data; name="file"; filename="import.${type}"\r\nContent-Type: text/plain\r\n\r\n${data}\r\n\r\n--boundary`,
data: [
'Content-Type: multipart/form-data; boundary=--boundary',
'',
'--boundary',
`Content-Disposition: form-data; name="file"; filename="import.${type}"`,
'Content-Type: text/plain',
'',
data,
'',
'--boundary',
].join('\r\n'),
error(res) {
error = res;
},
@ -56,7 +67,8 @@ describe('import functionality', function () {
const importurl = `${helper.padChrome$.window.location.href}/import`;
const textWithNewLines = 'imported text\nnewline';
importrequest(textWithNewLines, importurl, 'txt');
helper.waitFor(() => expect(getinnertext()).to.be('<span class="">imported text</span>\n<span class="">newline</span>\n<br>\n'));
helper.waitFor(() => expect(getinnertext())
.to.be('<span class="">imported text</span>\n<span class="">newline</span>\n<br>\n'));
const results = exportfunc(helper.padChrome$.window.location.href);
expect(results[0][1]).to.be('imported text<br>newline<br><br>');
expect(results[1][1]).to.be('imported text\nnewline\n\n');
@ -66,7 +78,8 @@ describe('import functionality', function () {
const importurl = `${helper.padChrome$.window.location.href}/import`;
const htmlWithNewLines = '<html><body>htmltext<br/>newline</body></html>';
importrequest(htmlWithNewLines, importurl, 'html');
helper.waitFor(() => expect(getinnertext()).to.be('<span class="">htmltext</span>\n<span class="">newline</span>\n<br>\n'));
helper.waitFor(() => expect(getinnertext())
.to.be('<span class="">htmltext</span>\n<span class="">newline</span>\n<br>\n'));
const results = exportfunc(helper.padChrome$.window.location.href);
expect(results[0][1]).to.be('htmltext<br>newline<br><br>');
expect(results[1][1]).to.be('htmltext\nnewline\n\n');
@ -74,69 +87,109 @@ describe('import functionality', function () {
});
xit('import a pad with attributes from html', function (done) {
const importurl = `${helper.padChrome$.window.location.href}/import`;
const htmlWithNewLines = '<html><body>htmltext<br/><span class="b s i u"><b><i><s><u>newline</u></s></i></b></body></html>';
const htmlWithNewLines = '<html><body>htmltext<br/><span class="b s i u">' +
'<b><i><s><u>newline</u></s></i></b></body></html>';
importrequest(htmlWithNewLines, importurl, 'html');
helper.waitFor(() => expect(getinnertext()).to.be('<span class="">htmltext</span>\n<span class="b i s u"><b><i><s><u>newline</u></s></i></b></span>\n<br>\n'));
helper.waitFor(() => expect(getinnertext())
.to.be('<span class="">htmltext</span>\n<span class="b i s u">' +
'<b><i><s><u>newline</u></s></i></b></span>\n<br>\n'));
const results = exportfunc(helper.padChrome$.window.location.href);
expect(results[0][1]).to.be('htmltext<br><strong><em><s><u>newline</u></s></em></strong><br><br>');
expect(results[0][1])
.to.be('htmltext<br><strong><em><s><u>newline</u></s></em></strong><br><br>');
expect(results[1][1]).to.be('htmltext\nnewline\n\n');
done();
});
xit('import a pad with bullets from html', function (done) {
const importurl = `${helper.padChrome$.window.location.href}/import`;
const htmlWithBullets = '<html><body><ul class="list-bullet1"><li>bullet line 1</li><li>bullet line 2</li><ul class="list-bullet2"><li>bullet2 line 1</li><li>bullet2 line 2</li></ul></ul></body></html>';
const htmlWithBullets = '<html><body><ul class="list-bullet1"><li>bullet line 1</li>' +
'<li>bullet line 2</li><ul class="list-bullet2"><li>bullet2 line 1</li>' +
'<li>bullet2 line 2</li></ul></ul></body></html>';
importrequest(htmlWithBullets, importurl, 'html');
helper.waitFor(() => expect(getinnertext()).to.be('\
<ul class="list-bullet1"><li><span class="">bullet line 1</span></li></ul>\n\
<ul class="list-bullet1"><li><span class="">bullet line 2</span></li></ul>\n\
<ul class="list-bullet2"><li><span class="">bullet2 line 1</span></li></ul>\n\
<ul class="list-bullet2"><li><span class="">bullet2 line 2</span></li></ul>\n\
<br>\n'));
helper.waitFor(() => expect(getinnertext()).to.be(
'<ul class="list-bullet1"><li><span class="">bullet line 1</span></li></ul>\n' +
'<ul class="list-bullet1"><li><span class="">bullet line 2</span></li></ul>\n' +
'<ul class="list-bullet2"><li><span class="">bullet2 line 1</span></li></ul>\n' +
'<ul class="list-bullet2"><li><span class="">bullet2 line 2</span></li></ul>\n' +
'<br>\n'));
const results = exportfunc(helper.padChrome$.window.location.href);
expect(results[0][1]).to.be('<ul class="bullet"><li>bullet line 1</li><li>bullet line 2</li><ul class="bullet"><li>bullet2 line 1</li><li>bullet2 line 2</li></ul></ul><br>');
expect(results[1][1]).to.be('\t* bullet line 1\n\t* bullet line 2\n\t\t* bullet2 line 1\n\t\t* bullet2 line 2\n\n');
expect(results[0][1]).to.be(
'<ul class="bullet"><li>bullet line 1</li><li>bullet line 2</li>' +
'<ul class="bullet"><li>bullet2 line 1</li><li>bullet2 line 2</li></ul></ul><br>');
expect(results[1][1])
.to.be('\t* bullet line 1\n\t* bullet line 2\n' +
'\t\t* bullet2 line 1\n\t\t* bullet2 line 2\n\n');
done();
});
xit('import a pad with bullets and newlines from html', function (done) {
const importurl = `${helper.padChrome$.window.location.href}/import`;
const htmlWithBullets = '<html><body><ul class="list-bullet1"><li>bullet line 1</li></ul><br/><ul class="list-bullet1"><li>bullet line 2</li><ul class="list-bullet2"><li>bullet2 line 1</li></ul></ul><br/><ul class="list-bullet1"><ul class="list-bullet2"><li>bullet2 line 2</li></ul></ul></body></html>';
const htmlWithBullets = '<html><body><ul class="list-bullet1"><li>bullet line 1</li>' +
'</ul><br/><ul class="list-bullet1"><li>bullet line 2</li><ul class="list-bullet2">' +
'<li>bullet2 line 1</li></ul></ul><br/><ul class="list-bullet1">' +
'<ul class="list-bullet2"><li>bullet2 line 2</li></ul></ul></body></html>';
importrequest(htmlWithBullets, importurl, 'html');
helper.waitFor(() => expect(getinnertext()).to.be('\
<ul class="list-bullet1"><li><span class="">bullet line 1</span></li></ul>\n\
<br>\n\
<ul class="list-bullet1"><li><span class="">bullet line 2</span></li></ul>\n\
<ul class="list-bullet2"><li><span class="">bullet2 line 1</span></li></ul>\n\
<br>\n\
<ul class="list-bullet2"><li><span class="">bullet2 line 2</span></li></ul>\n\
<br>\n'));
helper.waitFor(() => expect(getinnertext()).to.be(
'<ul class="list-bullet1"><li><span class="">bullet line 1</span></li></ul>\n' +
'<br>\n' +
'<ul class="list-bullet1"><li><span class="">bullet line 2</span></li></ul>\n' +
'<ul class="list-bullet2"><li><span class="">bullet2 line 1</span></li></ul>\n' +
'<br>\n' +
'<ul class="list-bullet2"><li><span class="">bullet2 line 2</span></li></ul>\n' +
'<br>\n'));
const results = exportfunc(helper.padChrome$.window.location.href);
expect(results[0][1]).to.be('<ul class="bullet"><li>bullet line 1</li></ul><br><ul class="bullet"><li>bullet line 2</li><ul class="bullet"><li>bullet2 line 1</li></ul></ul><br><ul><ul class="bullet"><li>bullet2 line 2</li></ul></ul><br>');
expect(results[1][1]).to.be('\t* bullet line 1\n\n\t* bullet line 2\n\t\t* bullet2 line 1\n\n\t\t* bullet2 line 2\n\n');
expect(results[0][1]).to.be(
'<ul class="bullet"><li>bullet line 1</li></ul><br><ul class="bullet">' +
'<li>bullet line 2</li><ul class="bullet"><li>bullet2 line 1</li></ul>' +
'</ul><br><ul><ul class="bullet"><li>bullet2 line 2</li></ul></ul><br>');
expect(results[1][1]).to.be(
'\t* bullet line 1\n\n\t* bullet line 2\n\t\t* bullet2 line 1\n\n\t\t* bullet2 line 2\n\n');
done();
});
xit('import a pad with bullets and newlines and attributes from html', function (done) {
const importurl = `${helper.padChrome$.window.location.href}/import`;
const htmlWithBullets = '<html><body><ul class="list-bullet1"><li>bullet line 1</li></ul><br/><ul class="list-bullet1"><li>bullet line 2</li><ul class="list-bullet2"><li>bullet2 line 1</li></ul></ul><br/><ul class="list-bullet1"><ul class="list-bullet2"><ul class="list-bullet3"><ul class="list-bullet4"><li><span class="b s i u"><b><i><s><u>bullet4 line 2 bisu</u></s></i></b></span></li><li><span class="b s "><b><s>bullet4 line 2 bs</s></b></span></li><li><span class="u"><u>bullet4 line 2 u</u></span><span class="u i s"><i><s><u>uis</u></s></i></span></li></ul></ul></ul></ul></body></html>';
const htmlWithBullets = '<html><body><ul class="list-bullet1"><li>bullet line 1</li>' +
'</ul><br/><ul class="list-bullet1"><li>bullet line 2</li>' +
'<ul class="list-bullet2"><li>bullet2 line 1</li></ul></ul>' +
'<br/><ul class="list-bullet1"><ul class="list-bullet2"><ul class="list-bullet3">' +
'<ul class="list-bullet4"><li><span class="b s i u"><b><i>' +
'<s><u>bullet4 line 2 bisu</u></s></i></b></span></li><li>' +
'<span class="b s "><b><s>bullet4 line 2 bs</s></b></span></li>' +
'<li><span class="u"><u>bullet4 line 2 u</u></span><span class="u i s">' +
'<i><s><u>uis</u></s></i></span></li></ul></ul></ul></ul></body></html>';
importrequest(htmlWithBullets, importurl, 'html');
helper.waitFor(() => expect(getinnertext()).to.be('\
<ul class="list-bullet1"><li><span class="">bullet line 1</span></li></ul>\n\<br>\n\
<ul class="list-bullet1"><li><span class="">bullet line 2</span></li></ul>\n\
<ul class="list-bullet2"><li><span class="">bullet2 line 1</span></li></ul>\n<br>\n\
<ul class="list-bullet4"><li><span class="b i s u"><b><i><s><u>bullet4 line 2 bisu</u></s></i></b></span></li></ul>\n\
<ul class="list-bullet4"><li><span class="b s"><b><s>bullet4 line 2 bs</s></b></span></li></ul>\n\
<ul class="list-bullet4"><li><span class="u"><u>bullet4 line 2 u</u></span><span class="i s u"><i><s><u>uis</u></s></i></span></li></ul>\n\
<br>\n'));
helper.waitFor(() => expect(getinnertext()).to.be(
'<ul class="list-bullet1"><li><span class="">bullet line 1</span></li></ul>\n<br>\n' +
'<ul class="list-bullet1"><li><span class="">bullet line 2</span></li></ul>\n' +
'<ul class="list-bullet2"><li><span class="">bullet2 line 1</span></li></ul>\n<br>\n' +
'<ul class="list-bullet4"><li><span class="b i s u">' +
'<b><i><s><u>bullet4 line 2 bisu</u></s></i></b></span></li></ul>\n' +
'<ul class="list-bullet4"><li><span class="b s">' +
'<b><s>bullet4 line 2 bs</s></b></span></li></ul>\n' +
'<ul class="list-bullet4"><li><span class="u"><u>bullet4 line 2 u</u>' +
'</span><span class="i s u"><i><s><u>uis</u></s></i></span></li></ul>\n' +
'<br>\n'));
const results = exportfunc(helper.padChrome$.window.location.href);
expect(results[0][1]).to.be('<ul class="bullet"><li>bullet line 1</li></ul><br><ul class="bullet"><li>bullet line 2</li><ul class="bullet"><li>bullet2 line 1</li></ul></ul><br><ul><ul><ul><ul class="bullet"><li><strong><em><s><u>bullet4 line 2 bisu</u></s></em></strong></li><li><strong><s>bullet4 line 2 bs</s></strong></li><li><u>bullet4 line 2 u<em><s>uis</s></em></u></li></ul></ul></ul></ul><br>');
expect(results[1][1]).to.be('\t* bullet line 1\n\n\t* bullet line 2\n\t\t* bullet2 line 1\n\n\t\t\t\t* bullet4 line 2 bisu\n\t\t\t\t* bullet4 line 2 bs\n\t\t\t\t* bullet4 line 2 uuis\n\n');
expect(results[0][1]).to.be(
'<ul class="bullet"><li>bullet line 1</li></ul>' +
'<br><ul class="bullet"><li>bullet line 2</li><ul class="bullet"><li>bullet2 line 1</li>' +
'</ul></ul><br><ul><ul><ul><ul class="bullet"><li><strong><em><s><u>bullet4 line 2 bisu' +
'</u></s></em></strong></li><li><strong><s>bullet4 line 2 bs</s></strong>' +
'</li><li><u>bullet4 line 2 u<em><s>uis</s></em></u></li></ul></ul></ul></ul><br>');
expect(results[1][1]).to.be(
'\t* bullet line 1\n\n\t* bullet line 2\n\t\t* bullet2 line 1\n\n\t\t\t\t* bullet4 line 2' +
' bisu\n\t\t\t\t* bullet4 line 2 bs\n\t\t\t\t* bullet4 line 2 uuis\n\n');
done();
});
xit('import a pad with nested bullets from html', function (done) {
const importurl = `${helper.padChrome$.window.location.href}/import`;
const htmlWithBullets = '<html><body><ul class="list-bullet1"><li>bullet line 1</li></ul><ul class="list-bullet1"><li>bullet line 2</li><ul class="list-bullet2"><li>bullet2 line 1</li></ul></ul><ul class="list-bullet1"><ul class="list-bullet2"><ul class="list-bullet3"><ul class="list-bullet4"><li>bullet4 line 2</li><li>bullet4 line 2</li><li>bullet4 line 2</li></ul><li>bullet3 line 1</li></ul></ul><li>bullet2 line 1</li></ul></body></html>';
const htmlWithBullets = '<html><body><ul class="list-bullet1"><li>bullet line 1</li>' +
'</ul><ul class="list-bullet1"><li>bullet line 2</li><ul class="list-bullet2">' +
'<li>bullet2 line 1</li></ul></ul><ul class="list-bullet1"><ul class="list-bullet2">' +
'<ul class="list-bullet3"><ul class="list-bullet4"><li>bullet4 line 2</li>' +
'<li>bullet4 line 2</li><li>bullet4 line 2</li></ul><li>bullet3 line 1</li></ul>' +
'</ul><li>bullet2 line 1</li></ul></body></html>';
importrequest(htmlWithBullets, importurl, 'html');
const oldtext = getinnertext();
helper.waitFor(() => oldtext != getinnertext()
helper.waitFor(() => oldtext !== getinnertext()
// return expect(getinnertext()).to.be('\
// <ul class="list-bullet1"><li><span class="">bullet line 1</span></li></ul>\n\
// <ul class="list-bullet1"><li><span class="">bullet line 2</span></li></ul>\n\
@ -148,73 +201,127 @@ describe('import functionality', function () {
);
const results = exportfunc(helper.padChrome$.window.location.href);
expect(results[0][1]).to.be('<ul class="bullet"><li>bullet line 1</li><li>bullet line 2</li><ul class="bullet"><li>bullet2 line 1</li><ul><ul class="bullet"><li>bullet4 line 2</li><li>bullet4 line 2</li><li>bullet4 line 2</li></ul><li>bullet3 line 1</li></ul></ul><li>bullet2 line 1</li></ul><br>');
expect(results[1][1]).to.be('\t* bullet line 1\n\t* bullet line 2\n\t\t* bullet2 line 1\n\t\t\t\t* bullet4 line 2\n\t\t\t\t* bullet4 line 2\n\t\t\t\t* bullet4 line 2\n\t\t\t* bullet3 line 1\n\t* bullet2 line 1\n\n');
expect(results[0][1]).to.be(
'<ul class="bullet"><li>bullet line 1</li><li>bullet line 2</li>' +
'<ul class="bullet"><li>bullet2 line 1</li><ul><ul class="bullet"><li>bullet4 line 2</li>' +
'<li>bullet4 line 2</li><li>bullet4 line 2</li></ul><li>bullet3 line 1</li></ul></ul>' +
'<li>bullet2 line 1</li></ul><br>');
expect(results[1][1]).to.be(
'\t* bullet line 1\n\t* bullet line 2\n\t\t* bullet2 line 1\n\t\t\t\t* bullet4 line 2' +
'\n\t\t\t\t* bullet4 line 2\n\t\t\t\t* bullet4 line 2\n\t\t\t* bullet3 line 1' +
'\n\t* bullet2 line 1\n\n');
done();
});
xit('import a pad with 8 levels of bullets and newlines and attributes from html', function (done) {
xit('import with 8 levels of bullets and newlines and attributes from html', function (done) {
const importurl = `${helper.padChrome$.window.location.href}/import`;
const htmlWithBullets = '<html><body><ul class="list-bullet1"><li>bullet line 1</li></ul><br/><ul class="list-bullet1"><li>bullet line 2</li><ul class="list-bullet2"><li>bullet2 line 1</li></ul></ul><br/><ul class="list-bullet1"><ul class="list-bullet2"><ul class="list-bullet3"><ul class="list-bullet4"><li><span class="b s i u"><b><i><s><u>bullet4 line 2 bisu</u></s></i></b></span></li><li><span class="b s "><b><s>bullet4 line 2 bs</s></b></span></li><li><span class="u"><u>bullet4 line 2 u</u></span><span class="u i s"><i><s><u>uis</u></s></i></span></li><ul class="list-bullet5"><ul class="list-bullet6"><ul class="list-bullet7"><ul class="list-bullet8"><li><span class="">foo</span></li><li><span class="b s"><b><s>foobar bs</b></s></span></li></ul></ul></ul></ul><ul class="list-bullet5"><li>foobar</li></ul></ul></ul></ul></body></html>';
const htmlWithBullets =
'<html><body><ul class="list-bullet1"><li>bullet line 1</li>' +
'</ul><br/><ul class="list-bullet1"><li>bullet line 2</li><ul class="list-bullet2"><li>' +
'bullet2 line 1</li></ul></ul><br/><ul class="list-bullet1"><ul class="list-bullet2">' +
'<ul class="list-bullet3"><ul class="list-bullet4"><li><span class="b s i u"><b><i>' +
'<s><u>bullet4 line 2 bisu</u></s></i></b></span></li><li><span class="b s "><b><s>' +
'bullet4 line 2 bs</s></b></span></li><li><span class="u"><u>bullet4 line 2 u' +
'</u></span><span class="u i s"><i><s><u>uis</u></s></i></span></li>' +
'<ul class="list-bullet5"><ul class="list-bullet6"><ul class="list-bullet7">' +
'<ul class="list-bullet8"><li><span class="">foo</span></li><li><span class="b s">' +
'<b><s>foobar bs</b></s></span></li></ul></ul></ul></ul><ul class="list-bullet5">' +
'<li>foobar</li></ul></ul></ul></ul></body></html>';
importrequest(htmlWithBullets, importurl, 'html');
helper.waitFor(() => expect(getinnertext()).to.be('\
<ul class="list-bullet1"><li><span class="">bullet line 1</span></li></ul>\n\<br>\n\
<ul class="list-bullet1"><li><span class="">bullet line 2</span></li></ul>\n\
<ul class="list-bullet2"><li><span class="">bullet2 line 1</span></li></ul>\n<br>\n\
<ul class="list-bullet4"><li><span class="b i s u"><b><i><s><u>bullet4 line 2 bisu</u></s></i></b></span></li></ul>\n\
<ul class="list-bullet4"><li><span class="b s"><b><s>bullet4 line 2 bs</s></b></span></li></ul>\n\
<ul class="list-bullet4"><li><span class="u"><u>bullet4 line 2 u</u></span><span class="i s u"><i><s><u>uis</u></s></i></span></li></ul>\n\
<ul class="list-bullet8"><li><span class="">foo</span></li></ul>\n\
<ul class="list-bullet8"><li><span class="b s"><b><s>foobar bs</s></b></span></li></ul>\n\
<ul class="list-bullet5"><li><span class="">foobar</span></li></ul>\n\
<br>\n'));
helper.waitFor(() => expect(getinnertext()).to.be(
'<ul class="list-bullet1"><li><span class="">bullet line 1</span></li></ul>\n<br>\n' +
'<ul class="list-bullet1"><li><span class="">bullet line 2</span></li></ul>\n' +
'<ul class="list-bullet2"><li><span class="">bullet2 line 1</span></li></ul>\n<br>\n' +
'<ul class="list-bullet4"><li><span class="b i s u"><b><i><s><u>bullet4 line 2 bisu</u>' +
'</s></i></b></span></li></ul>\n' +
'<ul class="list-bullet4"><li><span class="b s"><b><s>bullet4 line 2 bs</s></b>' +
'</span></li></ul>\n' +
'<ul class="list-bullet4"><li><span class="u"><u>bullet4 line 2 u</u></span>' +
'<span class="i s u"><i><s><u>uis</u></s>' +
'</i></span></li></ul>\n' +
'<ul class="list-bullet8"><li><span class="">foo</span></li></ul>\n' +
'<ul class="list-bullet8"><li><span class="b s"><b><s>foobar bs</s></b>' +
'</span></li></ul>\n' +
'<ul class="list-bullet5"><li><span class="">foobar</span></li></ul>\n' +
'<br>\n'));
const results = exportfunc(helper.padChrome$.window.location.href);
expect(results[0][1]).to.be('<ul class="bullet"><li>bullet line 1</li></ul><br><ul class="bullet"><li>bullet line 2</li><ul class="bullet"><li>bullet2 line 1</li></ul></ul><br><ul><ul><ul><ul class="bullet"><li><strong><em><s><u>bullet4 line 2 bisu</u></s></em></strong></li><li><strong><s>bullet4 line 2 bs</s></strong></li><li><u>bullet4 line 2 u<em><s>uis</s></em></u></li><ul><ul><ul><ul class="bullet"><li>foo</li><li><strong><s>foobar bs</s></strong></li></ul></ul></ul><li>foobar</li></ul></ul></ul></ul></ul><br>');
expect(results[1][1]).to.be('\t* bullet line 1\n\n\t* bullet line 2\n\t\t* bullet2 line 1\n\n\t\t\t\t* bullet4 line 2 bisu\n\t\t\t\t* bullet4 line 2 bs\n\t\t\t\t* bullet4 line 2 uuis\n\t\t\t\t\t\t\t\t* foo\n\t\t\t\t\t\t\t\t* foobar bs\n\t\t\t\t\t* foobar\n\n');
expect(results[0][1]).to.be(
'<ul class="bullet"><li>bullet line 1</li></ul><br><ul class="bullet">' +
'<li>bullet line 2</li><ul class="bullet"><li>bullet2 line 1</li></ul></ul>' +
'<br><ul><ul><ul><ul class="bullet"><li><strong><em><s><u>' +
'bullet4 line 2 bisu</u></s></em></strong></li><li><strong><s>' +
'bullet4 line 2 bs</s></strong></li><li><u>bullet4 line 2 u<em>' +
'<s>uis</s></em></u></li><ul><ul><ul><ul class="bullet"><li>foo</li>' +
'<li><strong><s>foobar bs</s></strong></li></ul></ul></ul><li>foobar</li>' +
'</ul></ul></ul></ul></ul><br>');
expect(results[1][1]).to.be(
'\t* bullet line 1\n\n\t* bullet line 2\n\t\t* ' +
'bullet2 line 1\n\n\t\t\t\t* bullet4 line 2 bisu\n\t\t\t\t* bullet4 line 2 ' +
'bs\n\t\t\t\t* bullet4 line 2 uuis\n\t\t\t\t\t\t\t\t* foo\n\t\t\t\t\t\t\t\t* ' +
'foobar bs\n\t\t\t\t\t* foobar\n\n');
done();
});
xit('import a pad with ordered lists from html', function (done) {
const importurl = `${helper.padChrome$.window.location.href}/import`;
const htmlWithBullets = '<html><body><ol class="list-number1" start="1"><li>number 1 line 1</li></ol><ol class="list-number1" start="2"><li>number 2 line 2</li></ol></body></html>';
const htmlWithBullets = '<html><body><ol class="list-number1" start="1">' +
'<li>number 1 line 1</li></ol><ol class="list-number1" start="2">' +
'<li>number 2 line 2</li></ol></body></html>';
importrequest(htmlWithBullets, importurl, 'html');
console.error(getinnertext());
expect(getinnertext()).to.be('\
<ol class="list-number1" start="1"><li><span class="">number 1 line 1</span></li></ol>\n\
<ol class="list-number1" start="2"><li><span class="">number 2 line 2</span></li></ol>\n\
<br>\n');
expect(getinnertext()).to.be(
'<ol class="list-number1" start="1"><li><span class="">number 1 line 1</span></li></ol>\n' +
'<ol class="list-number1" start="2"><li><span class="">number 2 line 2</span></li></ol>\n' +
'<br>\n');
const results = exportfunc(helper.padChrome$.window.location.href);
expect(results[0][1]).to.be('<ol class="list-number1" start="1"><li>number 1 line 1</li></ol><ol class="list-number1" start="2"><li>number 2 line 2</li></ol>');
expect(results[0][1]).to.be(
'<ol class="list-number1" start="1"><li>number 1 line 1</li>' +
'</ol><ol class="list-number1" start="2"><li>number 2 line 2</li></ol>');
expect(results[1][1]).to.be('');
done();
});
xit('import a pad with ordered lists and newlines from html', function (done) {
const importurl = `${helper.padChrome$.window.location.href}/import`;
const htmlWithBullets = '<html><body><ol class="list-number1" start="1"><li>number 9 line 1</li></ol><br/><ol class="list-number1" start="2"><li>number 10 line 2</li><ol class="list-number2"><li>number 2 times line 1</li></ol></ol><br/><ol class="list-bullet1"><ol class="list-number2"><li>number 2 times line 2</li></ol></ol></body></html>';
const htmlWithBullets = '<html><body><ol class="list-number1" start="1">' +
'<li>number 9 line 1</li></ol><br/><ol class="list-number1" start="2">' +
'<li>number 10 line 2</li><ol class="list-number2">' +
'<li>number 2 times line 1</li></ol></ol><br/><ol class="list-bullet1">' +
'<ol class="list-number2"><li>number 2 times line 2</li></ol></ol></body></html>';
importrequest(htmlWithBullets, importurl, 'html');
expect(getinnertext()).to.be('\
<ol class="list-number1" start="1"><li><span class="">number 9 line 1</span></li></ol>\n\
<br>\n\
<ol class="list-number1" start="2"><li><span class="">number 10 line 2</span></li></ol>\n\
<ol class="list-number2"><li><span class="">number 2 times line 1</span></li></ol>\n\
<br>\n\
<ol class="list-number2"><li><span class="">number 2 times line 2</span></li></ol>\n\
<br>\n');
expect(getinnertext()).to.be(
'<ol class="list-number1" start="1"><li><span class="">number 9 line 1</span></li></ol>\n' +
'<br>\n' +
'<ol class="list-number1" start="2"><li><span class="">number 10 line 2</span></li>' +
'</ol>\n' +
'<ol class="list-number2"><li><span class="">number 2 times line 1</span></li></ol>\n' +
'<br>\n' +
'<ol class="list-number2"><li><span class="">number 2 times line 2</span></li></ol>\n' +
'<br>\n');
const results = exportfunc(helper.padChrome$.window.location.href);
console.error(results);
done();
});
xit('import a pad with nested ordered lists and attributes and newlines from html', function (done) {
xit('import with nested ordered lists and attributes and newlines from html', function (done) {
const importurl = `${helper.padChrome$.window.location.href}/import`;
const htmlWithBullets = '<html><body><ol class="list-number1" start="1"><li><span class="b s i u"><b><i><s><u>bold strikethrough italics underline</u></s><i/></b></span> line <span class="b"><b>1bold</b></span></li></ol><br/><span class="i"><i><ol class="list-number1" start="2"><li>number 10 line 2</li><ol class="list-number2"><li>number 2 times line 1</li></ol></ol></i></span><br/><ol class="list-bullet1"><ol class="list-number2"><li>number 2 times line 2</li></ol></ol></body></html>';
const htmlWithBullets = '<html><body><ol class="list-number1" start="1"><li>' +
'<span class="b s i u"><b><i><s><u>bold strikethrough italics underline</u>' +
'</s><i/></b></span> line <span class="b"><b>1bold</b></span></li>' +
'</ol><br/><span class="i"><i><ol class="list-number1" start="2">' +
'<li>number 10 line 2</li><ol class="list-number2">' +
'<li>number 2 times line 1</li></ol></ol></i></span><br/>' +
'<ol class="list-bullet1"><ol class="list-number2">' +
'<li>number 2 times line 2</li></ol></ol></body></html>';
importrequest(htmlWithBullets, importurl, 'html');
expect(getinnertext()).to.be('\
<ol class="list-number1"><li><span class="b i s u"><b><i><s><u>bold strikethrough italics underline</u></s></i></b></span><span class=""> line </span><span class="b"><b>1bold</b></span></li></ol>\n\
<br>\n\
<ol class="list-number1"><li><span class="i"><i>number 10 line 2</i></span></li></ol>\n\
<ol class="list-number2"><li><span class="i"><i>number 2 times line 1</i></span></li></ol>\n\
<br>\n\
<ol class="list-number2"><li><span class="">number 2 times line 2</span></li></ol>\n\
<br>\n');
expect(getinnertext()).to.be(
'<ol class="list-number1"><li><span class="b i s u"><b><i><s><u>' +
'bold strikethrough italics underline</u></s></i></b></span><span class="">' +
' line </span><span class="b"><b>1bold</b></span></li></ol>\n' +
'<br>\n' +
'<ol class="list-number1"><li><span class="i"><i>number 10 line 2</i></span></li></ol>\n' +
'<ol class="list-number2"><li><span class="i">' +
'<i>number 2 times line 1</i></span></li></ol>\n' +
'<br>\n' +
'<ol class="list-number2"><li><span class="">number 2 times line 2</span></li></ol>\n' +
'<br>\n');
const results = exportfunc(helper.padChrome$.window.location.href);
console.error(results);
done();

View file

@ -1,3 +1,5 @@
'use strict';
describe('import indents functionality', function () {
beforeEach(function (cb) {
helper.newPad(cb); // creates a new pad
@ -13,7 +15,6 @@ describe('import indents functionality', function () {
return newtext;
}
function importrequest(data, importurl, type) {
let success;
let error;
const result = $.ajax({
url: importurl,
@ -24,7 +25,17 @@ describe('import indents functionality', function () {
accepts: {
text: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
},
data: `Content-Type: multipart/form-data; boundary=--boundary\r\n\r\n--boundary\r\nContent-Disposition: form-data; name="file"; filename="import.${type}"\r\nContent-Type: text/plain\r\n\r\n${data}\r\n\r\n--boundary`,
data: [
'Content-Type: multipart/form-data; boundary=--boundary',
'',
'--boundary',
`Content-Disposition: form-data; name="file"; filename="import.${type}"`,
'Content-Type: text/plain',
'',
data,
'',
'--boundary',
].join('\r\n'),
error(res) {
error = res;
},
@ -51,54 +62,67 @@ describe('import indents functionality', function () {
xit('import a pad with indents from html', function (done) {
const importurl = `${helper.padChrome$.window.location.href}/import`;
/* eslint-disable-next-line max-len */
const htmlWithIndents = '<html><body><ul class="list-indent1"><li>indent line 1</li><li>indent line 2</li><ul class="list-indent2"><li>indent2 line 1</li><li>indent2 line 2</li></ul></ul></body></html>';
importrequest(htmlWithIndents, importurl, 'html');
helper.waitFor(() => expect(getinnertext()).to.be('\
<ul class="list-indent1"><li><span class="">indent line 1</span></li></ul>\n\
<ul class="list-indent1"><li><span class="">indent line 2</span></li></ul>\n\
<ul class="list-indent2"><li><span class="">indent2 line 1</span></li></ul>\n\
<ul class="list-indent2"><li><span class="">indent2 line 2</span></li></ul>\n\
<br>\n'));
helper.waitFor(() => expect(getinnertext()).to.be(
'<ul class="list-indent1"><li><span class="">indent line 1</span></li></ul>\n' +
'<ul class="list-indent1"><li><span class="">indent line 2</span></li></ul>\n' +
'<ul class="list-indent2"><li><span class="">indent2 line 1</span></li></ul>\n' +
'<ul class="list-indent2"><li><span class="">indent2 line 2</span></li></ul>\n' +
'<br>\n'));
const results = exportfunc(helper.padChrome$.window.location.href);
/* eslint-disable-next-line max-len */
expect(results[0][1]).to.be('<ul class="indent"><li>indent line 1</li><li>indent line 2</li><ul class="indent"><li>indent2 line 1</li><li>indent2 line 2</li></ul></ul><br>');
expect(results[1][1]).to.be('\tindent line 1\n\tindent line 2\n\t\tindent2 line 1\n\t\tindent2 line 2\n\n');
expect(results[1][1])
.to.be('\tindent line 1\n\tindent line 2\n\t\tindent2 line 1\n\t\tindent2 line 2\n\n');
done();
});
xit('import a pad with indented lists and newlines from html', function (done) {
const importurl = `${helper.padChrome$.window.location.href}/import`;
/* eslint-disable-next-line max-len */
const htmlWithIndents = '<html><body><ul class="list-indent1"><li>indent line 1</li></ul><br/><ul class="list-indent1"><li>indent 1 line 2</li><ul class="list-indent2"><li>indent 2 times line 1</li></ul></ul><br/><ul class="list-indent1"><ul class="list-indent2"><li>indent 2 times line 2</li></ul></ul></body></html>';
importrequest(htmlWithIndents, importurl, 'html');
helper.waitFor(() => expect(getinnertext()).to.be('\
<ul class="list-indent1"><li><span class="">indent line 1</span></li></ul>\n\
<br>\n\
<ul class="list-indent1"><li><span class="">indent 1 line 2</span></li></ul>\n\
<ul class="list-indent2"><li><span class="">indent 2 times line 1</span></li></ul>\n\
<br>\n\
<ul class="list-indent2"><li><span class="">indent 2 times line 2</span></li></ul>\n\
<br>\n'));
helper.waitFor(() => expect(getinnertext()).to.be(
'<ul class="list-indent1"><li><span class="">indent line 1</span></li></ul>\n' +
'<br>\n' +
'<ul class="list-indent1"><li><span class="">indent 1 line 2</span></li></ul>\n' +
'<ul class="list-indent2"><li><span class="">indent 2 times line 1</span></li></ul>\n' +
'<br>\n' +
'<ul class="list-indent2"><li><span class="">indent 2 times line 2</span></li></ul>\n' +
'<br>\n'));
const results = exportfunc(helper.padChrome$.window.location.href);
/* eslint-disable-next-line max-len */
expect(results[0][1]).to.be('<ul class="indent"><li>indent line 1</li></ul><br><ul class="indent"><li>indent 1 line 2</li><ul class="indent"><li>indent 2 times line 1</li></ul></ul><br><ul><ul class="indent"><li>indent 2 times line 2</li></ul></ul><br>');
/* eslint-disable-next-line max-len */
expect(results[1][1]).to.be('\tindent line 1\n\n\tindent 1 line 2\n\t\tindent 2 times line 1\n\n\t\tindent 2 times line 2\n\n');
done();
});
xit('import a pad with 8 levels of indents and newlines and attributes from html', function (done) {
xit('import with 8 levels of indents and newlines and attributes from html', function (done) {
const importurl = `${helper.padChrome$.window.location.href}/import`;
/* eslint-disable-next-line max-len */
const htmlWithIndents = '<html><body><ul class="list-indent1"><li>indent line 1</li></ul><br/><ul class="list-indent1"><li>indent line 2</li><ul class="list-indent2"><li>indent2 line 1</li></ul></ul><br/><ul class="list-indent1"><ul class="list-indent2"><ul class="list-indent3"><ul class="list-indent4"><li><span class="b s i u"><b><i><s><u>indent4 line 2 bisu</u></s></i></b></span></li><li><span class="b s "><b><s>indent4 line 2 bs</s></b></span></li><li><span class="u"><u>indent4 line 2 u</u></span><span class="u i s"><i><s><u>uis</u></s></i></span></li><ul class="list-indent5"><ul class="list-indent6"><ul class="list-indent7"><ul class="list-indent8"><li><span class="">foo</span></li><li><span class="b s"><b><s>foobar bs</b></s></span></li></ul></ul></ul></ul><ul class="list-indent5"><li>foobar</li></ul></ul></ul></ul></body></html>';
importrequest(htmlWithIndents, importurl, 'html');
helper.waitFor(() => expect(getinnertext()).to.be('\
<ul class="list-indent1"><li><span class="">indent line 1</span></li></ul>\n\<br>\n\
<ul class="list-indent1"><li><span class="">indent line 2</span></li></ul>\n\
<ul class="list-indent2"><li><span class="">indent2 line 1</span></li></ul>\n<br>\n\
<ul class="list-indent4"><li><span class="b i s u"><b><i><s><u>indent4 line 2 bisu</u></s></i></b></span></li></ul>\n\
<ul class="list-indent4"><li><span class="b s"><b><s>indent4 line 2 bs</s></b></span></li></ul>\n\
<ul class="list-indent4"><li><span class="u"><u>indent4 line 2 u</u></span><span class="i s u"><i><s><u>uis</u></s></i></span></li></ul>\n\
<ul class="list-indent8"><li><span class="">foo</span></li></ul>\n\
<ul class="list-indent8"><li><span class="b s"><b><s>foobar bs</s></b></span></li></ul>\n\
<ul class="list-indent5"><li><span class="">foobar</span></li></ul>\n\
<br>\n'));
helper.waitFor(() => expect(getinnertext()).to.be(
'<ul class="list-indent1"><li><span class="">indent line 1</span></li></ul>\n<br>\n' +
'<ul class="list-indent1"><li><span class="">indent line 2</span></li></ul>\n' +
'<ul class="list-indent2"><li><span class="">indent2 line 1</span></li></ul>\n<br>\n' +
'<ul class="list-indent4"><li><span class="b i s u"><b><i><s><u>indent4 ' +
'line 2 bisu</u></s></i></b></span></li></ul>\n' +
'<ul class="list-indent4"><li><span class="b s"><b><s>' +
'indent4 line 2 bs</s></b></span></li></ul>\n' +
'<ul class="list-indent4"><li><span class="u"><u>indent4 line 2 u</u>' +
'</span><span class="i s u"><i><s><u>uis</u></s></i></span></li></ul>\n' +
'<ul class="list-indent8"><li><span class="">foo</span></li></ul>\n' +
'<ul class="list-indent8"><li><span class="b s"><b><s>foobar bs</s></b>' +
'</span></li></ul>\n' +
'<ul class="list-indent5"><li><span class="">foobar</span></li></ul>\n' +
'<br>\n'));
const results = exportfunc(helper.padChrome$.window.location.href);
/* eslint-disable-next-line max-len */
expect(results[0][1]).to.be('<ul class="indent"><li>indent line 1</li></ul><br><ul class="indent"><li>indent line 2</li><ul class="indent"><li>indent2 line 1</li></ul></ul><br><ul><ul><ul><ul class="indent"><li><strong><em><s><u>indent4 line 2 bisu</u></s></em></strong></li><li><strong><s>indent4 line 2 bs</s></strong></li><li><u>indent4 line 2 u<em><s>uis</s></em></u></li><ul><ul><ul><ul class="indent"><li>foo</li><li><strong><s>foobar bs</s></strong></li></ul></ul></ul><li>foobar</li></ul></ul></ul></ul></ul><br>');
/* eslint-disable-next-line max-len */
expect(results[1][1]).to.be('\tindent line 1\n\n\tindent line 2\n\t\tindent2 line 1\n\n\t\t\t\tindent4 line 2 bisu\n\t\t\t\tindent4 line 2 bs\n\t\t\t\tindent4 line 2 uuis\n\t\t\t\t\t\t\t\tfoo\n\t\t\t\t\t\t\t\tfoobar bs\n\t\t\t\t\tfoobar\n\n');
done();
});

View file

@ -1,3 +1,5 @@
'use strict';
describe('indentation button', function () {
// create a new pad before each test run
beforeEach(function (cb) {
@ -7,7 +9,6 @@ describe('indentation button', function () {
it('indent text with keypress', 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();
@ -15,7 +16,7 @@ describe('indentation button', function () {
// select this text element
$firstTextElement.sendkeys('{selectall}');
const e = inner$.Event(helper.evtType);
const e = new inner$.Event(helper.evtType);
e.keyCode = 9; // tab :|
inner$('#innerdocbody').trigger(e);
@ -56,9 +57,9 @@ describe('indentation button', function () {
});
});
it("indents text with spaces on enter if previous line ends with ':', '[', '(', or '{'", function (done) {
it('indents text with spaces on enter if previous line ends ' +
"with ':', '[', '(', or '{'", function (done) {
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;
// type a bit, make a line break and type again
const $firstTextElement = inner$('div').first();
@ -77,7 +78,8 @@ describe('indentation button', function () {
// curly braces
const $lineWithCurlyBraces = inner$('div').first().next().next().next();
$lineWithCurlyBraces.sendkeys('{{}');
pressEnter(); // cannot use sendkeys('{enter}') here, browser does not read the command properly
// cannot use sendkeys('{enter}') here, browser does not read the command properly
pressEnter();
const $lineAfterCurlyBraces = inner$('div').first().next().next().next().next();
expect($lineAfterCurlyBraces.text()).to.match(/\s{4}/); // tab === 4 spaces
@ -106,9 +108,9 @@ describe('indentation button', function () {
});
});
it("appends indentation to the indent of previous line if previous line ends with ':', '[', '(', or '{'", function (done) {
it('appends indentation to the indent of previous line if previous line ends ' +
"with ':', '[', '(', or '{'", function (done) {
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;
// type a bit, make a line break and type again
const $firstTextElement = inner$('div').first();
@ -124,47 +126,47 @@ describe('indentation button', function () {
$lineWithColon.sendkeys(':');
pressEnter();
const $lineAfterColon = inner$('div').first().next();
expect($lineAfterColon.text()).to.match(/\s{6}/); // previous line indentation + regular tab (4 spaces)
// previous line indentation + regular tab (4 spaces)
expect($lineAfterColon.text()).to.match(/\s{6}/);
done();
});
});
it("issue #2772 shows '*' when multiple indented lines receive a style and are outdented", function (done) {
it("issue #2772 shows '*' when multiple indented lines " +
' receive a style and are outdented', async function () {
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;
// make sure pad has more than one line
inner$('div').first().sendkeys('First{enter}Second{enter}');
helper.waitFor(() => inner$('div').first().text().trim() === 'First').done(() => {
// indent first 2 lines
const $lines = inner$('div');
const $firstLine = $lines.first();
const $secondLine = $lines.slice(1, 2);
helper.selectLines($firstLine, $secondLine);
await helper.waitForPromise(() => inner$('div').first().text().trim() === 'First');
const $indentButton = chrome$('.buttonicon-indent');
$indentButton.click();
// indent first 2 lines
const $lines = inner$('div');
const $firstLine = $lines.first();
let $secondLine = $lines.slice(1, 2);
helper.selectLines($firstLine, $secondLine);
helper.waitFor(() => inner$('div').first().find('ul li').length === 1).done(() => {
// apply bold
const $boldButton = chrome$('.buttonicon-bold');
$boldButton.click();
const $indentButton = chrome$('.buttonicon-indent');
$indentButton.click();
helper.waitFor(() => inner$('div').first().find('b').length === 1).done(() => {
// outdent first 2 lines
const $outdentButton = chrome$('.buttonicon-outdent');
$outdentButton.click();
helper.waitFor(() => inner$('div').first().find('ul li').length === 0).done(() => {
// check if '*' is displayed
const $secondLine = inner$('div').slice(1, 2);
expect($secondLine.text().trim()).to.be('Second');
await helper.waitForPromise(() => inner$('div').first().find('ul li').length === 1);
done();
});
});
});
});
// apply bold
const $boldButton = chrome$('.buttonicon-bold');
$boldButton.click();
await helper.waitForPromise(() => inner$('div').first().find('b').length === 1);
// outdent first 2 lines
const $outdentButton = chrome$('.buttonicon-outdent');
$outdentButton.click();
await helper.waitForPromise(() => inner$('div').first().find('ul li').length === 0);
// check if '*' is displayed
$secondLine = inner$('div').slice(1, 2);
expect($secondLine.text().trim()).to.be('Second');
});
/*
@ -184,7 +186,6 @@ describe('indentation button', function () {
var $indentButton = testHelper.$getPadChrome().find(".buttonicon-indent");
$indentButton.click();
//ace creates a new dom element when you press a button, so just get the first text element again
var newFirstTextElement = $inner.find("div").first();
// is there a list-indent class element now?
@ -222,7 +223,6 @@ describe('indentation button', function () {
$outdentButton.click();
$outdentButton.click();
//ace creates a new dom element when you press a button, so just get the first text element again
var newFirstTextElement = $inner.find("div").first();
// is there a list-indent class element now?
@ -269,7 +269,9 @@ describe('indentation button', function () {
//get the second text element out of the inner iframe
setTimeout(function(){ // THIS IS REALLY BAD
var secondTextElement = $('iframe').contents().find('iframe').contents().find('iframe').contents().find('body > div').get(1); // THIS IS UGLY
var secondTextElement = $('iframe').contents()
.find('iframe').contents()
.find('iframe').contents().find('body > div').get(1); // THIS IS UGLY
// is there a list-indent class element now?
var firstChild = secondTextElement.children(":first");
@ -284,7 +286,10 @@ describe('indentation button', function () {
expect(isLI).to.be(true);
//get the first text element out of the inner iframe
var thirdTextElement = $('iframe').contents().find('iframe').contents().find('iframe').contents().find('body > div').get(2); // THIS IS UGLY TOO
var thirdTextElement = $('iframe').contents()
.find('iframe').contents()
.find('iframe').contents()
.find('body > div').get(2); // THIS IS UGLY TOO
// is there a list-indent class element now?
var firstChild = thirdTextElement.children(":first");
@ -302,9 +307,9 @@ describe('indentation button', function () {
});*/
});
function pressEnter() {
const pressEnter = () => {
const inner$ = helper.padInner$;
const e = inner$.Event(helper.evtType);
const e = new inner$.Event(helper.evtType);
e.keyCode = 13; // enter :|
inner$('#innerdocbody').trigger(e);
}
};

View file

@ -1,3 +1,5 @@
'use strict';
describe('italic some text', function () {
// create a new pad before each test run
beforeEach(function (cb) {
@ -19,7 +21,7 @@ describe('italic some text', function () {
const $boldButton = chrome$('.buttonicon-italic');
$boldButton.click();
// ace creates a new dom element when you press a button, so just get the first text element again
// ace creates a new dom element when you press a button, just get the first text element again
const $newFirstTextElement = inner$('div').first();
// is there a <i> element now?
@ -36,7 +38,6 @@ describe('italic some text', function () {
it('makes text italic using keypress', 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();
@ -44,12 +45,12 @@ describe('italic some text', function () {
// select this text element
$firstTextElement.sendkeys('{selectall}');
const e = inner$.Event(helper.evtType);
const e = new inner$.Event(helper.evtType);
e.ctrlKey = true; // Control key
e.which = 105; // i
inner$('#innerdocbody').trigger(e);
// ace creates a new dom element when you press a button, so just get the first text element again
// ace creates a new dom element when you press a button, just get the first text element again
const $newFirstTextElement = inner$('div').first();
// is there a <i> element now?

View file

@ -1,6 +1,8 @@
function deletecookie(name) {
'use strict';
const deletecookie = (name) => {
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:01 GMT;`;
}
};
describe('Language select and change', function () {
// Destroy language cookies
@ -14,7 +16,6 @@ describe('Language select and change', function () {
// Destroy language cookies
it('makes text german', function (done) {
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;
// click on the settings button to make settings visible
@ -29,7 +30,7 @@ describe('Language select and change', function () {
$languageoption.attr('selected', 'selected');
$language.change();
helper.waitFor(() => chrome$('.buttonicon-bold').parent()[0].title == 'Fett (Strg-B)')
helper.waitFor(() => chrome$('.buttonicon-bold').parent()[0].title === 'Fett (Strg-B)')
.done(() => {
// get the value of the bold button
const $boldButton = chrome$('.buttonicon-bold').parent();
@ -44,7 +45,6 @@ describe('Language select and change', function () {
});
it('makes text English', function (done) {
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;
// click on the settings button to make settings visible
@ -60,7 +60,7 @@ describe('Language select and change', function () {
// get the value of the bold button
const $boldButton = chrome$('.buttonicon-bold').parent();
helper.waitFor(() => $boldButton[0].title != 'Fett (Strg+B)')
helper.waitFor(() => $boldButton[0].title !== 'Fett (Strg+B)')
.done(() => {
// get the value of the bold button
const $boldButton = chrome$('.buttonicon-bold').parent();
@ -75,7 +75,6 @@ describe('Language select and change', function () {
});
it('changes direction when picking an rtl lang', function (done) {
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;
// click on the settings button to make settings visible
@ -91,7 +90,7 @@ describe('Language select and change', function () {
$language.val('ar');
$languageoption.change();
helper.waitFor(() => chrome$('html')[0].dir != 'ltr')
helper.waitFor(() => chrome$('html')[0].dir !== 'ltr')
.done(() => {
// check if the document's direction was changed
expect(chrome$('html')[0].dir).to.be('rtl');
@ -100,7 +99,6 @@ describe('Language select and change', function () {
});
it('changes direction when picking an ltr lang', function (done) {
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;
// click on the settings button to make settings visible
@ -117,7 +115,7 @@ describe('Language select and change', function () {
$language.val('en');
$languageoption.change();
helper.waitFor(() => chrome$('html')[0].dir != 'rtl')
helper.waitFor(() => chrome$('html')[0].dir !== 'rtl')
.done(() => {
// check if the document's direction was changed
expect(chrome$('html')[0].dir).to.be('ltr');

View file

@ -1,7 +1,9 @@
'use strict';
describe('author of pad edition', function () {
// author 1 creates a new pad with some content (regular lines and lists)
before(function (done) {
var padId = helper.newPad(() => {
const padId = helper.newPad(() => {
// make sure pad has at least 3 lines
const $firstLine = helper.padInner$('div').first();
$firstLine.html('Hello World');
@ -13,7 +15,8 @@ describe('author of pad edition', function () {
setTimeout(() => {
// Expire cookie, so author is changed after reloading the pad.
// See https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#Example_4_Reset_the_previous_cookie
helper.padChrome$.document.cookie = 'token=foo;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
helper.padChrome$.document.cookie =
'token=foo;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
helper.newPad(done, padId);
}, 1000);
@ -27,7 +30,7 @@ describe('author of pad edition', function () {
clearAuthorship(done);
});
var clearAuthorship = function (done) {
const clearAuthorship = (done) => {
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;

View file

@ -1,3 +1,5 @@
'use strict';
describe('assign ordered list', function () {
// create a new pad before each test run
beforeEach(function (cb) {
@ -34,7 +36,8 @@ describe('assign ordered list', function () {
});
it('does not insert unordered list', function (done) {
helper.waitFor(() => helper.padInner$('div').first().find('ol li').length === 1).done(() => {
helper.waitFor(
() => helper.padInner$('div').first().find('ol li').length === 1).done(() => {
expect().fail(() => 'Unordered list inserted, should ignore shortcut');
}).fail(() => {
done();
@ -62,7 +65,8 @@ describe('assign ordered list', function () {
});
it('does not insert unordered list', function (done) {
helper.waitFor(() => helper.padInner$('div').first().find('ol li').length === 1).done(() => {
helper.waitFor(
() => helper.padInner$('div').first().find('ol li').length === 1).done(() => {
expect().fail(() => 'Unordered list inserted, should ignore shortcut');
}).fail(() => {
done();
@ -71,7 +75,8 @@ describe('assign ordered list', function () {
});
});
xit('issue #1125 keeps the numbered list on enter for the new line - EMULATES PASTING INTO A PAD', function (done) {
xit('issue #1125 keeps the numbered list on enter for the new line', function (done) {
// EMULATES PASTING INTO A PAD
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;
@ -91,24 +96,25 @@ describe('assign ordered list', function () {
expect(hasOLElement).to.be(true);
expect($newSecondLine.text()).to.be('line 2');
const hasLineNumber = $newSecondLine.find('ol').attr('start') === 2;
expect(hasLineNumber).to.be(true); // This doesn't work because pasting in content doesn't work
// This doesn't work because pasting in content doesn't work
expect(hasLineNumber).to.be(true);
done();
});
});
var triggerCtrlShiftShortcut = function (shortcutChar) {
const triggerCtrlShiftShortcut = (shortcutChar) => {
const inner$ = helper.padInner$;
const e = inner$.Event(helper.evtType);
const e = new inner$.Event(helper.evtType);
e.ctrlKey = true;
e.shiftKey = true;
e.which = shortcutChar.toString().charCodeAt(0);
inner$('#innerdocbody').trigger(e);
};
var makeSureShortcutIsDisabled = function (shortcut) {
const makeSureShortcutIsDisabled = (shortcut) => {
helper.padChrome$.window.clientVars.padShortcutEnabled[shortcut] = false;
};
var makeSureShortcutIsEnabled = function (shortcut) {
const makeSureShortcutIsEnabled = (shortcut) => {
helper.padChrome$.window.clientVars.padShortcutEnabled[shortcut] = true;
};
});
@ -133,7 +139,7 @@ describe('Pressing Tab in an OL increases and decreases indentation', function (
const $insertorderedlistButton = chrome$('.buttonicon-insertorderedlist');
$insertorderedlistButton.click();
const e = inner$.Event(helper.evtType);
const e = new inner$.Event(helper.evtType);
e.keyCode = 9; // tab
inner$('#innerdocbody').trigger(e);
@ -147,7 +153,8 @@ describe('Pressing Tab in an OL increases and decreases indentation', function (
});
describe('Pressing indent/outdent button in an OL increases and decreases indentation and bullet / ol formatting', function () {
describe('Pressing indent/outdent button in an OL increases and ' +
'decreases indentation and bullet / ol formatting', function () {
// create a new pad before each test run
beforeEach(function (cb) {
helper.newPad(cb);

View file

@ -1,3 +1,5 @@
'use strict';
describe('Pad modal', function () {
context('when modal is a "force reconnect" message', function () {
const MODAL_SELECTOR = '#connectivity';
@ -93,17 +95,17 @@ describe('Pad modal', function () {
});
});
var clickOnPadInner = function () {
const clickOnPadInner = () => {
const $editor = helper.padInner$('#innerdocbody');
$editor.click();
};
var clickOnPadOuter = function () {
const clickOnPadOuter = () => {
const $lineNumbersColumn = helper.padOuter$('#sidedivinner');
$lineNumbersColumn.click();
};
var openSettingsAndWaitForModalToBeVisible = function (done) {
const openSettingsAndWaitForModalToBeVisible = (done) => {
helper.padChrome$('.buttonicon-settings').click();
// wait for modal to be displayed
@ -111,7 +113,7 @@ describe('Pad modal', function () {
helper.waitFor(() => isModalOpened(modalSelector), 10000).done(done);
};
var isEditorDisabled = function () {
const isEditorDisabled = () => {
const editorDocument = helper.padOuter$("iframe[name='ace_inner']").get(0).contentDocument;
const editorBody = editorDocument.getElementById('innerdocbody');
@ -121,7 +123,7 @@ describe('Pad modal', function () {
return editorIsDisabled;
};
var isModalOpened = function (modalSelector) {
const isModalOpened = (modalSelector) => {
const $modal = helper.padChrome$(modalSelector);
return $modal.hasClass('popup-show');

View file

@ -1,3 +1,5 @@
'use strict';
describe('undo button then redo button', function () {
beforeEach(function (cb) {
helper.newPad(cb); // creates a new pad
@ -33,7 +35,6 @@ describe('undo button then redo button', function () {
it('redo some typing with keypress', function (done) {
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;
// get the first text element inside the editable space
const $firstTextElement = inner$('div span').first();
@ -44,12 +45,12 @@ describe('undo button then redo button', function () {
const modifiedValue = $firstTextElement.text(); // get the modified value
expect(modifiedValue).not.to.be(originalValue); // expect the value to change
var e = inner$.Event(helper.evtType);
let e = inner$.Event(helper.evtType);
e.ctrlKey = true; // Control key
e.which = 90; // z
inner$('#innerdocbody').trigger(e);
var e = inner$.Event(helper.evtType);
e = inner$.Event(helper.evtType);
e.ctrlKey = true; // Control key
e.which = 121; // y
inner$('#innerdocbody').trigger(e);

View file

@ -1,14 +1,19 @@
'use strict';
// Test for https://github.com/ether/etherpad-lite/issues/1763
// This test fails in Opera, IE and Safari
// Opera fails due to a weird way of handling the order of execution, yet actual performance seems fine
// Opera fails due to a weird way of handling the order of execution,
// yet actual performance seems fine
// Safari fails due the delay being too great yet the actual performance seems fine
// Firefox might panic that the script is taking too long so will fail
// IE will fail due to running out of memory as it can't fit 2M chars in memory.
// Just FYI Google Docs crashes on large docs whilst trying to Save, it's likely the limitations we are
// Just FYI Google Docs crashes on large docs whilst trying to Save,
// it's likely the limitations we are
// experiencing are more to do with browser limitations than improper implementation.
// A ueber fix for this would be to have a separate lower cpu priority thread that handles operations that aren't
// A ueber fix for this would be to have a separate lower cpu priority
// thread that handles operations that aren't
// visible to the user.
// Adapted from John McLear's original test case.
@ -20,16 +25,18 @@ xdescribe('Responsiveness of Editor', function () {
this.timeout(6000);
});
// JM commented out on 8th Sep 2020 for a release, after release this needs uncommenting
// And the test needs to be fixed to work in Firefox 52 on Windows 7. I am not sure why it fails on this specific platform
// The errors show this.timeout... then crash the browser but I am sure something is actually causing the stack trace and
// And the test needs to be fixed to work in Firefox 52 on Windows 7.
// I am not sure why it fails on this specific platform
// The errors show this.timeout... then crash the browser but
// I am sure something is actually causing the stack trace and
// I just need to narrow down what, offers to help accepted.
it('Fast response to keypress in pad with large amount of contents', function (done) {
// skip on Windows Firefox 52.0
if (window.bowser && window.bowser.windows && window.bowser.firefox && window.bowser.version == '52.0') {
if (window.bowser &&
window.bowser.windows && window.bowser.firefox && window.bowser.version === '52.0') {
this.skip();
}
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;
const chars = '0000000000'; // row of placeholder chars
const amount = 200000; // number of blocks of chars we will insert
const length = (amount * (chars.length) + 1); // include a counter for each space
@ -39,7 +46,7 @@ xdescribe('Responsiveness of Editor', function () {
// get keys to send
const keyMultiplier = 10; // multiplier * 10 == total number of key events
let keysToSend = '';
for (var i = 0; i <= keyMultiplier; i++) {
for (let i = 0; i <= keyMultiplier; i++) {
keysToSend += chars;
}
@ -47,23 +54,23 @@ xdescribe('Responsiveness of Editor', function () {
textElement.sendkeys('{selectall}'); // select all
textElement.sendkeys('{del}'); // clear the pad text
for (var i = 0; i <= amount; i++) {
for (let i = 0; i <= amount; i++) {
text = `${text + chars} `; // add the chars and space to the text contents
}
inner$('div').first().text(text); // Put the text contents into the pad
helper.waitFor(() => // Wait for the new contents to be on the pad
inner$('div').text().length > length
).done(() => {
expect(inner$('div').text().length).to.be.greaterThan(length); // has the text changed?
// Wait for the new contents to be on the pad
helper.waitFor(() => inner$('div').text().length > length).done(() => {
// has the text changed?
expect(inner$('div').text().length).to.be.greaterThan(length);
const start = Date.now(); // get the start time
// send some new text to the screen (ensure all 3 key events are sent)
const el = inner$('div').first();
for (let i = 0; i < keysToSend.length; ++i) {
var x = keysToSend.charCodeAt(i);
const x = keysToSend.charCodeAt(i);
['keyup', 'keypress', 'keydown'].forEach((type) => {
const e = $.Event(type);
const e = new $.Event(type);
e.keyCode = x;
el.trigger(e);
});

View file

@ -1,3 +1,5 @@
'use strict';
describe('select formatting buttons when selection has style applied', function () {
const STYLES = ['italic', 'bold', 'underline', 'strikethrough'];
const SHORTCUT_KEYS = ['I', 'B', 'U', '5']; // italic, bold, underline, strikethrough
@ -21,7 +23,7 @@ describe('select formatting buttons when selection has style applied', function
return $formattingButton.parent().hasClass('selected');
};
var selectLine = function (lineNumber, offsetStart, offsetEnd) {
const selectLine = function (lineNumber, offsetStart, offsetEnd) {
const inner$ = helper.padInner$;
const $line = inner$('div').eq(lineNumber);
helper.selectLines($line, $line, offsetStart, offsetEnd);
@ -58,7 +60,7 @@ describe('select formatting buttons when selection has style applied', function
applyStyleOnLineOnFullLineAndRemoveSelection(line, style, placeCaretOnLine, cb);
};
var applyStyleOnLineOnFullLineAndRemoveSelection = function (line, style, selectTarget, cb) {
const applyStyleOnLineOnFullLineAndRemoveSelection = function (line, style, selectTarget, cb) {
// see if line html has changed
const inner$ = helper.padInner$;
const oldLineHTML = inner$.find('div')[line];
@ -80,7 +82,6 @@ describe('select formatting buttons when selection has style applied', function
const pressFormattingShortcutOnSelection = function (key) {
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;
// get the first text element out of the inner iframe
const $firstTextElement = inner$('div').first();
@ -88,7 +89,7 @@ describe('select formatting buttons when selection has style applied', function
// select this text element
$firstTextElement.sendkeys('{selectall}');
const e = inner$.Event(helper.evtType);
const e = new inner$.Event(helper.evtType);
e.ctrlKey = true; // Control key
e.which = key.charCodeAt(0); // I, U, B, 5
inner$('#innerdocbody').trigger(e);

View file

@ -1,3 +1,5 @@
'use strict';
describe('strikethrough button', function () {
// create a new pad before each test run
beforeEach(function (cb) {
@ -19,7 +21,7 @@ describe('strikethrough button', function () {
const $strikethroughButton = chrome$('.buttonicon-strikethrough');
$strikethroughButton.click();
// ace creates a new dom element when you press a button, so just get the first text element again
// ace creates a new dom element when you press a button, just get the first text element again
const $newFirstTextElement = inner$('div').first();
// is there a <i> element now?

View file

@ -1,3 +1,5 @@
'use strict';
// deactivated, we need a nice way to get the timeslider, this is ugly
xdescribe('timeslider button takes you to the timeslider of a pad', function () {
beforeEach(function (cb) {
@ -12,7 +14,6 @@ xdescribe('timeslider button takes you to the timeslider of a pad', function ()
// get the first text element inside the editable space
const $firstTextElement = inner$('div span').first();
const originalValue = $firstTextElement.text(); // get the original value
const newValue = `Testing${originalValue}`;
$firstTextElement.sendkeys('Testing'); // send line 1 to the pad
const modifiedValue = $firstTextElement.text(); // get the modified value

View file

@ -1,3 +1,5 @@
'use strict';
describe('timeslider', function () {
// create a new pad before each test run
beforeEach(function (cb) {
@ -7,7 +9,7 @@ describe('timeslider', function () {
/**
* @todo test authorsList
*/
it("Shows a date and time in the timeslider and make sure it doesn't include NaN", async function () {
it("Shows a date/time in the timeslider and make sure it doesn't include NaN", async function () {
// make some changes to produce 3 revisions
const revs = 3;

View file

@ -1,3 +1,5 @@
'use strict';
describe('timeslider', function () {
const padId = 735773577357 + (Math.round(Math.random() * 1000));

View file

@ -1,3 +1,5 @@
'use strict';
describe('timeslider', function () {
// create a new pad before each test run
beforeEach(function (cb) {
@ -23,7 +25,8 @@ describe('timeslider', function () {
setTimeout(() => {
// go to timeslider
$('#iframe-container iframe').attr('src', `${$('#iframe-container iframe').attr('src')}/timeslider`);
$('#iframe-container iframe').attr('src',
`${$('#iframe-container iframe').attr('src')}/timeslider`);
setTimeout(() => {
const timeslider$ = $('#iframe-container iframe')[0].contentWindow.$;
@ -66,7 +69,6 @@ describe('timeslider', function () {
// Disabled as jquery trigger no longer works properly
xit('changes the url when clicking on the timeslider', function (done) {
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;
// make some changes to produce 7 revisions
const timePerRev = 1000;
@ -81,13 +83,13 @@ describe('timeslider', function () {
setTimeout(() => {
// go to timeslider
$('#iframe-container iframe').attr('src', `${$('#iframe-container iframe').attr('src')}/timeslider`);
$('#iframe-container iframe').attr('src',
`${$('#iframe-container iframe').attr('src')}/timeslider`);
setTimeout(() => {
const timeslider$ = $('#iframe-container iframe')[0].contentWindow.$;
const $sliderBar = timeslider$('#ui-slider-bar');
const latestContents = timeslider$('#innerdocbody').text();
const oldUrl = $('#iframe-container iframe')[0].contentWindow.location.hash;
// Click somewhere on the timeslider
@ -96,20 +98,23 @@ describe('timeslider', function () {
e.clientY = e.pageY = 60;
$sliderBar.trigger(e);
helper.waitFor(() => $('#iframe-container iframe')[0].contentWindow.location.hash != oldUrl, 6000).always(() => {
expect($('#iframe-container iframe')[0].contentWindow.location.hash).not.to.eql(oldUrl);
done();
});
helper.waitFor(
() => $('#iframe-container iframe')[0].contentWindow.location.hash !== oldUrl, 6000)
.always(() => {
expect(
$('#iframe-container iframe')[0].contentWindow.location.hash
).not.to.eql(oldUrl);
done();
});
}, 6000);
}, revs * timePerRev);
});
it('jumps to a revision given in the url', function (done) {
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;
this.timeout(40000);
// wait for the text to be loaded
helper.waitFor(() => inner$('body').text().length != 0, 10000).always(() => {
helper.waitFor(() => inner$('body').text().length !== 0, 10000).always(() => {
const newLines = inner$('body div').length;
const oldLength = inner$('body').text().length + newLines / 2;
expect(oldLength).to.not.eql(0);
@ -120,22 +125,25 @@ describe('timeslider', function () {
helper.waitFor(() => {
// newLines takes the new lines into account which are strippen when using
// inner$('body').text(), one <div> is used for one line in ACE.
const lenOkay = inner$('body').text().length + newLines / 2 != oldLength;
const lenOkay = inner$('body').text().length + newLines / 2 !== oldLength;
// this waits for the color to be added to our <span>, which means that the revision
// was accepted by the server.
const colorOkay = inner$('span').first().attr('class').indexOf('author-') == 0;
const colorOkay = inner$('span').first().attr('class').indexOf('author-') === 0;
return lenOkay && colorOkay;
}, 10000).always(() => {
// go to timeslider with a specific revision set
$('#iframe-container iframe').attr('src', `${$('#iframe-container iframe').attr('src')}/timeslider#0`);
$('#iframe-container iframe').attr('src',
`${$('#iframe-container iframe').attr('src')}/timeslider#0`);
// wait for the timeslider to be loaded
helper.waitFor(() => {
try {
timeslider$ = $('#iframe-container iframe')[0].contentWindow.$;
} catch (e) {}
} catch (e) {
// Empty catch block <3
}
if (timeslider$) {
return timeslider$('#innerdocbody').text().length == oldLength;
return timeslider$('#innerdocbody').text().length === oldLength;
}
}, 10000).always(() => {
expect(timeslider$('#innerdocbody').text().length).to.eql(oldLength);
@ -147,24 +155,26 @@ describe('timeslider', function () {
it('checks the export url', function (done) {
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;
this.timeout(11000);
inner$('div').first().sendkeys('a');
setTimeout(() => {
// go to timeslider
$('#iframe-container iframe').attr('src', `${$('#iframe-container iframe').attr('src')}/timeslider#0`);
$('#iframe-container iframe').attr('src',
`${$('#iframe-container iframe').attr('src')}/timeslider#0`);
let timeslider$;
let exportLink;
helper.waitFor(() => {
try {
timeslider$ = $('#iframe-container iframe')[0].contentWindow.$;
} catch (e) {}
} catch (e) {
// Empty catch block <3
}
if (!timeslider$) return false;
exportLink = timeslider$('#exportplaina').attr('href');
if (!exportLink) return false;
return exportLink.substr(exportLink.length - 12) == '0/export/txt';
return exportLink.substr(exportLink.length - 12) === '0/export/txt';
}, 6000).always(() => {
expect(exportLink.substr(exportLink.length - 12)).to.eql('0/export/txt');
done();

View file

@ -1,3 +1,5 @@
'use strict';
describe('undo button', function () {
beforeEach(function (cb) {
helper.newPad(cb); // creates a new pad
@ -30,7 +32,6 @@ describe('undo button', function () {
it('undo some typing using a keypress', function (done) {
const inner$ = helper.padInner$;
const chrome$ = helper.padChrome$;
// get the first text element inside the editable space
const $firstTextElement = inner$('div span').first();
@ -40,7 +41,7 @@ describe('undo button', function () {
const modifiedValue = $firstTextElement.text(); // get the modified value
expect(modifiedValue).not.to.be(originalValue); // expect the value to change
const e = inner$.Event(helper.evtType);
const e = new inner$.Event(helper.evtType);
e.ctrlKey = true; // Control key
e.which = 90; // z
inner$('#innerdocbody').trigger(e);

View file

@ -1,3 +1,5 @@
'use strict';
describe('assign unordered list', function () {
// create a new pad before each test run
beforeEach(function (cb) {
@ -130,7 +132,8 @@ describe('Pressing Tab in an UL increases and decreases indentation', function (
});
});
describe('Pressing indent/outdent button in an UL increases and decreases indentation and bullet / ol formatting', function () {
describe('Pressing indent/outdent button in an UL increases and decreases indentation ' +
'and bullet / ol formatting', function () {
// create a new pad before each test run
beforeEach(function (cb) {
helper.newPad(cb);

View file

@ -1,3 +1,5 @@
'use strict';
describe('Automatic pad reload on Force Reconnect message', function () {
let padId, $originalPadFrame;

View file

@ -1,17 +1,19 @@
var srcFolder = '../../../src/node_modules/';
var wd = require(`${srcFolder}wd`);
var async = require(`${srcFolder}async`);
'use strict';
var config = {
const wd = require('ep_etherpad-lite/node_modules/wd');
const async = require('ep_etherpad-lite/node_modules/async');
const config = {
host: 'ondemand.saucelabs.com',
port: 80,
username: process.env.SAUCE_USER,
accessKey: process.env.SAUCE_ACCESS_KEY,
};
var allTestsPassed = true;
let allTestsPassed = true;
// overwrite the default exit code
// in case not all worker can be run (due to saucelabs limits), `queue.drain` below will not be called
// in case not all worker can be run (due to saucelabs limits),
// `queue.drain` below will not be called
// and the script would silently exit with error code 0
process.exitCode = 2;
process.on('exit', (code) => {
@ -20,13 +22,18 @@ process.on('exit', (code) => {
}
});
var sauceTestWorker = async.queue((testSettings, callback) => {
const browser = wd.promiseChainRemote(config.host, config.port, config.username, config.accessKey);
const name = `${process.env.GIT_HASH} - ${testSettings.browserName} ${testSettings.version}, ${testSettings.platform}`;
const sauceTestWorker = async.queue((testSettings, callback) => {
const browser = wd.promiseChainRemote(
config.host, config.port, config.username, config.accessKey);
const name =
`${process.env.GIT_HASH} - ${testSettings.browserName} ` +
`${testSettings.version}, ${testSettings.platform}`;
testSettings.name = name;
testSettings.public = true;
testSettings.build = process.env.GIT_HASH;
testSettings.extendedDebugging = true; // console.json can be downloaded via saucelabs, don't know how to print them into output of the tests
// console.json can be downloaded via saucelabs,
// don't know how to print them into output of the tests
testSettings.extendedDebugging = true;
testSettings.tunnelIdentifier = process.env.TRAVIS_JOB_NUMBER;
browser.init(testSettings).get('http://localhost:9001/tests/frontend/', () => {
@ -34,7 +41,7 @@ var sauceTestWorker = async.queue((testSettings, callback) => {
console.log(`Remote sauce test '${name}' started! ${url}`);
// tear down the test excecution
const stopSauce = function (success, timesup) {
const stopSauce = (success, timesup) => {
clearInterval(getStatusInterval);
clearTimeout(timeout);
@ -43,12 +50,15 @@ var sauceTestWorker = async.queue((testSettings, callback) => {
allTestsPassed = false;
}
// if stopSauce is called via timeout (in contrast to via getStatusInterval) than the log of up to the last
// if stopSauce is called via timeout
// (in contrast to via getStatusInterval) than the log of up to the last
// five seconds may not be available here. It's an error anyway, so don't care about it.
printLog(logIndex);
if (timesup) {
console.log(`[${testSettings.browserName} ${testSettings.platform}${testSettings.version === '' ? '' : (` ${testSettings.version}`)}] \x1B[31mFAILED\x1B[39m allowed test duration exceeded`);
console.log(`[${testSettings.browserName} ${testSettings.platform}` +
`${testSettings.version === '' ? '' : (` ${testSettings.version}`)}]` +
' \x1B[31mFAILED\x1B[39m allowed test duration exceeded');
}
console.log(`Remote sauce test '${name}' finished! ${url}`);
@ -58,17 +68,19 @@ var sauceTestWorker = async.queue((testSettings, callback) => {
/**
* timeout if a test hangs or the job exceeds 14.5 minutes
* It's necessary because if travis kills the saucelabs session due to inactivity, we don't get any output
* @todo this should be configured in testSettings, see https://wiki.saucelabs.com/display/DOCS/Test+Configuration+Options#TestConfigurationOptions-Timeouts
* It's necessary because if travis kills the saucelabs session due to inactivity,
* we don't get any output
* @todo this should be configured in testSettings, see
* https://wiki.saucelabs.com/display/DOCS/Test+Configuration+Options#TestConfigurationOptions-Timeouts
*/
var timeout = setTimeout(() => {
const timeout = setTimeout(() => {
stopSauce(false, true);
}, 870000); // travis timeout is 15 minutes, set this to a slightly lower value
let knownConsoleText = '';
// how many characters of the log have been sent to travis
let logIndex = 0;
var getStatusInterval = setInterval(() => {
const getStatusInterval = setInterval(() => {
browser.eval("$('#console').text()", (err, consoleText) => {
if (!consoleText || err) {
return;
@ -76,9 +88,10 @@ var sauceTestWorker = async.queue((testSettings, callback) => {
knownConsoleText = consoleText;
if (knownConsoleText.indexOf('FINISHED') > 0) {
const match = knownConsoleText.match(/FINISHED.*([0-9]+) tests passed, ([0-9]+) tests failed/);
const match = knownConsoleText.match(
/FINISHED.*([0-9]+) tests passed, ([0-9]+) tests failed/);
// finished without failures
if (match[2] && match[2] == '0') {
if (match[2] && match[2] === '0') {
stopSauce(true);
// finished but some tests did not return or some tests failed
@ -99,13 +112,17 @@ var sauceTestWorker = async.queue((testSettings, callback) => {
*
* @param {number} index offset from where to start
*/
function printLog(index) {
let testResult = knownConsoleText.substring(index).replace(/\[red\]/g, '\x1B[31m').replace(/\[yellow\]/g, '\x1B[33m')
const printLog = (index) => {
let testResult = knownConsoleText.substring(index)
.replace(/\[red\]/g, '\x1B[31m').replace(/\[yellow\]/g, '\x1B[33m')
.replace(/\[green\]/g, '\x1B[32m').replace(/\[clear\]/g, '\x1B[39m');
testResult = testResult.split('\\n').map((line) => `[${testSettings.browserName} ${testSettings.platform}${testSettings.version === '' ? '' : (` ${testSettings.version}`)}] ${line}`).join('\n');
testResult = testResult.split('\\n').map((line) => `[${testSettings.browserName} ` +
`${testSettings.platform}` +
`${testSettings.version === '' ? '' : (` ${testSettings.version}`)}]` +
`${line}`).join('\n');
console.log(testResult);
}
};
});
}, 6); // run 6 tests in parrallel

View file

@ -1,8 +1,12 @@
'use strict';
let etherpad;
try {
var etherpad = require('../../src/node_modules/etherpad-cli-client');
etherpad = require('ep_etherpad-lite/node_modules/etherpad-cli-client');
// ugly
} catch {
var etherpad = require('etherpad-cli-client');
/* eslint-disable-next-line node/no-missing-require */
etherpad = require('etherpad-cli-client'); // uses global
}
const pad = etherpad.connect(process.argv[2]);
pad.on('connected', () => {
@ -18,7 +22,7 @@ pad.on('connected', () => {
});
// in case of disconnect exit code 1
pad.on('message', (message) => {
if (message.disconnect == 'rateLimited') {
if (message.disconnect === 'rateLimited') {
process.exit(1);
}
});