diff --git a/tests/frontend/helper.js b/tests/frontend/helper.js index 7a8d19b60..800dfb293 100644 --- a/tests/frontend/helper.js +++ b/tests/frontend/helper.js @@ -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); } -})() \ No newline at end of file +})() diff --git a/tests/frontend/specs/bold.js b/tests/frontend/specs/bold.js index 2d77d1680..94e3a9b5b 100644 --- a/tests/frontend/specs/bold.js +++ b/tests/frontend/specs/bold.js @@ -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); diff --git a/tests/frontend/specs/caret.js b/tests/frontend/specs/caret.js index e35ad0e9a..45c2eb3be 100644 --- a/tests/frontend/specs/caret.js +++ b/tests/frontend/specs/caret.js @@ -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 } diff --git a/tests/frontend/specs/indentation.js b/tests/frontend/specs/indentation.js index 1b9732ef3..2173f9e07 100644 --- a/tests/frontend/specs/indentation.js +++ b/tests/frontend/specs/indentation.js @@ -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); } diff --git a/tests/frontend/specs/italic.js b/tests/frontend/specs/italic.js index b56887ea9..3c62e00e8 100644 --- a/tests/frontend/specs/italic.js +++ b/tests/frontend/specs/italic.js @@ -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); diff --git a/tests/frontend/specs/ordered_list.js b/tests/frontend/specs/ordered_list.js index ec9694904..f4aa57273 100644 --- a/tests/frontend/specs/ordered_list.js +++ b/tests/frontend/specs/ordered_list.js @@ -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); diff --git a/tests/frontend/specs/redo.js b/tests/frontend/specs/redo.js index 63406c3b6..4f7c43f1e 100644 --- a/tests/frontend/specs/redo.js +++ b/tests/frontend/specs/redo.js @@ -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); diff --git a/tests/frontend/specs/scroll.js b/tests/frontend/specs/scroll.js index 2c46cdfba..3d88b0445 100644 --- a/tests/frontend/specs/scroll.js +++ b/tests/frontend/specs/scroll.js @@ -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' diff --git a/tests/frontend/specs/select_formatting_buttons.js b/tests/frontend/specs/select_formatting_buttons.js index 15b17da04..572858957 100644 --- a/tests/frontend/specs/select_formatting_buttons.js +++ b/tests/frontend/specs/select_formatting_buttons.js @@ -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); diff --git a/tests/frontend/specs/undo.js b/tests/frontend/specs/undo.js index b41a895c2..172a2b81e 100644 --- a/tests/frontend/specs/undo.js +++ b/tests/frontend/specs/undo.js @@ -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);