diff --git a/inline-script.js b/inline-script.js index 2b97cd213..0646e848b 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 +function safeParse (str) { + return str === 'undefined' ? undefined : JSON.parse(str) +} + const hasLocalStorage = testHasLocalStorageOnce() +const currentInstance = hasLocalStorage && + localStorage.store_currentInstance && + safeParse(localStorage.store_currentInstance) -if (hasLocalStorage && localStorage.store_currentInstance && localStorage.store_instanceThemes) { - let safeParse = (str) => str === 'undefined' ? undefined : JSON.parse(str) +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 48f8b3acb..4fa8c995f 100644 --- a/src/template.html +++ b/src/template.html @@ -48,7 +48,7 @@ - diff --git a/tests/spec/002-login-spec.js b/tests/spec/002-login-spec.js index efefab0f6..47312d7ab 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 a9b23eded..a8f2719a6 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) {