Skip to content

Commit 7daee34

Browse files
authored
Merge pull request #278 from manosim/v2-react-router-4
[V2] React Router v4
2 parents 39960b1 + 63ad344 commit 7daee34

File tree

17 files changed

+378
-277
lines changed

17 files changed

+378
-277
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
"react-icheck": "=0.3.7",
7777
"react-modal": "=1.7.3",
7878
"react-redux": "=5.0.4",
79-
"react-router": "=3.0.0",
79+
"react-router": "=4.1.0",
80+
"react-router-dom": "=4.1.0",
8081
"redux": "=3.6.0",
8182
"redux-storage": "=4.1.2",
8283
"redux-storage-decorator-filter": "=1.1.8",

src/js/__mocks__/react-icheck.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
3+
export class Checkbox extends React.PureComponent {
4+
render() {
5+
return (
6+
<div>
7+
<strong>{this.props.label}</strong>
8+
<input
9+
type="checkbox"
10+
checked={this.props.defaultChecked}
11+
onChange={(evt) => this.props.onChange(evt)} />
12+
</div>
13+
);
14+
};
15+
}
16+
17+
export class Radio extends React.PureComponent {
18+
render() {
19+
return (
20+
<div>
21+
<strong>{this.props.label}</strong>
22+
<input
23+
type="radio"
24+
value={this.props.value}
25+
checked={this.props.defaultChecked}
26+
onChange={(evt) => this.props.onChange(evt)} />
27+
</div>
28+
);
29+
};
30+
}
31+
32+
export class RadioGroup extends React.PureComponent {
33+
render() {
34+
return (
35+
<div>
36+
{this.props.children}
37+
</div>
38+
);
39+
};
40+
}

src/js/__mocks__/react-modal.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
3+
export default class Modal extends React.PureComponent {
4+
render() {
5+
return this.props.isOpen ? (
6+
<div>{this.props.children}</div>
7+
) : null;
8+
};
9+
}

src/js/__tests__/app.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { ipcRenderer } from 'electron';
44

55
import * as actions from '../actions';
66

