From 62403159df4ceafc48da96d2c8cc6d2d6c60f772 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 31 Mar 2021 17:14:53 -0400 Subject: [PATCH] tests: Invert conditions to improve readability --- src/tests/frontend/helper/methods.js | 57 ++++++++++++---------------- src/tests/frontend/helper/ui.js | 24 +++++------- 2 files changed, 35 insertions(+), 46 deletions(-) diff --git a/src/tests/frontend/helper/methods.js b/src/tests/frontend/helper/methods.js index 4b039177..2cb6241f 100644 --- a/src/tests/frontend/helper/methods.js +++ b/src/tests/frontend/helper/methods.js @@ -6,14 +6,13 @@ */ helper.spyOnSocketIO = () => { helper.contentWindow().pad.socket.on('message', (msg) => { - if (msg.type === 'COLLABROOM') { - if (msg.data.type === 'ACCEPT_COMMIT') { - helper.commits.push(msg); - } else if (msg.data.type === 'USER_NEWINFO') { - helper.userInfos.push(msg); - } else if (msg.data.type === 'CHAT_MESSAGE') { - helper.chatMessages.push(msg); - } + if (msg.type !== 'COLLABROOM') return; + if (msg.data.type === 'ACCEPT_COMMIT') { + helper.commits.push(msg); + } else if (msg.data.type === 'USER_NEWINFO') { + helper.userInfos.push(msg); + } else if (msg.data.type === 'CHAT_MESSAGE') { + helper.chatMessages.push(msg); } }); }; @@ -93,10 +92,9 @@ helper.sendChatMessage = (message) => { * @returns {Promise} */ helper.showSettings = () => { - if (!helper.isSettingsShown()) { - helper.settingsButton().click(); - return helper.waitForPromise(() => helper.isSettingsShown(), 2000); - } + if (helper.isSettingsShown()) return; + helper.settingsButton().click(); + return helper.waitForPromise(() => helper.isSettingsShown(), 2000); }; /** @@ -106,10 +104,9 @@ helper.showSettings = () => { * @todo untested */ helper.hideSettings = () => { - if (helper.isSettingsShown()) { - helper.settingsButton().click(); - return helper.waitForPromise(() => !helper.isSettingsShown(), 2000); - } + if (!helper.isSettingsShown()) return; + helper.settingsButton().click(); + return helper.waitForPromise(() => !helper.isSettingsShown(), 2000); }; /** @@ -120,10 +117,9 @@ helper.hideSettings = () => { */ helper.enableStickyChatviaSettings = () => { const stickyChat = helper.padChrome$('#options-stickychat'); - if (helper.isSettingsShown() && !stickyChat.is(':checked')) { - stickyChat.click(); - return helper.waitForPromise(() => helper.isChatboxSticky(), 2000); - } + if (!helper.isSettingsShown() || stickyChat.is(':checked')) return; + stickyChat.click(); + return helper.waitForPromise(() => helper.isChatboxSticky(), 2000); }; /** @@ -134,10 +130,9 @@ helper.enableStickyChatviaSettings = () => { */ helper.disableStickyChatviaSettings = () => { const stickyChat = helper.padChrome$('#options-stickychat'); - if (helper.isSettingsShown() && stickyChat.is(':checked')) { - stickyChat.click(); - return helper.waitForPromise(() => !helper.isChatboxSticky(), 2000); - } + if (!helper.isSettingsShown() || !stickyChat.is(':checked')) return; + stickyChat.click(); + return helper.waitForPromise(() => !helper.isChatboxSticky(), 2000); }; /** @@ -148,10 +143,9 @@ helper.disableStickyChatviaSettings = () => { */ helper.enableStickyChatviaIcon = () => { const stickyChat = helper.padChrome$('#titlesticky'); - if (helper.isChatboxShown() && !helper.isChatboxSticky()) { - stickyChat.click(); - return helper.waitForPromise(() => helper.isChatboxSticky(), 2000); - } + if (!helper.isChatboxShown() || helper.isChatboxSticky()) return; + stickyChat.click(); + return helper.waitForPromise(() => helper.isChatboxSticky(), 2000); }; /** @@ -161,10 +155,9 @@ helper.enableStickyChatviaIcon = () => { * @returns {Promise} */ helper.disableStickyChatviaIcon = () => { - if (helper.isChatboxShown() && helper.isChatboxSticky()) { - helper.titlecross().click(); - return helper.waitForPromise(() => !helper.isChatboxSticky(), 2000); - } + if (!helper.isChatboxShown() || !helper.isChatboxSticky()) return; + helper.titlecross().click(); + return helper.waitForPromise(() => !helper.isChatboxSticky(), 2000); }; /** diff --git a/src/tests/frontend/helper/ui.js b/src/tests/frontend/helper/ui.js index 84d00589..86bfdd32 100644 --- a/src/tests/frontend/helper/ui.js +++ b/src/tests/frontend/helper/ui.js @@ -15,10 +15,9 @@ helper.contentWindow = () => $('#iframe-container iframe')[0].contentWindow; */ helper.showChat = () => { const chaticon = helper.chatIcon(); - if (chaticon.hasClass('visible')) { - chaticon.click(); - return helper.waitForPromise(() => !chaticon.hasClass('visible'), 2000); - } + if (!chaticon.hasClass('visible')) return; + chaticon.click(); + return helper.waitForPromise(() => !chaticon.hasClass('visible'), 2000); }; /** @@ -27,10 +26,9 @@ helper.showChat = () => { * @returns {Promise} */ helper.hideChat = () => { - if (helper.isChatboxShown() && !helper.isChatboxSticky()) { - helper.titlecross().click(); - return helper.waitForPromise(() => !helper.isChatboxShown(), 2000); - } + if (!helper.isChatboxShown() || helper.isChatboxSticky()) return; + helper.titlecross().click(); + return helper.waitForPromise(() => !helper.isChatboxShown(), 2000); }; /** @@ -132,9 +130,8 @@ helper.isSettingsShown = () => helper.padChrome$('#settings').hasClass('popup-sh * @returns {HTMLElement} timer */ helper.timesliderTimer = () => { - if (typeof helper.contentWindow().$ === 'function') { - return helper.contentWindow().$('#timer'); - } + if (typeof helper.contentWindow().$ !== 'function') return; + return helper.contentWindow().$('#timer'); }; /** @@ -143,9 +140,8 @@ helper.timesliderTimer = () => { * @returns {HTMLElement} timer */ helper.timesliderTimerTime = () => { - if (helper.timesliderTimer()) { - return helper.timesliderTimer().text(); - } + if (!helper.timesliderTimer()) return; + return helper.timesliderTimer().text(); }; /**