Skip to content

Commit

Permalink
fix: styles of initialization errors
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed May 17, 2023
1 parent 07492a4 commit aca40e6
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 26 deletions.
2 changes: 0 additions & 2 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const { defineConfig } = require('cypress');
const { initPlugin } = require('@frsource/cypress-plugin-visual-regression-diff/plugins');

module.exports = defineConfig({
userAgent:
'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1',
video: false,
fixturesFolder: 'tests/e2e/fixtures',
screenshotsFolder: 'tests/e2e/screenshots',
Expand Down
16 changes: 14 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,22 @@
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@300;400;500;600;700&family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
body > noscript > p.fullscreen-error-message,
body > p.fullscreen-error-message {
margin: 0 auto;
padding-top: 30vh;
padding-left: 20px;
padding-right: 20px;
max-width: 400px;
font: 23px/28px 'Inter', sans-serif;
text-align: center;
}
</style>
</head>
<body>
<noscript>
<p class="fullscreen-message">
<p class="fullscreen-error-message">
Base æpp doesn't work without JavaScript enabled.
Please enable it to continue.
</p>
Expand All @@ -32,7 +44,7 @@
return;
}

document.body.innerHTML = '<p class="fullscreen-message">'
document.body.innerHTML = '<p class="fullscreen-error-message">'
+ 'Base app has failed to run in this browser.'
+ '</p>';
}
Expand Down
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'normalize.css';
import Vue from 'vue';
import './lib/setGlobalPolyfills';
import store from './store';
Expand Down
17 changes: 0 additions & 17 deletions src/styles/fullscreen-message.scss

This file was deleted.

2 changes: 0 additions & 2 deletions src/ui-common.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Vue from 'vue';
import 'normalize.css';
import 'focus-visible';
import './styles/fullscreen-message.scss';
import './components/icon.scss';
import { IS_IOS, DISABLED_BROWSER, ROUTE_MOBILE_LOGGED_IN } from './lib/constants';

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions tests/e2e/specs/load-error.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function ensureThrownError(message) {
cy.wrap(new Promise((resolve) => {
cy.on('uncaught:exception', (err) => {
expect(err.message).to.include(message);
resolve();
return false;
});
}));
}

describe('Load error', () => {
[false, true].forEach((isDesktop) => {
it(`load error ${isDesktop ? 'desktop' : 'mobile'}`, () => {
if (!isDesktop) cy.viewport('iphone-se2');
cy.visit('/', {
isDesktop,
onBeforeLoad(contentWindow) {
contentWindow.Array = {}; // eslint-disable-line no-param-reassign
},
});
ensureThrownError('Array.isArray is not a function');
cy.matchImage();
});
});

[false, true].forEach((isDesktop) => {
it(`fails to load state ${isDesktop ? 'desktop' : 'mobile'}`, () => {
if (!isDesktop) cy.viewport('iphone-se2');
cy.visit('/', {
isDesktop,
onBeforeLoad(contentWindow) {
contentWindow.localStorage.setItem('vuex', '!');
},
});
ensureThrownError('Unexpected token \'!\', "!" is not valid JSON');
const button = cy.get('.ae-button').should('be.visible');
cy.matchImage();
button.click();
cy.get('.note').should('be.visible'); // reloaded to desktop
});
});
});
2 changes: 1 addition & 1 deletion tests/e2e/specs/settings/index.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Settings', () => {
cy.get('.overlay').should('not.exist');
cy.get('[data-cy="reset"]').click();
cy.get('.ae-button.primary').click();
cy.location('pathname').should('eq', '/add-to-home-screen');
cy.get('.note').should('be.visible'); // reloaded to desktop
});

[
Expand Down
10 changes: 8 additions & 2 deletions tests/e2e/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

Cypress.Commands.overwrite('visit', (originalFn, url, options = {}) => originalFn(
Cypress.Commands.overwrite('visit', (originalFn, url, {
isDesktop, login, state, ...options
} = {}) => originalFn(
url,
{
...options,
onBeforeLoad(contentWindow) {
const { login, state } = options;
/* eslint-disable no-param-reassign */
contentWindow.localStorage.vuex = login || state ? JSON.stringify(Cypress._.merge(
login && {
Expand Down Expand Up @@ -70,6 +71,11 @@ Cypress.Commands.overwrite('visit', (originalFn, url, options = {}) => originalF
)) : null;
const promise = new Promise(() => {});
contentWindow.navigator.serviceWorker.register = () => promise;
if (!isDesktop) {
Object.defineProperty(contentWindow.navigator, 'userAgent', {
value: 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1',
});
}
/* eslint-enable no-param-reassign */
if (options.onBeforeLoad) options.onBeforeLoad(contentWindow);
},
Expand Down

0 comments on commit aca40e6

Please sign in to comment.