pad.pub0.org/tests/frontend/specs/redo.js

82 lines
2.7 KiB
JavaScript
Raw Normal View History

2012-10-28 18:19:16 +00:00
describe("undo button then redo button", function(){
2012-10-09 00:30:46 +00:00
beforeEach(function(cb){
helper.newPad(cb); // creates a new pad
2012-11-01 23:19:59 +00:00
this.timeout(60000);
2012-10-09 00:30:46 +00:00
});
it("redo some typing with button", function(done){
2012-10-09 00:30:46 +00:00
var inner$ = helper.padInner$;
var chrome$ = helper.padChrome$;
2012-10-09 00:30:46 +00:00
// get the first text element inside the editable space
var $firstTextElement = inner$("div span").first();
var originalValue = $firstTextElement.text(); // get the original value
2012-10-28 18:19:16 +00:00
var newString = "Foo";
2012-10-09 00:30:46 +00:00
2012-10-28 18:19:16 +00:00
$firstTextElement.sendkeys(newString); // send line 1 to the pad
2012-10-09 00:30:46 +00:00
var modifiedValue = $firstTextElement.text(); // get the modified value
expect(modifiedValue).not.to.be(originalValue); // expect the value to change
2012-10-28 18:19:16 +00:00
// get undo and redo buttons
2012-10-09 00:30:46 +00:00
var $undoButton = chrome$(".buttonicon-undo");
var $redoButton = chrome$(".buttonicon-redo");
// click the buttons
2012-10-28 18:19:16 +00:00
$undoButton.click(); // removes foo
$redoButton.click(); // resends foo
2012-10-09 00:30:46 +00:00
helper.waitFor(function(){
2012-10-28 18:19:16 +00:00
console.log(inner$("div span").first().text());
return inner$("div span").first().text() === newString;
2012-10-09 00:30:46 +00:00
}).done(function(){
2012-10-28 18:19:16 +00:00
var finalValue = inner$("div").first().text();
2012-10-09 00:30:46 +00:00
expect(finalValue).to.be(modifiedValue); // expect the value to change
done();
});
});
it("redo some typing with keypress", function(done){
var inner$ = helper.padInner$;
var chrome$ = helper.padChrome$;
// get the first text element inside the editable space
var $firstTextElement = inner$("div span").first();
var originalValue = $firstTextElement.text(); // get the original value
var newString = "Foo";
$firstTextElement.sendkeys(newString); // send line 1 to the pad
var modifiedValue = $firstTextElement.text(); // get the modified value
expect(modifiedValue).not.to.be(originalValue); // expect the value to change
if(inner$(window)[0].bowser.firefox || inner$(window)[0].bowser.modernIE){ // if it's IE
2013-03-14 17:22:58 +00:00
var evtType = "keypress";
2013-03-14 17:36:54 +00:00
}else{
// Edge also requires keypress.
if(window.navigator.userAgent.indexOf("Edge") > -1){
var evtType = "keypress";
}else{
var evtType = "keydown";
}
}
var e = inner$.Event(evtType);
e.ctrlKey = true; // Control key
e.which = 90; // z
inner$("#innerdocbody").trigger(e);
2013-03-14 16:52:20 +00:00
var e = inner$.Event(evtType);
e.ctrlKey = true; // Control key
e.which = 121; // y
inner$("#innerdocbody").trigger(e);
helper.waitFor(function(){
console.log(inner$("div span").first().text());
return inner$("div span").first().text() === newString;
}).done(function(){
var finalValue = inner$("div").first().text();
expect(finalValue).to.be(modifiedValue); // expect the value to change
done();
});
});
2012-10-09 00:30:46 +00:00
});