2021-02-01 20:23:14 +00:00
|
|
|
'use strict';
|
|
|
|
|
2020-11-23 18:21:51 +00:00
|
|
|
describe('author of pad edition', function () {
|
|
|
|
const REGULAR_LINE = 0;
|
|
|
|
const LINE_WITH_ORDERED_LIST = 1;
|
|
|
|
const LINE_WITH_UNORDERED_LIST = 2;
|
2018-07-09 20:44:38 +00:00
|
|
|
|
|
|
|
// author 1 creates a new pad with some content (regular lines and lists)
|
2020-11-23 18:21:51 +00:00
|
|
|
before(function (done) {
|
2021-02-01 20:23:14 +00:00
|
|
|
const padId = helper.newPad(() => {
|
2018-07-09 20:44:38 +00:00
|
|
|
// make sure pad has at least 3 lines
|
2020-11-23 18:21:51 +00:00
|
|
|
const $firstLine = helper.padInner$('div').first();
|
2021-02-01 20:23:14 +00:00
|
|
|
const threeLines = ['regular line', 'line with ordered list', 'line with unordered list']
|
|
|
|
.join('<br>');
|
2018-07-09 20:44:38 +00:00
|
|
|
$firstLine.html(threeLines);
|
|
|
|
|
|
|
|
// wait for lines to be processed by Etherpad
|
2020-11-23 18:21:51 +00:00
|
|
|
helper.waitFor(() => {
|
|
|
|
const $lineWithUnorderedList = getLine(LINE_WITH_UNORDERED_LIST);
|
2018-07-09 20:44:38 +00:00
|
|
|
return $lineWithUnorderedList.text() === 'line with unordered list';
|
2020-11-23 18:21:51 +00:00
|
|
|
}).done(() => {
|
2018-07-09 20:44:38 +00:00
|
|
|
// create the unordered list
|
2020-11-23 18:21:51 +00:00
|
|
|
const $lineWithUnorderedList = getLine(LINE_WITH_UNORDERED_LIST);
|
2018-07-09 20:44:38 +00:00
|
|
|
$lineWithUnorderedList.sendkeys('{selectall}');
|
|
|
|
|
2020-11-23 18:21:51 +00:00
|
|
|
const $insertUnorderedListButton = helper.padChrome$('.buttonicon-insertunorderedlist');
|
2018-07-09 20:44:38 +00:00
|
|
|
$insertUnorderedListButton.click();
|
|
|
|
|
2020-11-23 18:21:51 +00:00
|
|
|
helper.waitFor(() => {
|
|
|
|
const $lineWithUnorderedList = getLine(LINE_WITH_UNORDERED_LIST);
|
2018-07-09 20:44:38 +00:00
|
|
|
return $lineWithUnorderedList.find('ul li').length === 1;
|
2020-11-23 18:21:51 +00:00
|
|
|
}).done(() => {
|
2018-07-09 20:44:38 +00:00
|
|
|
// create the ordered list
|
2020-11-23 18:21:51 +00:00
|
|
|
const $lineWithOrderedList = getLine(LINE_WITH_ORDERED_LIST);
|
2018-07-09 20:44:38 +00:00
|
|
|
$lineWithOrderedList.sendkeys('{selectall}');
|
|
|
|
|
2020-11-23 18:21:51 +00:00
|
|
|
const $insertOrderedListButton = helper.padChrome$('.buttonicon-insertorderedlist');
|
2018-07-09 20:44:38 +00:00
|
|
|
$insertOrderedListButton.click();
|
|
|
|
|
2020-11-23 18:21:51 +00:00
|
|
|
helper.waitFor(() => {
|
|
|
|
const $lineWithOrderedList = getLine(LINE_WITH_ORDERED_LIST);
|
2018-07-09 20:44:38 +00:00
|
|
|
return $lineWithOrderedList.find('ol li').length === 1;
|
2020-11-23 18:21:51 +00:00
|
|
|
}).done(() => {
|
2018-07-09 20:44:38 +00:00
|
|
|
// Reload pad, to make changes as a second user. Need a timeout here to make sure
|
|
|
|
// all changes were saved before reloading
|
2020-11-23 18:21:51 +00:00
|
|
|
setTimeout(() => {
|
2018-09-01 20:53:46 +00:00
|
|
|
// 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
|
2021-02-01 20:23:14 +00:00
|
|
|
helper.padChrome$.document.cookie =
|
|
|
|
'token=foo;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
|
2018-09-01 20:53:46 +00:00
|
|
|
|
2018-07-09 20:44:38 +00:00
|
|
|
helper.newPad(done, padId);
|
|
|
|
}, 1000);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.timeout(60000);
|
|
|
|
});
|
|
|
|
|
|
|
|
// author 2 makes some changes on the pad
|
2020-11-23 18:21:51 +00:00
|
|
|
it('marks only the new content as changes of the second user on a regular line', function (done) {
|
2018-07-09 20:44:38 +00:00
|
|
|
changeLineAndCheckOnlyThatChangeIsFromThisAuthor(REGULAR_LINE, 'x', done);
|
|
|
|
});
|
|
|
|
|
2021-02-01 20:23:14 +00:00
|
|
|
it('marks only the new content as changes of the second user on a ' +
|
|
|
|
'line with ordered list', function (done) {
|
2018-07-09 20:44:38 +00:00
|
|
|
changeLineAndCheckOnlyThatChangeIsFromThisAuthor(LINE_WITH_ORDERED_LIST, 'y', done);
|
|
|
|
});
|
|
|
|
|
2021-02-01 20:23:14 +00:00
|
|
|
it('marks only the new content as changes of the second user on ' +
|
|
|
|
'a line with unordered list', function (done) {
|
2018-07-09 20:44:38 +00:00
|
|
|
changeLineAndCheckOnlyThatChangeIsFromThisAuthor(LINE_WITH_UNORDERED_LIST, 'z', done);
|
|
|
|
});
|
|
|
|
|
|
|
|
/* ********************** Helper functions ************************ */
|
2021-02-01 20:23:14 +00:00
|
|
|
const getLine = (lineNumber) => helper.padInner$('div').eq(lineNumber);
|
2018-07-09 20:44:38 +00:00
|
|
|
|
2021-02-01 20:23:14 +00:00
|
|
|
const getAuthorFromClassList = (classes) => classes.find((cls) => cls.startsWith('author'));
|
2018-07-09 20:44:38 +00:00
|
|
|
|
2021-02-01 20:23:14 +00:00
|
|
|
const changeLineAndCheckOnlyThatChangeIsFromThisAuthor = (lineNumber, textChange, done) => {
|
2018-07-09 20:44:38 +00:00
|
|
|
// get original author class
|
2020-11-23 18:21:51 +00:00
|
|
|
const classes = getLine(lineNumber).find('span').first().attr('class').split(' ');
|
|
|
|
const originalAuthor = getAuthorFromClassList(classes);
|
2018-07-09 20:44:38 +00:00
|
|
|
|
|
|
|
// make change on target line
|
2020-11-23 18:21:51 +00:00
|
|
|
const $regularLine = getLine(lineNumber);
|
2018-07-09 20:44:38 +00:00
|
|
|
helper.selectLines($regularLine, $regularLine, 2, 2); // place caret after 2nd char of line
|
|
|
|
$regularLine.sendkeys(textChange);
|
|
|
|
|
|
|
|
// wait for change to be processed by Etherpad
|
2020-11-23 18:21:51 +00:00
|
|
|
let otherAuthorsOfLine;
|
|
|
|
helper.waitFor(() => {
|
|
|
|
const authorsOfLine = getLine(lineNumber).find('span').map(function () {
|
2018-07-09 20:44:38 +00:00
|
|
|
return getAuthorFromClassList($(this).attr('class').split(' '));
|
|
|
|
}).get();
|
2020-11-23 18:21:51 +00:00
|
|
|
otherAuthorsOfLine = authorsOfLine.filter((author) => author !== originalAuthor);
|
|
|
|
const lineHasChangeOfThisAuthor = otherAuthorsOfLine.length > 0;
|
2018-07-09 20:44:38 +00:00
|
|
|
return lineHasChangeOfThisAuthor;
|
2020-11-23 18:21:51 +00:00
|
|
|
}).done(() => {
|
|
|
|
const thisAuthor = otherAuthorsOfLine[0];
|
|
|
|
const $changeOfThisAuthor = getLine(lineNumber).find(`span.${thisAuthor}`);
|
2018-07-09 20:44:38 +00:00
|
|
|
expect($changeOfThisAuthor.text()).to.be(textChange);
|
|
|
|
done();
|
|
|
|
});
|
2020-11-23 18:21:51 +00:00
|
|
|
};
|
2018-07-09 20:44:38 +00:00
|
|
|
});
|