Skip to content

Commit 90f8671

Browse files
committed
Add IClient test
1 parent 2dcc0f7 commit 90f8671

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

app/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Router, Route, IndexRoute, hashHistory } from 'react-router'
44
import 'bulma/css/bulma.css'
55
import 'font-awesome-webpack'
66

7-
import iClientComponent from 'components/iClient/iClientComponent';
7+
import iClientComponent from 'components/IClient/IClient';
88
import HomeComponent from 'components/Home/Home';
99
import ClientComponent from 'components/Client/Client';
1010
import AreaComponent from 'components/Area/Area';

app/components/iClient/iClientComponent.js renamed to app/components/IClient/IClient.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
2-
import { Router, Route, IndexRoute, IndexLink, Link } from 'react-router'
32

43
import LoginComponent from 'components/Login/Login';
54
import MenuComponent from 'components/Menu/Menu';
65

7-
class iClientComponent extends React.Component{
8-
constructor(props) {
9-
super(props);
6+
class IClient extends React.Component
7+
{
8+
constructor(props, context) {
9+
super(props, context);
1010
this.handleView = this.handleView.bind(this);
1111
}
1212

@@ -20,10 +20,11 @@ class iClientComponent extends React.Component{
2020
</div>
2121
);
2222
}
23+
2324
render() {
2425
let view = this.handleView();
2526

26-
if (!localStorage.token) {
27+
if (!window.localStorage.getItem('token')) {
2728
view = <LoginComponent />;
2829
}
2930
return (
@@ -32,5 +33,5 @@ class iClientComponent extends React.Component{
3233
}
3334
}
3435

35-
export default iClientComponent;
36+
export default IClient;
3637

tests/IClient.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
describe('Test iClient', () => {
3+
require('../tests/__mocks__/LocalStorageMock');
4+
5+
const React = require('react');
6+
const enzyme = require('enzyme');
7+
const shallow = enzyme.shallow;
8+
const mount = enzyme.mount;
9+
const IClient = require('components/IClient/IClient').default;
10+
11+
it('iClient should show login component if not logged', (done) => {
12+
13+
let component = shallow(
14+
<IClient />
15+
);
16+
17+
expect(component.text()).toEqual('<Login />');
18+
19+
done();
20+
});
21+
22+
it('iClient should show login component if not logged', (done) => {
23+
24+
window.localStorage.setItem('token', 'test_menu');
25+
26+
let component = shallow(
27+
<IClient>
28+
Test
29+
</IClient>
30+
);
31+
32+
expect(component.text()).toEqual('<Menu />Test');
33+
34+
done();
35+
});
36+
});
37+

0 commit comments

Comments
 (0)