From c90ad1768611b2f12315a18fc526725c3903a821 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Fri, 14 Dec 2018 00:25:12 -0800 Subject: [PATCH] fix: logging out results in visible homescreen (#807) * fix: logging out results in visible homescreen fixes #805 * fixup --- inline-script.js | 15 +++++++++++---- src/template.html | 2 +- tests/spec/002-login-spec.js | 22 ++++++++++++++++++---- tests/utils.js | 6 ++++++ 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/inline-script.js b/inline-script.js index 2b97cd21..0646e848 100644 --- a/inline-script.js +++ b/inline-script.js @@ -1,3 +1,4 @@ + // For perf reasons, this script is run inline to quickly set certain styles. // To allow CSP to work correctly, we also calculate a sha256 hash during // the build process and write it to inline-script-checksum.json. @@ -7,17 +8,23 @@ import { switchToTheme } from './src/routes/_utils/themeEngine' window.__themeColors = process.env.THEME_COLORS -const hasLocalStorage = testHasLocalStorageOnce() +function safeParse (str) { + return str === 'undefined' ? undefined : JSON.parse(str) +} -if (hasLocalStorage && localStorage.store_currentInstance && localStorage.store_instanceThemes) { - let safeParse = (str) => str === 'undefined' ? undefined : JSON.parse(str) +const hasLocalStorage = testHasLocalStorageOnce() +const currentInstance = hasLocalStorage && + localStorage.store_currentInstance && + safeParse(localStorage.store_currentInstance) + +if (currentInstance && localStorage.store_instanceThemes) { let theme = safeParse(localStorage.store_instanceThemes)[safeParse(localStorage.store_currentInstance)] if (theme && theme !== 'default') { switchToTheme(theme) } } -if (!hasLocalStorage || !localStorage.store_currentInstance) { +if (!hasLocalStorage || !currentInstance) { // if not logged in, show all these 'hidden-from-ssr' elements let style = document.createElement('style') style.textContent = '.hidden-from-ssr { opacity: 1 !important; }' diff --git a/src/template.html b/src/template.html index 48f8b3ac..4fa8c995 100644 --- a/src/template.html +++ b/src/template.html @@ -48,7 +48,7 @@ html{scrollbar-face-color:var(--scrollbar-face-color);scrollbar-track-color:var( - diff --git a/tests/spec/002-login-spec.js b/tests/spec/002-login-spec.js index efefab0f..47312d7a 100644 --- a/tests/spec/002-login-spec.js +++ b/tests/spec/002-login-spec.js @@ -1,9 +1,16 @@ import { Selector as $ } from 'testcafe' import { addInstanceButton, - authorizeInput, emailInput, formError, getFirstVisibleStatus, getUrl, instanceInput, logInToInstanceLink, + authorizeInput, + emailInput, + formError, + getFirstVisibleStatus, getOpacity, + getUrl, + homeNavButton, + instanceInput, + logInToInstanceLink, mastodonLogInButton, - passwordInput, + passwordInput, reload, settingsButton, sleep } from '../utils' @@ -55,6 +62,13 @@ test('Logs in and logs out of localhost:3000', async t => { .expect($('.acct-display-name').innerText).eql('foobar') .click($('button').withText('Log out')) .click($('.modal-dialog button').withText('OK')) - .expect($('.main-content').innerText) - .contains("You're not logged in to any instances") + .expect($('.main-content').innerText).contains("You're not logged in to any instances") + .click(homeNavButton) + // check that the "hidden from SSR" content is visible + .expect(getOpacity('.hidden-from-ssr')()).eql('1') + .navigateTo('/') + .expect(getOpacity('.hidden-from-ssr')()).eql('1') + await reload() + await t + .expect(getOpacity('.hidden-from-ssr')()).eql('1') }) diff --git a/tests/utils.js b/tests/utils.js index a9b23ede..a8f2719a 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -102,6 +102,8 @@ export const goBack = exec(() => window.history.back()) export const goForward = exec(() => window.history.forward()) +export const reload = exec(() => window.location.reload()) + export const forceOffline = exec(() => window.__forceOnline(false)) export const forceOnline = exec(() => window.__forceOnline(true)) @@ -110,6 +112,10 @@ export const getComposeSelectionStart = exec(() => composeInput().selectionStart dependencies: { composeInput } }) +export const getOpacity = selector => exec(() => window.getComputedStyle(document.querySelector(selector)).opacity, { + dependencies: { selector } +}) + export const getCurrentTheme = exec(() => { let themeLink = document.head.querySelector('link[rel=stylesheet][href^="/theme-"]') if (themeLink) {