lint: src/tests/frontend/helper.js and friends

This commit is contained in:
Richard Hansen 2021-02-13 00:41:01 -05:00
parent 8f2f6593be
commit eb9d5bb470
3 changed files with 60 additions and 86 deletions

View file

@ -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 () {
return $(this).text();
}).get();
};
helper.timesliderTextLines = () => helper.contentWindow().$('.ace-line').map(function () {
return $(this).text();
}).get();
helper.padIsEmpty = () => (
!helper.padInner$.document.getSelection().isCollapsed ||

View file

@ -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');