Skip to content

Commit e55a540

Browse files
Merge pull request #36 from marcoaraujojunior/develop
Refactor create Areas and increase tests
2 parents c251bbd + c328f02 commit e55a540

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

app/components/Area/Create/Area.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ class Area extends React.Component
2121
e.preventDefault();
2222

2323
let form = e.target;
24+
let parent = '';
25+
if (form.querySelector('[name="parent"]')) {
26+
parent = form.querySelector('[name="parent"]').value;
27+
}
2428
let formData = {
2529
_id : this.refs.area.value,
26-
parent: form.querySelector('[name="parent"]').value
30+
parent: parent
2731
};
2832

2933
this.setState({area: formData});

tests/Create.Area.test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,5 +256,50 @@ describe('Test Create Area', () => {
256256
}
257257
}, 0);
258258
});
259+
260+
it('Should return data on submit when first time using areas', (done) => {
261+
262+
let areaInput;
263+
let areaSelected;
264+
let Area = require('components/Area/Create/Area').default;
265+
let mockAdapter = new MockAdapter(axios);
266+
let component = mount(
267+
<Area />,
268+
{ context }
269+
);
270+
let expected = {
271+
_id : 'Test',
272+
parent : '',
273+
}
274+
275+
mockAdapter
276+
.onGet(HOST + '/api/v1/area').reply(404, {error: "Not Found"})
277+
.onPost(HOST + '/api/v1/area').reply(201)
278+
279+
setTimeout(() => {
280+
281+
try {
282+
283+
let inputs = {
284+
area : component.find('input'),
285+
parent : component.find('select'),
286+
}
287+
288+
areaInput = component.find('input');
289+
areaInput.node.value = 'Test';
290+
areaInput.simulate('change', areaInput);
291+
292+
expect(component.find('.is-danger').text()).toEqual('Not Found');
293+
294+
component.find('form').simulate('submit', { target: component.find('form').get(0) });
295+
296+
expect(component.state().area).toEqual(expected);
297+
expect(component.state().error).toEqual('');
298+
done();
299+
} catch (e) {
300+
console.log(e);
301+
}
302+
}, 25);
303+
});
259304
});
260305

0 commit comments

Comments
 (0)