mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-25 09:56:15 -04:00
tests: refactor some frontend tests (#4408)
* don't include sendkeys in index.html as it's included in helper.init mocha opts: add default timeout and replace ignoreLeaks with checkLeaks, as the former is deprecated * introduce helper.edit to write to a pad * add test to check if helper.edit() supports line numbers * helper tests: waitFor/waitForPromise seem to be a little bit faster sometimes * tests: refactor chat.js * tests: refactor timeslider_numeric_padID * tests: refactor timeslider_labels * tests: refactor timeslider_follow * ensure followContents is enabled, although it should be by default * timeslider_follow: increase number of revision for Edge * make textLines() depend on linesDiv() Co-authored-by: Richard Hansen <rhansen@rhansen.org> * make linesDiv return standard Array * use `contain` instead of `indexOf` * more fixes from the review * review fixes * align waitFor and waitForPromise behaviour * timeslider_follow: check if it's following to the correct lines * lower expected waitFor/waitForPromise interval check * disable responsivness and regression test in timeslider_follow * timeslider_follow: fix Range detection * more explicit test for linesDiv Co-authored-by: Richard Hansen <rhansen@rhansen.org>
This commit is contained in:
parent
94cb000e8f
commit
69c7033a86
11 changed files with 685 additions and 252 deletions
|
@ -1,55 +1,120 @@
|
|||
describe("timeslider", function(){
|
||||
describe("timeslider follow", function(){
|
||||
//create a new pad before each test run
|
||||
beforeEach(function(cb){
|
||||
helper.newPad(cb);
|
||||
this.timeout(6000);
|
||||
});
|
||||
|
||||
it("follow content as it's added to timeslider", function(done) { // passes
|
||||
var inner$ = helper.padInner$;
|
||||
var chrome$ = helper.padChrome$;
|
||||
|
||||
// make some changes to produce 100 revisions
|
||||
var timePerRev = 900
|
||||
, revs = 10;
|
||||
this.timeout(revs*timePerRev+10000);
|
||||
for(var i=0; i < revs; i++) {
|
||||
setTimeout(function() {
|
||||
// enter 'a' in the first text element
|
||||
inner$("div").last().sendkeys('a\n');
|
||||
inner$("div").last().sendkeys('{enter}');
|
||||
inner$("div").last().sendkeys('{enter}');
|
||||
inner$("div").last().sendkeys('{enter}');
|
||||
inner$("div").last().sendkeys('{enter}');
|
||||
}, timePerRev*i);
|
||||
it("content as it's added to timeslider", async function() {
|
||||
// send 6 revisions
|
||||
let revs = 6;
|
||||
let message = 'a\n\n\n\n\n\n\n\n\n\n';
|
||||
let newLines = message.split('\n').length
|
||||
for (let i=0;i<revs;i++){
|
||||
await helper.edit(message, newLines*i + 1);
|
||||
}
|
||||
|
||||
setTimeout(function() {
|
||||
// go to timeslider
|
||||
$('#iframe-container iframe').attr('src', $('#iframe-container iframe').attr('src')+'/timeslider#0');
|
||||
await helper.gotoTimeslider(0);
|
||||
await helper.waitForPromise(function(){return helper.contentWindow().location.hash === '#0'})
|
||||
|
||||
setTimeout(function() {
|
||||
var timeslider$ = $('#iframe-container iframe')[0].contentWindow.$;
|
||||
var $sliderBar = timeslider$('#ui-slider-bar');
|
||||
let originalTop = helper.contentWindow().$('#innerdocbody').offset();
|
||||
|
||||
var latestContents = timeslider$('#innerdocbody').text();
|
||||
// set to follow contents as it arrives
|
||||
helper.contentWindow().$('#options-followContents').prop("checked", true);
|
||||
helper.contentWindow().$('#playpause_button_icon').click();
|
||||
|
||||
// set to follow contents as it arrives
|
||||
timeslider$('#options-followContents').prop("checked", true);
|
||||
|
||||
var originalTop = timeslider$('#innerdocbody').offset();
|
||||
timeslider$('#playpause_button_icon').click();
|
||||
|
||||
setTimeout(function() {
|
||||
//make sure the text has changed
|
||||
var newTop = timeslider$('#innerdocbody').offset();
|
||||
expect( originalTop ).not.to.eql( newTop );
|
||||
done();
|
||||
}, 1000);
|
||||
|
||||
}, 2000);
|
||||
}, revs*timePerRev);
|
||||
let newTop;
|
||||
return helper.waitForPromise(function(){
|
||||
newTop = helper.contentWindow().$('#innerdocbody').offset();
|
||||
return newTop.top < originalTop.top;
|
||||
})
|
||||
});
|
||||
|
||||
/**
|
||||
* Tests for bug described in #4389
|
||||
* The goal is to scroll to the first line that contains a change right before
|
||||
* the change is applied.
|
||||
*
|
||||
*/
|
||||
it("only to lines that exist in the current pad view, see #4389", async function(){
|
||||
// Select everything and clear via delete key
|
||||
let e = helper.padInner$.Event(helper.evtType);
|
||||
e.keyCode = 8; //delete key
|
||||
let lines = helper.linesDiv();
|
||||
helper.selectLines(lines[0], lines[lines.length - 1]); // select all lines
|
||||
// probably unnecessary, but wait for the selection to be Range not Caret
|
||||
await helper.waitForPromise(function(){
|
||||
return !helper.padInner$.document.getSelection().isCollapsed;
|
||||
//only supported in FF57+
|
||||
//return helper.padInner$.document.getSelection().type === 'Range';
|
||||
})
|
||||
helper.padInner$('#innerdocbody').trigger(e);
|
||||
await helper.waitForPromise(function(){
|
||||
return helper.commits.length === 1;
|
||||
})
|
||||
await helper.edit("Test line\n\n")
|
||||
await helper.edit("Another test line", 3)
|
||||
|
||||
await helper.gotoTimeslider();
|
||||
|
||||
// set to follow contents as it arrives
|
||||
helper.contentWindow().$('#options-followContents').prop("checked", true);
|
||||
|
||||
let oldYPosition = helper.contentWindow().$("#editorcontainerbox")[0].scrollTop;
|
||||
expect(oldYPosition).to.be(0);
|
||||
|
||||
/**
|
||||
* pad content rev 0 [default Pad text]
|
||||
* pad content rev 1 ['']
|
||||
* pad content rev 2 ['Test line','','']
|
||||
* pad content rev 3 ['Test line','','Another test line']
|
||||
*/
|
||||
|
||||
// line 3 changed
|
||||
helper.contentWindow().$('#leftstep').click();
|
||||
await helper.waitForPromise(function(){
|
||||
return hasFollowedToLine(3);
|
||||
})
|
||||
|
||||
// line 1 is the first line that changed
|
||||
helper.contentWindow().$('#leftstep').click();
|
||||
await helper.waitForPromise(function(){
|
||||
return hasFollowedToLine(1);
|
||||
})
|
||||
|
||||
// line 1 changed
|
||||
helper.contentWindow().$('#leftstep').click();
|
||||
await helper.waitForPromise(function(){
|
||||
return hasFollowedToLine(1);
|
||||
})
|
||||
|
||||
// line 1 changed
|
||||
helper.contentWindow().$('#rightstep').click();
|
||||
await helper.waitForPromise(function(){
|
||||
return hasFollowedToLine(1);
|
||||
})
|
||||
|
||||
// line 1 is the first line that changed
|
||||
helper.contentWindow().$('#rightstep').click();
|
||||
await helper.waitForPromise(function(){
|
||||
return hasFollowedToLine(1);
|
||||
})
|
||||
|
||||
// line 3 changed
|
||||
helper.contentWindow().$('#rightstep').click();
|
||||
return helper.waitForPromise(function(){
|
||||
return hasFollowedToLine(3);
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {number} lineNum
|
||||
* @returns {boolean} scrolled to the lineOffset?
|
||||
*/
|
||||
function hasFollowedToLine(lineNum) {
|
||||
let scrollPosition = helper.contentWindow().$("#editorcontainerbox")[0].scrollTop;
|
||||
let lineOffset = helper.contentWindow().$('#innerdocbody').find(`div:nth-child(${lineNum})`)[0].offsetTop;
|
||||
|
||||
return Math.abs(scrollPosition - lineOffset) < 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue