Skip to content

Commit 632ab89

Browse files
authored
Merge pull request #94 from oslabs-beta/rydang/error
changed error message and styling
2 parents 0aec537 + 32bf934 commit 632ab89

File tree

3 files changed

+55
-38
lines changed

3 files changed

+55
-38
lines changed

src/app/__tests__/MainContainer.test.js

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/* eslint-disable react/jsx-filename-extension */
22

3-
import { mount, configure } from 'enzyme';
3+
import { shallow, configure } from 'enzyme';
44
import React from 'react';
5-
import { act } from 'react-dom/test-utils';
65
import Adapter from 'enzyme-adapter-react-16';
76
import MainContainer from '../containers/MainContainer';
87
import { useStoreContext } from '../store';
@@ -18,15 +17,8 @@ const chrome = require('sinon-chrome');
1817
configure({ adapter: new Adapter() });
1918

2019
const state = {
21-
tabs: {
22-
87: {
23-
snapshots: [{}, {}, {}, {}],
24-
sliderIndex: 0,
25-
viewIndex: -1,
26-
mode: {},
27-
},
28-
},
29-
currentTab: 87,
20+
tabs: {},
21+
currentTab: null,
3022
};
3123

3224
const dispatch = jest.fn();
@@ -35,12 +27,9 @@ useStoreContext.mockImplementation(() => [state, dispatch]);
3527

3628
let wrapper;
3729
global.chrome = chrome;
38-
let eventListener;
3930
const port = {
4031
onMessage: {
41-
addListener: fn => {
42-
eventListener = fn;
43-
},
32+
addListener: () => {},
4433
},
4534
onDisconnect: {
4635
addListener: () => {},
@@ -49,29 +38,32 @@ const port = {
4938
chrome.runtime.connect.returns(port);
5039

5140
beforeEach(() => {
52-
wrapper = mount(<MainContainer />);
41+
wrapper = shallow(<MainContainer />);
5342
useStoreContext.mockClear();
5443
dispatch.mockClear();
5544
});
5645

5746
describe('MainContainer rendering', () => {
58-
test.skip('With no connection, should not render any containers', () => {
59-
expect(wrapper.text()).toEqual('please install our npm package in your app');
47+
test('With no snapshots, should not render any containers', () => {
48+
expect(wrapper.text()).toEqual(
49+
'No React application found. Please install our npm package in your app.',
50+
);
6051
expect(wrapper.find(HeadContainer).length).toBe(0);
6152
expect(wrapper.find(ActionContainer).length).toBe(0);
6253
expect(wrapper.find(StateContainer).length).toBe(0);
6354
expect(wrapper.find(TravelContainer).length).toBe(0);
6455
expect(wrapper.find(ButtonsContainer).length).toBe(0);
6556
});
66-
test('With connection established, should render all containers', () => {
67-
// fake connect
68-
act(() => {
69-
eventListener({
70-
action: 'initialConnectSnapshots',
71-
payload: 'test',
72-
});
73-
});
74-
wrapper.update();
57+
test('With snapshots, should render all containers', () => {
58+
state.currentTab = 87;
59+
state.tabs[87] = {
60+
snapshots: [{}],
61+
viewIndex: -1,
62+
sliderIndex: 0,
63+
mode: {},
64+
};
65+
66+
wrapper = shallow(<MainContainer />);
7567
expect(wrapper.find(HeadContainer).length).toBe(1);
7668
expect(wrapper.find(ActionContainer).length).toBe(1);
7769
expect(wrapper.find(StateContainer).length).toBe(1);

src/app/containers/MainContainer.jsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react';
1+
import React, { useEffect } from 'react';
22
import HeadContainer from './HeadContainer';
33
import ActionContainer from './ActionContainer';
44
import StateContainer from './StateContainer';
@@ -11,7 +11,6 @@ import {
1111
import { useStoreContext } from '../store';
1212

1313
function MainContainer() {
14-
const [npmExists, setnpm] = useState(false);
1514
const [store, dispatch] = useStoreContext();
1615
const { tabs, currentTab, port: currentPort } = store;
1716

@@ -39,7 +38,6 @@ function MainContainer() {
3938
}
4039
case 'initialConnectSnapshots': {
4140
dispatch(initialConnect(payload));
42-
setnpm(true);
4341
break;
4442
}
4543
default:
@@ -54,7 +52,19 @@ function MainContainer() {
5452
dispatch(setPort(port));
5553
});
5654

57-
if (!npmExists) return <div style={{ color: 'black' }}>Please install our npm package in your app</div>;
55+
if (!tabs[currentTab]) {
56+
return (
57+
<div className="error-container">
58+
<a
59+
href="https://www.npmjs.com/package/react-time-travel"
60+
target="_blank"
61+
rel="noopener noreferrer"
62+
>
63+
No React application found. Please install our npm package in your app.
64+
</a>
65+
</div>
66+
);
67+
}
5868
const { viewIndex, sliderIndex, snapshots } = tabs[currentTab];
5969

6070
// if viewIndex is -1, then use the sliderIndex instead

src/app/styles/styles.scss

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,30 @@ body {
1818
overflow: hidden;
1919
}
2020

21+
.error-container {
22+
height: 100%;
23+
margin: 0 auto;
24+
background-color: $brand-color;
25+
overflow: hidden;
26+
27+
display: grid;
28+
justify-content: center;
29+
a {
30+
color: white;
31+
margin-top: 5%;
32+
height: 3%;
33+
}
34+
}
35+
2136
.body-container {
2237
height: 94%;
2338
display: grid;
2439
grid-template-columns: 1fr 2fr;
2540
grid-template-rows: 8fr 1fr;
2641
grid-template-areas:
27-
"actions states"
28-
"travel travel"
29-
"buttons buttons";
42+
'actions states'
43+
'travel travel'
44+
'buttons buttons';
3045
}
3146

3247
/* if extension width is less than 500px, stack the body containers */
@@ -35,10 +50,10 @@ body {
3550
grid-template-rows: 3fr 5fr 1fr;
3651
grid-template-columns: auto;
3752
grid-template-areas:
38-
"actions"
39-
"states"
40-
"travel"
41-
"buttons";
53+
'actions'
54+
'states'
55+
'travel'
56+
'buttons';
4257
}
4358
}
4459
.travel-container {

0 commit comments

Comments
 (0)