mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-24 17:36:14 -04:00
Enable multi-line selection on frontend tests
This commit is contained in:
parent
b24e62f90a
commit
95dc9d0315
3 changed files with 209 additions and 10 deletions
|
@ -55,7 +55,7 @@ describe("the test helper", function(){
|
|||
it("takes an interval and checks on every interval", function(done){
|
||||
this.timeout(4000);
|
||||
var checks = 0;
|
||||
|
||||
|
||||
helper.waitFor(function(){
|
||||
checks++;
|
||||
return false;
|
||||
|
@ -96,4 +96,99 @@ describe("the test helper", function(){
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("the selectLines method", function(){
|
||||
// function to support tests, use a single way to represent whitespaces
|
||||
var cleanText = function(text){
|
||||
return text
|
||||
.replace(/\n/gi, "\\\\n") // avoid \n to be replaced by \s on next line
|
||||
.replace(/\s/gi, " ")
|
||||
.replace(/\\\\n/gi, "\n"); // move back \n to its original state
|
||||
}
|
||||
|
||||
before(function(done){
|
||||
helper.newPad(function() {
|
||||
// create some lines to be used on the tests
|
||||
var $firstLine = helper.padInner$("div").first();
|
||||
$firstLine.sendkeys("{selectall}some{enter}short{enter}lines{enter}to test{enter}");
|
||||
|
||||
// wait for lines to be split
|
||||
helper.waitFor(function(){
|
||||
var $fourthLine = helper.padInner$("div").slice(3,4);
|
||||
return $fourthLine.text() === "to test";
|
||||
}).done(done);
|
||||
});
|
||||
|
||||
this.timeout(60000);
|
||||
});
|
||||
|
||||
it("changes editor selection to be between startOffset of $startLine and endOffset of $endLine", function(done){
|
||||
var inner$ = helper.padInner$;
|
||||
|
||||
var startOffset = 2;
|
||||
var endOffset = 4;
|
||||
|
||||
var $lines = inner$("div");
|
||||
var $startLine = $lines.slice(1,2);
|
||||
var $endLine = $lines.slice(3,4);
|
||||
|
||||
helper.selectLines($startLine, $endLine, startOffset, endOffset);
|
||||
|
||||
var selection = inner$.document.getSelection();
|
||||
expect(cleanText(selection.toString())).to.be("ort \nlines \nto t");
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it("ends selection at beginning of $endLine when it is an empty line", function(done){
|
||||
var inner$ = helper.padInner$;
|
||||
|
||||
var startOffset = 2;
|
||||
var endOffset = 1;
|
||||
|
||||
var $lines = inner$("div");
|
||||
var $startLine = $lines.slice(1,2);
|
||||
var $endLine = $lines.slice(4,5);
|
||||
|
||||
helper.selectLines($startLine, $endLine, startOffset, endOffset);
|
||||
|
||||
var selection = inner$.document.getSelection();
|
||||
expect(cleanText(selection.toString())).to.be("ort \nlines \nto test\n");
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it("selects full line when offset is longer than line content", function(done){
|
||||
var inner$ = helper.padInner$;
|
||||
|
||||
var startOffset = 2;
|
||||
var endOffset = 50;
|
||||
|
||||
var $lines = inner$("div");
|
||||
var $startLine = $lines.slice(1,2);
|
||||
var $endLine = $lines.slice(3,4);
|
||||
|
||||
helper.selectLines($startLine, $endLine, startOffset, endOffset);
|
||||
|
||||
var selection = inner$.document.getSelection();
|
||||
expect(cleanText(selection.toString())).to.be("ort \nlines \nto test");
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it("selects all text between beginning of $startLine and end of $endLine when no offset is provided", function(done){
|
||||
var inner$ = helper.padInner$;
|
||||
|
||||
var $lines = inner$("div");
|
||||
var $startLine = $lines.slice(1,2);
|
||||
var $endLine = $lines.slice(3,4);
|
||||
|
||||
helper.selectLines($startLine, $endLine);
|
||||
|
||||
var selection = inner$.document.getSelection();
|
||||
expect(cleanText(selection.toString())).to.be("short \nlines \nto test");
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -142,6 +142,51 @@ describe("indentation button", function(){
|
|||
});
|
||||
});
|
||||
|
||||
it("issue #2772 shows '*' when multiple indented lines receive a style and are outdented", function(done){
|
||||
var inner$ = helper.padInner$;
|
||||
var chrome$ = helper.padChrome$;
|
||||
|
||||
// make sure pad has more than one line
|
||||
inner$("div").first().sendkeys("First{enter}Second{enter}");
|
||||
helper.waitFor(function(){
|
||||
return inner$("div").first().text().trim() === "First";
|
||||
}).done(function(){
|
||||
// indent first 2 lines
|
||||
var $lines = inner$("div");
|
||||
var $firstLine = $lines.first();
|
||||
var $secondLine = $lines.slice(1,2);
|
||||
helper.selectLines($firstLine, $secondLine);
|
||||
|
||||
var $indentButton = chrome$(".buttonicon-indent");
|
||||
$indentButton.click();
|
||||
|
||||
helper.waitFor(function(){
|
||||
return inner$("div").first().find("ul li").length === 1;
|
||||
}).done(function(){
|
||||
// apply bold
|
||||
var $boldButton = chrome$(".buttonicon-bold");
|
||||
$boldButton.click();
|
||||
|
||||
helper.waitFor(function(){
|
||||
return inner$("div").first().find("b").length === 1;
|
||||
}).done(function(){
|
||||
// outdent first 2 lines
|
||||
var $outdentButton = chrome$(".buttonicon-outdent");
|
||||
$outdentButton.click();
|
||||
helper.waitFor(function(){
|
||||
return inner$("div").first().find("ul li").length === 0;
|
||||
}).done(function(){
|
||||
// check if '*' is displayed
|
||||
var $secondLine = inner$("div").slice(1,2);
|
||||
expect($secondLine.text().trim()).to.be("Second");
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
|
||||
it("makes text indented and outdented", function() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue