tests: use helper for evttype to reduce duplicate code

This commit is contained in:
John McLear 2020-03-23 10:53:58 +00:00 committed by muxator
parent be9afc7955
commit 675c839d92
10 changed files with 27 additions and 117 deletions

View File

@ -56,6 +56,22 @@ var helper = {};
window.document.cookie = "";
}
// Functionality for knowing what key event type is required for tests
var evtType = "keydown";
// if it's IE require keypress
if(window.navigator.userAgent.indexOf("MSIE") > -1){
evtType = "keypress";
}
// Edge also requires keypress.
if(window.navigator.userAgent.indexOf("Edge") > -1){
evtType = "keypress";
}
// Opera also requires keypress.
if(window.navigator.userAgent.indexOf("OPR") > -1){
evtType = "keypress";
}
helper.evtType = evtType;
helper.newPad = function(cb, padName){
//build opts object
var opts = {clearCookies: true}
@ -216,4 +232,4 @@ var helper = {};
_it(name, func);
}
})()
})()

View File

@ -44,18 +44,7 @@ describe("bold button", function(){
//select this text element
$firstTextElement.sendkeys('{selectall}');
if(inner$(window)[0].bowser.modernIE){ // if it's IE
var evtType = "keypress";
}else{
// Edge also requires keypress.
if(window.navigator.userAgent.indexOf("Edge") > -1){
var evtType = "keypress";
}else{
var evtType = "keydown";
}
}
var e = inner$.Event(evtType);
var e = inner$.Event(helper.evtType);
e.ctrlKey = true; // Control key
e.which = 66; // b
inner$("#innerdocbody").trigger(e);

View File

@ -297,20 +297,8 @@ function prepareDocument(n, target){ // generates a random document with random
}
function keyEvent(target, charCode, ctrl, shift){ // sends a charCode to the window
if(inner$(window)[0].bowser.firefox || inner$(window)[0].bowser.modernIE){ // if it's IE
var evtType = "keypress";
}else{
// Edge also requires keypress.
if(window.navigator.userAgent.indexOf("Edge") > -1){
var evtType = "keypress";
}else{
var evtType = "keydown";
}
}
var e = target.Event(evtType);
console.log(e);
var e = target.Event(helper.evtType);
if(ctrl){
e.ctrlKey = true; // Control key
}

View File

@ -15,18 +15,7 @@ describe("indentation button", function(){
//select this text element
$firstTextElement.sendkeys('{selectall}');
if(inner$(window)[0].bowser.modernIE){ // if it's IE
var evtType = "keypress";
}else{
// Edge also requires keypress.
if(window.navigator.userAgent.indexOf("Edge") > -1){
var evtType = "keypress";
}else{
var evtType = "keydown";
}
}
var e = inner$.Event(evtType);
var e = inner$.Event(helper.evtType);
e.keyCode = 9; // tab :|
inner$("#innerdocbody").trigger(e);
@ -330,12 +319,7 @@ describe("indentation button", function(){
function pressEnter(){
var inner$ = helper.padInner$;
if(inner$(window)[0].bowser.modernIE){ // if it's IE
var evtType = "keypress";
}else{
var evtType = "keydown";
}
var e = inner$.Event(evtType);
var e = inner$.Event(helper.evtType);
e.keyCode = 13; // enter :|
inner$("#innerdocbody").trigger(e);
}

View File

@ -44,18 +44,7 @@ describe("italic some text", function(){
//select this text element
$firstTextElement.sendkeys('{selectall}');
if(inner$(window)[0].bowser.modernIE){ // if it's IE
var evtType = "keypress";
}else{
// Edge also requires keypress.
if(window.navigator.userAgent.indexOf("Edge") > -1){
var evtType = "keypress";
}else{
var evtType = "keydown";
}
}
var e = inner$.Event(evtType);
var e = inner$.Event(helper.evtType);
e.ctrlKey = true; // Control key
e.which = 105; // i
inner$("#innerdocbody").trigger(e);

View File

@ -111,17 +111,7 @@ describe("assign ordered list", function(){
var triggerCtrlShiftShortcut = function(shortcutChar) {
var inner$ = helper.padInner$;
if(inner$(window)[0].bowser.modernIE){ // if it's IE
var evtType = "keypress";
}else{
// Edge also requires keypress.
if(window.navigator.userAgent.indexOf("Edge") > -1){
var evtType = "keypress";
}else{
var evtType = "keydown";
}
}
var e = inner$.Event(evtType);
var e = inner$.Event(helper.evtType);
e.ctrlKey = true;
e.shiftKey = true;
e.which = shortcutChar.toString().charCodeAt(0);

View File

@ -47,18 +47,7 @@ describe("undo button then redo button", function(){
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
var evtType = "keypress";
}else{
// Edge also requires keypress.
if(window.navigator.userAgent.indexOf("Edge") > -1){
var evtType = "keypress";
}else{
var evtType = "keydown";
}
}
var e = inner$.Event(evtType);
var e = inner$.Event(helper.evtType);
e.ctrlKey = true; // Control key
e.which = 90; // z
inner$("#innerdocbody").trigger(e);

View File

@ -512,20 +512,7 @@ describe('scroll when focus line is out of viewport', function () {
var pressKey = function(keyCode, shiftIsPressed){
var inner$ = helper.padInner$;
var evtType;
if(inner$(window)[0].bowser.modernIE){ // if it's IE
var evtType = "keypress";
}else{
// Edge also requires keypress.
if(window.navigator.userAgent.indexOf("Edge") > -1){
var evtType = "keypress";
}else{
var evtType = "keydown";
}
}
var e = inner$.Event(evtType);
var e = inner$.Event(helper.evtType);
e.shiftKey = shiftIsPressed;
e.keyCode = keyCode;
e.which = keyCode; // etherpad listens to 'which'

View File

@ -88,18 +88,7 @@ describe("select formatting buttons when selection has style applied", function(
//select this text element
$firstTextElement.sendkeys('{selectall}');
if(inner$(window)[0].bowser.modernIE){ // if it's IE
var evtType = "keypress";
}else{
// Edge also requires keypress.
if(window.navigator.userAgent.indexOf("Edge") > -1){
var evtType = "keypress";
}else{
var evtType = "keydown";
}
}
var e = inner$.Event(evtType);
var e = inner$.Event(helper.evtType);
e.ctrlKey = true; // Control key
e.which = key.charCodeAt(0); // I, U, B, 5
inner$("#innerdocbody").trigger(e);

View File

@ -42,18 +42,7 @@ describe("undo button", function(){
var modifiedValue = $firstTextElement.text(); // get the modified value
expect(modifiedValue).not.to.be(originalValue); // expect the value to change
if(inner$(window)[0].bowser.modernIE){ // if it's IE
var evtType = "keypress";
}else{
// Edge also requires keypress.
if(window.navigator.userAgent.indexOf("Edge") > -1){
var evtType = "keypress";
}else{
var evtType = "keydown";
}
}
var e = inner$.Event(evtType);
var e = inner$.Event(helper.evtType);
e.ctrlKey = true; // Control key
e.which = 90; // z
inner$("#innerdocbody").trigger(e);