lint: `src/tests/frontend/helper.js` and friends
parent
8f2f6593be
commit
eb9d5bb470
|
@ -2,11 +2,11 @@
|
|||
|
||||
const helper = {}; // eslint-disable-line no-redeclare
|
||||
|
||||
(function () {
|
||||
let $iframe; const
|
||||
jsLibraries = {};
|
||||
(() => {
|
||||
let $iframe;
|
||||
const jsLibraries = {};
|
||||
|
||||
helper.init = function (cb) {
|
||||
helper.init = (cb) => {
|
||||
$.get('/static/js/jquery.js').done((code) => {
|
||||
// make sure we don't override existing jquery
|
||||
jsLibraries.jquery = `if(typeof $ === 'undefined') {\n${code}\n}`;
|
||||
|
@ -19,7 +19,7 @@ const helper = {}; // eslint-disable-line no-redeclare
|
|||
});
|
||||
};
|
||||
|
||||
helper.randomString = function randomString(len) {
|
||||
helper.randomString = (len) => {
|
||||
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
||||
let randomstring = '';
|
||||
for (let i = 0; i < len; i++) {
|
||||
|
@ -29,7 +29,7 @@ const helper = {}; // eslint-disable-line no-redeclare
|
|||
return randomstring;
|
||||
};
|
||||
|
||||
const getFrameJQuery = function ($iframe) {
|
||||
const getFrameJQuery = ($iframe) => {
|
||||
/*
|
||||
I tried over 9001 ways to inject javascript into iframes.
|
||||
This is the only way I found that worked in IE 7+8+9, FF and Chrome
|
||||
|
@ -38,7 +38,7 @@ const helper = {}; // eslint-disable-line no-redeclare
|
|||
const doc = win.document;
|
||||
|
||||
// IE 8+9 Hack to make eval appear
|
||||
// http://stackoverflow.com/questions/2720444/why-does-this-window-object-not-have-the-eval-function
|
||||
// https://stackoverflow.com/q/2720444
|
||||
win.execScript && win.execScript('null');
|
||||
|
||||
win.eval(jsLibraries.jquery);
|
||||
|
@ -50,15 +50,15 @@ const helper = {}; // eslint-disable-line no-redeclare
|
|||
return win.$;
|
||||
};
|
||||
|
||||
helper.clearSessionCookies = function () {
|
||||
// Expire cookies, so author and language are changed after reloading the pad.
|
||||
// See https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#Example_4_Reset_the_previous_cookie
|
||||
helper.clearSessionCookies = () => {
|
||||
// Expire cookies, so author and language are changed after reloading the pad. See:
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#example_4_reset_the_previous_cookie
|
||||
window.document.cookie = 'token=;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
|
||||
window.document.cookie = 'language=;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
|
||||
};
|
||||
|
||||
// Can only happen when the iframe exists, so we're doing it separately from other cookies
|
||||
helper.clearPadPrefCookie = function () {
|
||||
helper.clearPadPrefCookie = () => {
|
||||
helper.padChrome$.document.cookie = 'prefsHttp=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
|
||||
};
|
||||
|
||||
|
@ -68,7 +68,7 @@ const helper = {}; // eslint-disable-line no-redeclare
|
|||
// seem to have independent cookies, UNLESS we put path=/ here (which we don't).
|
||||
// I don't fully understand it, but this function seems to properly simulate
|
||||
// padCookie.setPref in the client code
|
||||
helper.setPadPrefCookie = function (prefs) {
|
||||
helper.setPadPrefCookie = (prefs) => {
|
||||
helper.padChrome$.document.cookie =
|
||||
(`prefsHttp=${escape(JSON.stringify(prefs))};expires=Thu, 01 Jan 3000 00:00:00 GMT`);
|
||||
};
|
||||
|
@ -94,7 +94,7 @@ const helper = {}; // eslint-disable-line no-redeclare
|
|||
// This ensures that tests run regardless of this problem
|
||||
helper.retry = 0;
|
||||
|
||||
helper.newPad = function (cb, padName) {
|
||||
helper.newPad = (cb, padName) => {
|
||||
// build opts object
|
||||
let opts = {clearCookies: true};
|
||||
if (typeof cb === 'function') {
|
||||
|
@ -181,7 +181,7 @@ const helper = {}; // eslint-disable-line no-redeclare
|
|||
return padName;
|
||||
};
|
||||
|
||||
helper.newAdmin = async function (page) {
|
||||
helper.newAdmin = async (page) => {
|
||||
// define the iframe
|
||||
$iframe = $(`<iframe src='/admin/${page}'></iframe>`);
|
||||
|
||||
|
@ -197,7 +197,7 @@ const helper = {}; // eslint-disable-line no-redeclare
|
|||
});
|
||||
};
|
||||
|
||||
helper.waitFor = function (conditionFunc, timeoutTime = 1900, intervalTime = 10) {
|
||||
helper.waitFor = (conditionFunc, timeoutTime = 1900, intervalTime = 10) => {
|
||||
const deferred = new $.Deferred();
|
||||
|
||||
const _fail = deferred.fail.bind(deferred);
|
||||
|
@ -242,14 +242,12 @@ const helper = {}; // eslint-disable-line no-redeclare
|
|||
* @returns {Promise}
|
||||
*
|
||||
*/
|
||||
helper.waitForPromise = async function (...args) {
|
||||
// Note: waitFor() has a strange API: On timeout it rejects, but it also throws an uncatchable
|
||||
// exception unless .fail() has been called. That uncatchable exception is disabled here by
|
||||
// passing a no-op function to .fail().
|
||||
return await this.waitFor(...args).fail(() => {});
|
||||
};
|
||||
helper.waitForPromise = async (...args) => await helper.waitFor(...args).fail(() => {});
|
||||
|
||||
helper.selectLines = function ($startLine, $endLine, startOffset, endOffset) {
|
||||
helper.selectLines = ($startLine, $endLine, startOffset, endOffset) => {
|
||||
// if no offset is provided, use beginning of start line and end of end line
|
||||
startOffset = startOffset || 0;
|
||||
endOffset = endOffset === undefined ? $endLine.text().length : endOffset;
|
||||
|
@ -268,7 +266,7 @@ const helper = {}; // eslint-disable-line no-redeclare
|
|||
selection.addRange(range);
|
||||
};
|
||||
|
||||
const getTextNodeAndOffsetOf = function ($targetLine, targetOffsetAtLine) {
|
||||
const getTextNodeAndOffsetOf = ($targetLine, targetOffsetAtLine) => {
|
||||
const $textNodes = $targetLine.find('*').contents().filter(function () {
|
||||
return this.nodeType === Node.TEXT_NODE;
|
||||
});
|
||||
|
@ -310,5 +308,5 @@ const helper = {}; // eslint-disable-line no-redeclare
|
|||
|
||||
/* Ensure console.log doesn't blow up in IE, ugly but ok for a test framework imho*/
|
||||
window.console = window.console || {};
|
||||
window.console.log = window.console.log || function () {};
|
||||
window.console.log = window.console.log || (() => {});
|
||||
})();
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* Spys on socket.io messages and saves them into several arrays
|
||||
* that are visible in tests
|
||||
*/
|
||||
helper.spyOnSocketIO = function () {
|
||||
helper.spyOnSocketIO = () => {
|
||||
helper.contentWindow().pad.socket.on('message', (msg) => {
|
||||
if (msg.type === 'COLLABROOM') {
|
||||
if (msg.data.type === 'ACCEPT_COMMIT') {
|
||||
|
@ -30,7 +30,7 @@ helper.spyOnSocketIO = function () {
|
|||
* @todo needs to support writing to a specified caret position
|
||||
*
|
||||
*/
|
||||
helper.edit = async function (message, line) {
|
||||
helper.edit = async (message, line) => {
|
||||
const editsNum = helper.commits.length;
|
||||
line = line ? line - 1 : 0;
|
||||
helper.linesDiv()[line].sendkeys(message);
|
||||
|
@ -45,7 +45,7 @@ helper.edit = async function (message, line) {
|
|||
*
|
||||
* @returns {Array.<HTMLElement>} array of divs
|
||||
*/
|
||||
helper.linesDiv = function () {
|
||||
helper.linesDiv = () => {
|
||||
return helper.padInner$('.ace-line').map(function () {
|
||||
return $(this);
|
||||
}).get();
|
||||
|
@ -57,18 +57,15 @@ helper.linesDiv = function () {
|
|||
*
|
||||
* @returns {Array.<string>} lines of text
|
||||
*/
|
||||
helper.textLines = function () {
|
||||
return helper.linesDiv().map((div) => div.text());
|
||||
};
|
||||
helper.textLines = () => helper.linesDiv().map((div) => div.text());
|
||||
|
||||
/**
|
||||
* The default pad text transmitted via `clientVars`
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
helper.defaultText = function () {
|
||||
return helper.padChrome$.window.clientVars.collab_client_vars.initialAttributedText.text;
|
||||
};
|
||||
helper.defaultText =
|
||||
() => helper.padChrome$.window.clientVars.collab_client_vars.initialAttributedText.text;
|
||||
|
||||
/**
|
||||
* Sends a chat `message` via `sendKeys`
|
||||
|
@ -84,7 +81,7 @@ helper.defaultText = function () {
|
|||
* @param {string} message the chat message to be sent
|
||||
* @returns {Promise}
|
||||
*/
|
||||
helper.sendChatMessage = function (message) {
|
||||
helper.sendChatMessage = (message) => {
|
||||
const noOfChatMessages = helper.chatMessages.length;
|
||||
helper.padChrome$('#chatinput').sendkeys(message);
|
||||
return helper.waitForPromise(() => noOfChatMessages + 1 === helper.chatMessages.length);
|
||||
|
@ -95,7 +92,7 @@ helper.sendChatMessage = function (message) {
|
|||
*
|
||||
* @returns {Promise}
|
||||
*/
|
||||
helper.showSettings = function () {
|
||||
helper.showSettings = () => {
|
||||
if (!helper.isSettingsShown()) {
|
||||
helper.settingsButton().click();
|
||||
return helper.waitForPromise(() => helper.isSettingsShown(), 2000);
|
||||
|
@ -108,7 +105,7 @@ helper.showSettings = function () {
|
|||
* @returns {Promise}
|
||||
* @todo untested
|
||||
*/
|
||||
helper.hideSettings = function () {
|
||||
helper.hideSettings = () => {
|
||||
if (helper.isSettingsShown()) {
|
||||
helper.settingsButton().click();
|
||||
return helper.waitForPromise(() => !helper.isSettingsShown(), 2000);
|
||||
|
@ -121,7 +118,7 @@ helper.hideSettings = function () {
|
|||
*
|
||||
* @returns {Promise}
|
||||
*/
|
||||
helper.enableStickyChatviaSettings = function () {
|
||||
helper.enableStickyChatviaSettings = () => {
|
||||
const stickyChat = helper.padChrome$('#options-stickychat');
|
||||
if (helper.isSettingsShown() && !stickyChat.is(':checked')) {
|
||||
stickyChat.click();
|
||||
|
@ -135,7 +132,7 @@ helper.enableStickyChatviaSettings = function () {
|
|||
*
|
||||
* @returns {Promise}
|
||||
*/
|
||||
helper.disableStickyChatviaSettings = function () {
|
||||
helper.disableStickyChatviaSettings = () => {
|
||||
const stickyChat = helper.padChrome$('#options-stickychat');
|
||||
if (helper.isSettingsShown() && stickyChat.is(':checked')) {
|
||||
stickyChat.click();
|
||||
|
@ -149,7 +146,7 @@ helper.disableStickyChatviaSettings = function () {
|
|||
*
|
||||
* @returns {Promise}
|
||||
*/
|
||||
helper.enableStickyChatviaIcon = function () {
|
||||
helper.enableStickyChatviaIcon = () => {
|
||||
const stickyChat = helper.padChrome$('#titlesticky');
|
||||
if (helper.isChatboxShown() && !helper.isChatboxSticky()) {
|
||||
stickyChat.click();
|
||||
|
@ -163,7 +160,7 @@ helper.enableStickyChatviaIcon = function () {
|
|||
*
|
||||
* @returns {Promise}
|
||||
*/
|
||||
helper.disableStickyChatviaIcon = function () {
|
||||
helper.disableStickyChatviaIcon = () => {
|
||||
if (helper.isChatboxShown() && helper.isChatboxSticky()) {
|
||||
helper.titlecross().click();
|
||||
return helper.waitForPromise(() => !helper.isChatboxSticky(), 2000);
|
||||
|
@ -182,7 +179,7 @@ helper.disableStickyChatviaIcon = function () {
|
|||
* @todo for some reason this does only work the first time, you cannot
|
||||
* goto rev 0 and then via the same method to rev 5. Use buttons instead
|
||||
*/
|
||||
helper.gotoTimeslider = function (revision) {
|
||||
helper.gotoTimeslider = (revision) => {
|
||||
revision = Number.isInteger(revision) ? `#${revision}` : '';
|
||||
const iframe = $('#iframe-container iframe');
|
||||
iframe.attr('src', `${iframe.attr('src')}/timeslider${revision}`);
|
||||
|
@ -198,7 +195,7 @@ helper.gotoTimeslider = function (revision) {
|
|||
* @todo no mousemove test
|
||||
* @param {number} X coordinate
|
||||
*/
|
||||
helper.sliderClick = function (X) {
|
||||
helper.sliderClick = (X) => {
|
||||
const sliderBar = helper.sliderBar();
|
||||
const edown = new jQuery.Event('mousedown');
|
||||
const eup = new jQuery.Event('mouseup');
|
||||
|
@ -214,11 +211,9 @@ helper.sliderClick = function (X) {
|
|||
*
|
||||
* @returns {Array.<string>} lines of text
|
||||
*/
|
||||
helper.timesliderTextLines = function () {
|
||||
return helper.contentWindow().$('.ace-line').map(function () {
|
||||
helper.timesliderTextLines = () => helper.contentWindow().$('.ace-line').map(function () {
|
||||
return $(this).text();
|
||||
}).get();
|
||||
};
|
||||
|
||||
helper.padIsEmpty = () => (
|
||||
!helper.padInner$.document.getSelection().isCollapsed ||
|
||||
|
|
|
@ -5,9 +5,7 @@
|
|||
*
|
||||
* @returns {HTMLElement} contentWindow
|
||||
*/
|
||||
helper.contentWindow = function () {
|
||||
return $('#iframe-container iframe')[0].contentWindow;
|
||||
};
|
||||
helper.contentWindow = () => $('#iframe-container iframe')[0].contentWindow;
|
||||
|
||||
/**
|
||||
* Opens the chat unless it is already open via an
|
||||
|
@ -15,7 +13,7 @@ helper.contentWindow = function () {
|
|||
*
|
||||
* @returns {Promise}
|
||||
*/
|
||||
helper.showChat = function () {
|
||||
helper.showChat = () => {
|
||||
const chaticon = helper.chatIcon();
|
||||
if (chaticon.hasClass('visible')) {
|
||||
chaticon.click();
|
||||
|
@ -28,7 +26,7 @@ helper.showChat = function () {
|
|||
*
|
||||
* @returns {Promise}
|
||||
*/
|
||||
helper.hideChat = function () {
|
||||
helper.hideChat = () => {
|
||||
if (helper.isChatboxShown() && !helper.isChatboxSticky()) {
|
||||
helper.titlecross().click();
|
||||
return helper.waitForPromise(() => !helper.isChatboxShown(), 2000);
|
||||
|
@ -40,53 +38,48 @@ helper.hideChat = function () {
|
|||
*
|
||||
* @returns {HTMLElement} the chat icon
|
||||
*/
|
||||
helper.chatIcon = function () { return helper.padChrome$('#chaticon'); };
|
||||
helper.chatIcon = () => helper.padChrome$('#chaticon');
|
||||
|
||||
/**
|
||||
* The chat messages from the UI
|
||||
*
|
||||
* @returns {Array.<HTMLElement>}
|
||||
*/
|
||||
helper.chatTextParagraphs = function () { return helper.padChrome$('#chattext').children('p'); };
|
||||
helper.chatTextParagraphs = () => helper.padChrome$('#chattext').children('p');
|
||||
|
||||
/**
|
||||
* Returns true if the chat box is sticky
|
||||
*
|
||||
* @returns {boolean} stickyness of the chat box
|
||||
*/
|
||||
helper.isChatboxSticky = function () {
|
||||
return helper.padChrome$('#chatbox').hasClass('stickyChat');
|
||||
};
|
||||
helper.isChatboxSticky = () => helper.padChrome$('#chatbox').hasClass('stickyChat');
|
||||
|
||||
/**
|
||||
* Returns true if the chat box is shown
|
||||
*
|
||||
* @returns {boolean} visibility of the chat box
|
||||
*/
|
||||
helper.isChatboxShown = function () {
|
||||
return helper.padChrome$('#chatbox').hasClass('visible');
|
||||
};
|
||||
helper.isChatboxShown = () => helper.padChrome$('#chatbox').hasClass('visible');
|
||||
|
||||
/**
|
||||
* Gets the settings menu
|
||||
*
|
||||
* @returns {HTMLElement} the settings menu
|
||||
*/
|
||||
helper.settingsMenu = function () { return helper.padChrome$('#settings'); };
|
||||
helper.settingsMenu = () => helper.padChrome$('#settings');
|
||||
|
||||
/**
|
||||
* Gets the settings button
|
||||
*
|
||||
* @returns {HTMLElement} the settings button
|
||||
*/
|
||||
helper.settingsButton = function () {
|
||||
return helper.padChrome$("button[data-l10n-id='pad.toolbar.settings.title']");
|
||||
};
|
||||
helper.settingsButton =
|
||||
() => helper.padChrome$("button[data-l10n-id='pad.toolbar.settings.title']");
|
||||
|
||||
/**
|
||||
* Toggles user list
|
||||
*/
|
||||
helper.toggleUserList = async function () {
|
||||
helper.toggleUserList = async () => {
|
||||
const isVisible = helper.userListShown();
|
||||
const button = helper.padChrome$("button[data-l10n-id='pad.toolbar.showusers.title']");
|
||||
button.click();
|
||||
|
@ -98,18 +91,14 @@ helper.toggleUserList = async function () {
|
|||
*
|
||||
* @returns {HTMLElement} user name input field
|
||||
*/
|
||||
helper.usernameField = function () {
|
||||
return helper.padChrome$("input[data-l10n-id='pad.userlist.entername']");
|
||||
};
|
||||
helper.usernameField = () => helper.padChrome$("input[data-l10n-id='pad.userlist.entername']");
|
||||
|
||||
/**
|
||||
* Is the user list popup shown?
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
helper.userListShown = function () {
|
||||
return helper.padChrome$('div#users').hasClass('popup-show');
|
||||
};
|
||||
helper.userListShown = () => helper.padChrome$('div#users').hasClass('popup-show');
|
||||
|
||||
/**
|
||||
* Sets the user name
|
||||
|
@ -128,23 +117,21 @@ helper.setUserName = async (name) => {
|
|||
*
|
||||
* @returns {HTMLElement} the titlecross icon
|
||||
*/
|
||||
helper.titlecross = function () { return helper.padChrome$('#titlecross'); };
|
||||
helper.titlecross = () => helper.padChrome$('#titlecross');
|
||||
|
||||
/**
|
||||
* Returns true if the settings menu is visible
|
||||
*
|
||||
* @returns {boolean} is the settings menu shown?
|
||||
*/
|
||||
helper.isSettingsShown = function () {
|
||||
return helper.padChrome$('#settings').hasClass('popup-show');
|
||||
};
|
||||
helper.isSettingsShown = () => helper.padChrome$('#settings').hasClass('popup-show');
|
||||
|
||||
/**
|
||||
* Gets the timer div of a timeslider that has the datetime of the revision
|
||||
*
|
||||
* @returns {HTMLElement} timer
|
||||
*/
|
||||
helper.timesliderTimer = function () {
|
||||
helper.timesliderTimer = () => {
|
||||
if (typeof helper.contentWindow().$ === 'function') {
|
||||
return helper.contentWindow().$('#timer');
|
||||
}
|
||||
|
@ -155,7 +142,7 @@ helper.timesliderTimer = function () {
|
|||
*
|
||||
* @returns {HTMLElement} timer
|
||||
*/
|
||||
helper.timesliderTimerTime = function () {
|
||||
helper.timesliderTimerTime = () => {
|
||||
if (helper.timesliderTimer()) {
|
||||
return helper.timesliderTimer().text();
|
||||
}
|
||||
|
@ -166,9 +153,7 @@ helper.timesliderTimerTime = function () {
|
|||
*
|
||||
* @returns {HTMLElement}
|
||||
*/
|
||||
helper.sliderBar = function () {
|
||||
return helper.contentWindow().$('#ui-slider-bar');
|
||||
};
|
||||
helper.sliderBar = () => helper.contentWindow().$('#ui-slider-bar');
|
||||
|
||||
/**
|
||||
* revision_date element
|
||||
|
@ -176,9 +161,7 @@ helper.sliderBar = function () {
|
|||
*
|
||||
* @returns {HTMLElement}
|
||||
*/
|
||||
helper.revisionDateElem = function () {
|
||||
return helper.contentWindow().$('#revision_date').text();
|
||||
};
|
||||
helper.revisionDateElem = () => helper.contentWindow().$('#revision_date').text();
|
||||
|
||||
/**
|
||||
* revision_label element
|
||||
|
@ -186,6 +169,4 @@ helper.revisionDateElem = function () {
|
|||
*
|
||||
* @returns {HTMLElement}
|
||||
*/
|
||||
helper.revisionLabelElem = function () {
|
||||
return helper.contentWindow().$('#revision_label');
|
||||
};
|
||||
helper.revisionLabelElem = () => helper.contentWindow().$('#revision_label');
|
||||
|
|
Loading…
Reference in New Issue