2021-02-01 20:23:14 +00:00
|
|
|
'use strict';
|
|
|
|
|
2020-11-23 13:21:51 -05: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 17:44:38 -03:00
|
|
|
|
|
|
|
// author 1 creates a new pad with some content (regular lines and lists)
|
2021-03-26 17:09:20 -04:00
|
|
|
before(async function () {
|
|
|
|
const padId = await helper.aNewPad();
|
|
|
|
|
|
|
|
// 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>');
|
|
|
|
$firstLine.html(threeLines);
|
|
|
|
|
|
|
|
// wait for lines to be processed by Etherpad
|
2021-04-01 03:10:18 -04:00
|
|
|
await helper.waitForPromise(() => (
|
|
|
|
getLine(LINE_WITH_UNORDERED_LIST).text() === 'line with unordered list' &&
|
|
|
|
helper.commits.length === 1));
|
2021-03-26 17:09:20 -04:00
|
|
|
|
|
|
|
// create the unordered list
|
|
|
|
const $lineWithUnorderedList = getLine(LINE_WITH_UNORDERED_LIST);
|
|
|
|
$lineWithUnorderedList.sendkeys('{selectall}');
|
|
|
|
|
|
|
|
const $insertUnorderedListButton = helper.padChrome$('.buttonicon-insertunorderedlist');
|
2023-08-08 18:26:25 +02:00
|
|
|
$insertUnorderedListButton.trigger('click');
|
2021-03-26 17:09:20 -04:00
|
|
|
|
2021-04-01 03:10:18 -04:00
|
|
|
await helper.waitForPromise(() => (
|
|
|
|
getLine(LINE_WITH_UNORDERED_LIST).find('ul li').length === 1 &&
|
|
|
|
helper.commits.length === 2));
|
2021-03-26 17:09:20 -04:00
|
|
|
|
|
|
|
// create the ordered list
|
|
|
|
const $lineWithOrderedList = getLine(LINE_WITH_ORDERED_LIST);
|
|
|
|
$lineWithOrderedList.sendkeys('{selectall}');
|
|
|
|
|
|
|
|
const $insertOrderedListButton = helper.padChrome$('.buttonicon-insertorderedlist');
|
2023-08-08 18:26:25 +02:00
|
|
|
$insertOrderedListButton.trigger('click');
|
2021-03-26 17:09:20 -04:00
|
|
|
|
2021-04-01 03:10:18 -04:00
|
|
|
await helper.waitForPromise(() => (
|
|
|
|
getLine(LINE_WITH_ORDERED_LIST).find('ol li').length === 1 &&
|
|
|
|
helper.commits.length === 3));
|
2021-03-26 17:09:20 -04:00
|
|
|
|
|
|
|
// Expire cookie, so author is changed after reloading the pad.
|
2021-03-26 01:09:56 -04:00
|
|
|
const {Cookies} = helper.padChrome$.window.require('ep_etherpad-lite/static/js/pad_utils');
|
|
|
|
Cookies.remove('token');
|
2021-03-26 17:09:20 -04:00
|
|
|
|
|
|
|
// Reload pad, to make changes as a second user.
|
|
|
|
await helper.aNewPad({id: padId});
|
2018-07-09 17:44:38 -03:00
|
|
|
});
|
|
|
|
|
|
|
|
// author 2 makes some changes on the pad
|
2021-03-26 17:09:20 -04:00
|
|
|
it('regular line', async function () {
|
|
|
|
await changeLineAndCheckOnlyThatChangeIsFromThisAuthor(REGULAR_LINE, 'x');
|
2018-07-09 17:44:38 -03:00
|
|
|
});
|
|
|
|
|
2021-03-26 17:09:20 -04:00
|
|
|
it('line with ordered list', async function () {
|
|
|
|
await changeLineAndCheckOnlyThatChangeIsFromThisAuthor(LINE_WITH_ORDERED_LIST, 'y');
|
2018-07-09 17:44:38 -03:00
|
|
|
});
|
|
|
|
|
2021-03-26 17:09:20 -04:00
|
|
|
it('line with unordered list', async function () {
|
|
|
|
await changeLineAndCheckOnlyThatChangeIsFromThisAuthor(LINE_WITH_UNORDERED_LIST, 'z');
|
2018-07-09 17:44:38 -03:00
|
|
|
});
|
|
|
|
|
|
|
|
/* ********************** Helper functions ************************ */
|
2021-02-01 20:23:14 +00:00
|
|
|
const getLine = (lineNumber) => helper.padInner$('div').eq(lineNumber);
|
2018-07-09 17:44:38 -03:00
|
|
|
|
2021-02-01 20:23:14 +00:00
|
|
|
const getAuthorFromClassList = (classes) => classes.find((cls) => cls.startsWith('author'));
|
2018-07-09 17:44:38 -03:00
|
|
|
|
2021-03-26 17:09:20 -04:00
|
|
|
const changeLineAndCheckOnlyThatChangeIsFromThisAuthor = async (lineNumber, textChange) => {
|
2018-07-09 17:44:38 -03:00
|
|
|
// get original author class
|
2020-11-23 13:21:51 -05:00
|
|
|
const classes = getLine(lineNumber).find('span').first().attr('class').split(' ');
|
|
|
|
const originalAuthor = getAuthorFromClassList(classes);
|
2018-07-09 17:44:38 -03:00
|
|
|
|
|
|
|
// make change on target line
|
2020-11-23 13:21:51 -05:00
|
|
|
const $regularLine = getLine(lineNumber);
|
2018-07-09 17:44:38 -03: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 13:21:51 -05:00
|
|
|
let otherAuthorsOfLine;
|
2021-03-26 17:09:20 -04:00
|
|
|
await helper.waitForPromise(() => {
|
2020-11-23 13:21:51 -05:00
|
|
|
const authorsOfLine = getLine(lineNumber).find('span').map(function () {
|
2018-07-09 17:44:38 -03:00
|
|
|
return getAuthorFromClassList($(this).attr('class').split(' '));
|
|
|
|
}).get();
|
2020-11-23 13:21:51 -05:00
|
|
|
otherAuthorsOfLine = authorsOfLine.filter((author) => author !== originalAuthor);
|
|
|
|
const lineHasChangeOfThisAuthor = otherAuthorsOfLine.length > 0;
|
2018-07-09 17:44:38 -03:00
|
|
|
return lineHasChangeOfThisAuthor;
|
|
|
|
});
|
2021-03-26 17:09:20 -04:00
|
|
|
const thisAuthor = otherAuthorsOfLine[0];
|
|
|
|
const $changeOfThisAuthor = getLine(lineNumber).find(`span.${thisAuthor}`);
|
|
|
|
expect($changeOfThisAuthor.text()).to.be(textChange);
|
2020-11-23 13:21:51 -05:00
|
|
|
};
|
2018-07-09 17:44:38 -03:00
|
|
|
});
|