Skip to content

Commit d979d82

Browse files
committed
Add coverage to json stub
1 parent fe85da6 commit d979d82

File tree

5 files changed

+122
-1
lines changed

5 files changed

+122
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"collectCoverage": true,
5050
"globals": {
5151
"HOST": "http://localhost:3000",
52-
"jsonStubHeaders": "{}"
52+
"jsonStubHeaders": ""
5353
},
5454
"moduleNameMapper": {
5555
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/tests/__mocks__/fileMock.js",

tests/Area.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,35 @@ describe('Test Area', () => {
8989
}, 0);
9090
});
9191

92+
it('Should show headers to stub json', (done) => {
93+
94+
let response = require('AreasResponseMock').default;
95+
let Area;
96+
let component;
97+
let mockAdapter = new MockAdapter(axios);
98+
jsonStubHeaders = '{ "JsonStub-User-Key": "user-key", "JsonStub-Project-Key": "project-key" }';
99+
100+
mockAdapter.onGet(HOST + '/api/v1/visit/group/area').reply(200, response);
101+
102+
Area = require('components/Area/Area').default;
103+
104+
component = shallow(
105+
<Area />
106+
);
107+
108+
setTimeout(() => {
109+
expect(
110+
shallow(
111+
component.state().areas[0]
112+
).find('.title').at(0).text()
113+
).toEqual('Center');
114+
expect(
115+
shallow(
116+
component.state().areas[1]
117+
).find('.title').at(0).text()
118+
).toEqual('South');
119+
done();
120+
}, 0);
121+
});
122+
92123
});

tests/List.Area.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,35 @@ describe('Test Area', () => {
101101
}, 0);
102102
});
103103

104+
it('Should show headers to stub json', (done) => {
105+
let response = {
106+
areas: [
107+
{_id: 'South', parent: 'Center', ancestors: 'Center'},
108+
{_id: 'North', parent: 'Center', ancestors: 'Center'},
109+
]
110+
};
111+
let Area;
112+
let component;
113+
let mockAdapter = new MockAdapter(axios);
114+
jsonStubHeaders = '{ "JsonStub-User-Key": "user-key", "JsonStub-Project-Key": "project-key" }';
115+
116+
mockAdapter.onGet(HOST + '/api/v1/area').reply(200, response);
117+
118+
Area = require('components/Area/List/Area').default;
119+
120+
component = shallow(
121+
<Area />
122+
);
123+
124+
setTimeout(() => {
125+
try {
126+
component.update();
127+
expect(component.find('tbody td').at(0).text()).toEqual('South');
128+
done();
129+
} catch (e) {
130+
console.log(e);
131+
}
132+
}, 0);
133+
});
104134
});
105135

tests/List.Client.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,34 @@ describe('Test Client', () => {
8989
}, 0);
9090
});
9191

92+
it('Should show headers to stub json', (done) => {
93+
94+
let response = {
95+
clients: [
96+
{name: 'Jon Snow', address: '7 Street', city: 'Winterfell'},
97+
{name: 'Cotter Pyke', address: '0 Street', city: 'Castle Black'},
98+
]
99+
};
100+
let Client;
101+
let component;
102+
let mockAdapter = new MockAdapter(axios);
103+
jsonStubHeaders = '{ "JsonStub-User-Key": "user-key", "JsonStub-Project-Key": "project-key" }';
104+
105+
mockAdapter.onGet(HOST + '/api/v1/client').reply(200, response);
106+
107+
Client = require('components/Client/List/Client').default;
108+
109+
component = shallow(
110+
<Client />
111+
);
112+
113+
setTimeout(() => {
114+
component.update();
115+
expect(component.find('tbody td').at(0).text()).toEqual('Jon Snow');
116+
expect(component.find('tbody td').at(1).text()).toEqual('7 Street - Winterfell');
117+
done();
118+
}, 0);
119+
});
120+
92121
});
93122

tests/Login.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,36 @@ describe('Test Login', () => {
161161
}, 0);
162162
});
163163

164+
it('Should show headers to stub json', (done) => {
165+
166+
let Login = require('components/Login/Login').default;
167+
let response = { error:"User Not Found" };
168+
let mockAdapter = new MockAdapter(axios);
169+
jsonStubHeaders = '{ "JsonStub-User-Key": "user-key", "JsonStub-Project-Key": "project-key" }';
170+
171+
mockAdapter.onPost(HOST + '/authenticate').reply(401, response);
172+
173+
let component = mount(
174+
<Login />,
175+
{ context }
176+
);
177+
178+
let inputLogin = component.find('form div p input[type="text"]');
179+
let inputPassword = component.find('form div p input[type="password"]');
180+
181+
inputLogin.node.value = 'Astolfo';
182+
inputLogin.simulate('change', inputLogin);
183+
184+
inputPassword.node.value = 'abcd';
185+
inputPassword.simulate('change', inputPassword);
186+
187+
component.find('form').simulate('submit', { target: component.find('form').get(0) });
188+
189+
setTimeout(() => {
190+
expect(component.state().error).toEqual('User Not Found');
191+
done();
192+
}, 0);
193+
});
194+
164195
});
165196

0 commit comments

Comments
 (0)