7-
jest.mock('../routes');
87
jest.mock('../store/configureStore', () => {
98
return () => ({
109
getState: () => {
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`components/settings-modal.js should render itself & its children (closed modal) 1`] = `null`;
4+
5+
exports[`components/settings-modal.js should render itself & its children (open modal) 1`] = `
6+
<div>
7+
<h3
8+
className="modal-title"
9+
>
10+
Settings
11+
<span
12+
className="octicon octicon-x btn-close pull-right"
13+
onClick={[Function]}
14+
/>
15+
</h3>
16+
<div
17+
className="row setting"
18+
>
19+
<div>
20+
<strong>
21+
Show only participating
22+
</strong>
23+
<input
24+
checked={false}
25+
onChange={[Function]}
26+
type="checkbox"
27+
/>
28+
</div>
29+
</div>
30+
<div
31+
className="row setting"
32+
>
33+
<div>
34+
<strong>
35+
Play sound
36+
</strong>
37+
<input
38+
checked={true}
39+
onChange={[Function]}
40+
type="checkbox"
41+
/>
42+
</div>
43+
</div>
44+
<div
45+
className="row setting"
46+
>
47+
<div>
48+
<strong>
49+
Show notifications
50+
</strong>
51+
<input
52+
checked={true}
53+
onChange={[Function]}
54+
type="checkbox"
55+
/>
56+
</div>
57+
</div>
58+
<div
59+
className="row setting"
60+
>
61+
<div>
62+
<strong>
63+
On Click, Mark as Read
64+
</strong>
65+
<input
66+
checked={false}
67+
onChange={[Function]}
68+
type="checkbox"
69+
/>
70+
</div>
71+
</div>
72+
<div
73+
className="row setting"
74+
>
75+
<div>
76+
<strong>
77+
Open at startup
78+
</strong>
79+
<input
80+
checked={false}
81+
onChange={[Function]}
82+
type="checkbox"
83+
/>
84+
</div>
85+
</div>
86+
<div>
87+
<div>
88+
<strong>
89+
Both Icons
90+
</strong>
91+
<input
92+
checked={undefined}
93+
onChange={[Function]}
94+
type="radio"
95+
value="both"
96+
/>
97+
</div>
98+
<div>
99+
<strong>
100+
Tray Icon
101+
</strong>
102+
<input
103+
checked={undefined}
104+
onChange={[Function]}
105+
type="radio"
106+
value="tray"
107+
/>
108+
</div>
109+
<div>
110+
<strong>
111+
Dock Icon
112+
</strong>
113+
<input
114+
checked={undefined}
115+
onChange={[Function]}
116+
type="radio"
117+
value="dock"
118+
/>
119+
</div>
120+
</div>
121+
<button
122+
className="btn btn-block btn-outline-danger btn-logout"
123+
onClick={[Function]}
124+
>
125+
<span
126+
className="octicon octicon-sign-out"
127+
/>
128+
Logout
129+
</button>
130+
</div>
131+
`;

src/js/__tests__/components/loading.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
import React from 'react'; // eslint-disable-line no-unused-vars
22
import { shallow, mount } from 'enzyme';
3+
import { Map } from 'immutable';
34
import NProgress from 'nprogress';
45

5-
import Loading from '../../components/loading';
6+
import { Loading, mapStateToProps } from '../../components/loading';
67

7-
function setupShallow() {
8-
const props = {};
9-
const wrapper = shallow(<Loading {...props} />);
8+
describe('components/loading.js', function () {
9+
const props = {
1010

11-
return {
12-
props: props,
13-
wrapper: wrapper,
1411
};
15-
};
1612

17-
describe('components/loading.js', function () {
1813
beforeEach(() => {
1914
NProgress.start = jest.fn();
2015
NProgress.done = jest.fn();
@@ -27,8 +22,20 @@ describe('components/loading.js', function () {
2722
NProgress.remove.mockReset();
2823
});
2924

25+
it('should test the mapStateToProps method', () => {
26+
const state = {
27+
notifications: Map({
28+
isFetching: false,
29+
}),
30+
};
31+
32+
const mappedProps = mapStateToProps(state);
33+
34+
expect(mappedProps.isLoading).toBeFalsy();
35+
});
36+
3037
it('should render itself & its children', function () {
31-
const { wrapper } = setupShallow();
38+
const wrapper = shallow(<Loading {...props} />);
3239

3340
expect(wrapper).toBeDefined();
3441
expect(wrapper.children().length).toBe(0);
@@ -38,8 +45,8 @@ describe('components/loading.js', function () {
3845
spyOn(Loading.prototype, 'componentDidMount').and.callThrough();
3946

4047
const isLoading = true;
41-
const props = { isLoading };
42-
const wrapper = mount(<Loading {...props} />);
48+
const caseProps = { isLoading };
49+
const wrapper = mount(<Loading {...caseProps} />);
4350

4451
expect(wrapper).toBeDefined();
4552
expect(wrapper.children().length).toEqual(0);
@@ -52,8 +59,8 @@ describe('components/loading.js', function () {
5259
spyOn(Loading.prototype, 'componentDidMount').and.callThrough();;
5360

5461
const isLoading = true;
55-
const props = { isLoading };
56-
const wrapper = mount(<Loading {...props} />);
62+
const caseProps = { isLoading };
63+
const wrapper = mount(<Loading {...caseProps} />);
5764

5865
expect(wrapper).toBeDefined();
5966
expect(wrapper.children().length).toEqual(0);
@@ -76,8 +83,8 @@ describe('components/loading.js', function () {
7683
spyOn(Loading.prototype, 'componentWillUnmount').and.callThrough();;
7784

7885
const isLoading = true;
79-
const props = { isLoading };
80-
const wrapper = mount(<Loading {...props} />);
86+
const caseProps = { isLoading };
87+
const wrapper = mount(<Loading {...caseProps} />);
8188

8289
expect(wrapper).toBeDefined();
8390
expect(wrapper.children().length).toEqual(0);

src/js/__tests__/components/login.js

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,6 @@ import { LoginPage, mapStateToProps } from '../../components/login';
77
const { shell, ipcRenderer, remote } = require('electron');
88
const BrowserWindow = remote.BrowserWindow;
99

10-
function setup(props) {
11-
const options = {
12-
context: {
13-
router: {
14-
push: jest.fn(),
15-
replace: jest.fn()
16-
}
17-
}
18-
};
19-
20-
const wrapper = shallow(<LoginPage {...props} />, options);
21-
22-
return {
23-
context: options.context,
24-
props: props,
25-
wrapper: wrapper,
26-
};
27-
};
28-
2910
describe('components/login.js', () => {
3011
beforeEach(function() {
3112
BrowserWindow().loadURL.mockReset();
@@ -58,7 +39,7 @@ describe('components/login.js', () => {
5839
isFetching: false
5940
};
6041

61-
const { wrapper } = setup(props);
42+
const wrapper = shallow(<LoginPage {...props} />);
6243

6344
expect(wrapper).toBeDefined();
6445
expect(wrapper.find('.desc').text()).toContain('in your menu bar.');
@@ -84,7 +65,7 @@ describe('components/login.js', () => {
8465
isFetching: false
8566
};
8667

87-
const { wrapper } = setup(props);
68+
const wrapper = shallow(<LoginPage {...props} />);
8869

8970
expect(wrapper).toBeDefined();
9071

@@ -116,7 +97,7 @@ describe('components/login.js', () => {
11697
isFetching: false
11798
};
11899

119-
const { wrapper } = setup(props);
100+
const wrapper = shallow(<LoginPage {...props} />);
120101

121102
expect(wrapper).toBeDefined();
122103

@@ -148,7 +129,7 @@ describe('components/login.js', () => {
148129
isFetching: false
149130
};
150131

151-
const { wrapper } = setup(props);
132+
const wrapper = shallow(<LoginPage {...props} />);
152133

153134
expect(wrapper).toBeDefined();
154135

@@ -179,7 +160,7 @@ describe('components/login.js', () => {
179160
isFetching: false
180161
};
181162

182-
const { wrapper } = setup(props);
163+
const wrapper = shallow(<LoginPage {...props} />);
183164

184165
expect(wrapper).toBeDefined();
185166

@@ -197,7 +178,7 @@ describe('components/login.js', () => {
197178
isFetching: false
198179
};
199180

200-
const { wrapper, context } = setup(props);
181+
const wrapper = shallow(<LoginPage {...props} />);
201182

202183
expect(wrapper).toBeDefined();
203184

@@ -207,8 +188,8 @@ describe('components/login.js', () => {
207188

208189
expect(ipcRenderer.send).toHaveBeenCalledTimes(1);
209190
expect(ipcRenderer.send).toHaveBeenCalledWith('reopen-window');
210-
expect(context.router.push).toHaveBeenCalledTimes(1);
211-
expect(context.router.push).toHaveBeenCalledWith('/notifications');
191+
192+
expect(wrapper.props().to).toEqual('/');
212193
});
213194

214195
it('should request the github token if the oauth code is received', () => {
@@ -222,7 +203,7 @@ describe('components/login.js', () => {
222203
isFetching: false
223204
};
224205

225-
const { wrapper } = setup(props);
206+
const wrapper = shallow(<LoginPage {...props} />);
226207

227208
expect(wrapper).toBeDefined();
228209

0 commit comments

Comments
 (0)