Skip to content

Commit e0b3a09

Browse files
Add tests for like and comments
1 parent 6a5d3bd commit e0b3a09

File tree

7 files changed

+392
-28
lines changed

7 files changed

+392
-28
lines changed

step-4-done/tests/components/wine-app.spec.js

+56-4
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,19 @@ window.fetch = (url, post) => {
119119

120120
// POST sur comments
121121
if (url.startsWith(`/api/wines/${wines1[0].id}/comments`) && post) {
122-
comments[wines1[0].id].push(JSON.parse(post.body));
122+
comments[wines1[0].id].push(Object.assign({}, JSON.parse(post.body), { date: 'today' } ));
123123
return promise({ json: () => [] });
124124
}
125125
if (url.startsWith(`/api/wines/${wines1[1].id}/comments`) && post) {
126-
comments[wines1[1].id].push(JSON.parse(post.body));
126+
comments[wines1[1].id].push(Object.assign({}, JSON.parse(post.body), { date: 'today' } ));
127127
return promise({ json: () => [] });
128128
}
129129
if (url.startsWith(`/api/wines/${wines2[0].id}/comments`) && post) {
130-
comments[wines2[0].id].push(JSON.parse(post.body));
130+
comments[wines2[0].id].push(Object.assign({}, JSON.parse(post.body), { date: 'today' } ));
131131
return promise({ json: () => [] });
132132
}
133133
if (url.startsWith(`/api/wines/${wines2[1].id}/comments`) && post) {
134-
comments[wines2[1].id].push(JSON.parse(post.body));
134+
comments[wines2[1].id].push(Object.assign({}, JSON.parse(post.body), { date: 'today' } ));
135135
return promise({ json: () => [] });
136136
}
137137
// GET sur comments
@@ -266,4 +266,56 @@ describe('<App />', () => {
266266
expect(foundGrapes.length).to.equal(2);
267267
}
268268
});
269+
270+
it('doit afficher un vin et le liker', () => {
271+
const history = createMemoryHistory(window.location);
272+
const wrapper = mount(
273+
<App history={history} />
274+
);
275+
276+
const region1 = wrapper.find('Regions').find('div').filterWhere(n => n.get(0).innerHTML === regions[0]);
277+
region1.simulate('click');
278+
279+
const wine1 = wrapper.find('WineList').find('div').filterWhere(n => n.get(0).innerHTML === wines1[0].name);
280+
wine1.simulate('click');
281+
282+
const like = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'like');
283+
expect(like.length).to.equal(1);
284+
285+
like.simulate('click');
286+
287+
const like2 = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'unlike');
288+
expect(like2.length).to.equal(1);
289+
290+
like2.simulate('click');
291+
292+
const like3 = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'like');
293+
expect(like3.length).to.equal(1);
294+
});
295+
296+
it('doit afficher un vin et poster un commentaire', () => {
297+
const history = createMemoryHistory(window.location);
298+
const wrapper = mount(
299+
<App history={history} />
300+
);
301+
302+
const region1 = wrapper.find('Regions').find('div').filterWhere(n => n.get(0).innerHTML === regions[0]);
303+
region1.simulate('click');
304+
305+
const wine1 = wrapper.find('WineList').find('div').filterWhere(n => n.get(0).innerHTML === wines1[0].name);
306+
wine1.simulate('click');
307+
308+
// find comemnts
309+
310+
let paragraphs = wrapper.find('Comments').find('p');
311+
expect(paragraphs.length).to.equals(0);
312+
313+
wrapper.find('Comments').find('input').simulate('change', { target: { value: 'Comment 1' } });
314+
wrapper.find('Comments').find('textarea').simulate('change', { target: { value: 'Comment 1 body' } });
315+
wrapper.find('Comments').find('button').simulate('click');
316+
317+
paragraphs = wrapper.find('Comments').find('p');
318+
expect(paragraphs.length).to.equals(1);
319+
expect(paragraphs.at(0).html()).to.equals('<p>Comment 1 body</p>');
320+
});
269321
});

step-4/tests/components/wine-app.spec.js

+56-4
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,19 @@ window.fetch = (url, post) => {
119119

120120
// POST sur comments
121121
if (url.startsWith(`/api/wines/${wines1[0].id}/comments`) && post) {
122-
comments[wines1[0].id].push(JSON.parse(post.body));
122+
comments[wines1[0].id].push(Object.assign({}, JSON.parse(post.body), { date: 'today' } ));
123123
return promise({ json: () => [] });
124124
}
125125
if (url.startsWith(`/api/wines/${wines1[1].id}/comments`) && post) {
126-
comments[wines1[1].id].push(JSON.parse(post.body));
126+
comments[wines1[1].id].push(Object.assign({}, JSON.parse(post.body), { date: 'today' } ));
127127
return promise({ json: () => [] });
128128
}
129129
if (url.startsWith(`/api/wines/${wines2[0].id}/comments`) && post) {
130-
comments[wines2[0].id].push(JSON.parse(post.body));
130+
comments[wines2[0].id].push(Object.assign({}, JSON.parse(post.body), { date: 'today' } ));
131131
return promise({ json: () => [] });
132132
}
133133
if (url.startsWith(`/api/wines/${wines2[1].id}/comments`) && post) {
134-
comments[wines2[1].id].push(JSON.parse(post.body));
134+
comments[wines2[1].id].push(Object.assign({}, JSON.parse(post.body), { date: 'today' } ));
135135
return promise({ json: () => [] });
136136
}
137137
// GET sur comments
@@ -266,4 +266,56 @@ describe('<App />', () => {
266266
expect(foundGrapes.length).to.equal(2);
267267
}
268268
});
269+
270+
it('doit afficher un vin et le liker', () => {
271+
const history = createMemoryHistory(window.location);
272+
const wrapper = mount(
273+
<App history={history} />
274+
);
275+
276+
const region1 = wrapper.find('Regions').find('div').filterWhere(n => n.get(0).innerHTML === regions[0]);
277+
region1.simulate('click');
278+
279+
const wine1 = wrapper.find('WineList').find('div').filterWhere(n => n.get(0).innerHTML === wines1[0].name);
280+
wine1.simulate('click');
281+
282+
const like = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'like');
283+
expect(like.length).to.equal(1);
284+
285+
like.simulate('click');
286+
287+
const like2 = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'unlike');
288+
expect(like2.length).to.equal(1);
289+
290+
like2.simulate('click');
291+
292+
const like3 = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'like');
293+
expect(like3.length).to.equal(1);
294+
});
295+
296+
it('doit afficher un vin et poster un commentaire', () => {
297+
const history = createMemoryHistory(window.location);
298+
const wrapper = mount(
299+
<App history={history} />
300+
);
301+
302+
const region1 = wrapper.find('Regions').find('div').filterWhere(n => n.get(0).innerHTML === regions[0]);
303+
region1.simulate('click');
304+
305+
const wine1 = wrapper.find('WineList').find('div').filterWhere(n => n.get(0).innerHTML === wines1[0].name);
306+
wine1.simulate('click');
307+
308+
// find comemnts
309+
310+
let paragraphs = wrapper.find('Comments').find('p');
311+
expect(paragraphs.length).to.equals(0);
312+
313+
wrapper.find('Comments').find('input').simulate('change', { target: { value: 'Comment 1' } });
314+
wrapper.find('Comments').find('textarea').simulate('change', { target: { value: 'Comment 1 body' } });
315+
wrapper.find('Comments').find('button').simulate('click');
316+
317+
paragraphs = wrapper.find('Comments').find('p');
318+
expect(paragraphs.length).to.equals(1);
319+
expect(paragraphs.at(0).html()).to.equals('<p>Comment 1 body</p>');
320+
});
269321
});

step-5-done/tests/components/wine-app.spec.js

+56-4
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,19 @@ window.fetch = (url, post) => {
119119

120120
// POST sur comments
121121
if (url.startsWith(`/api/wines/${wines1[0].id}/comments`) && post) {
122-
comments[wines1[0].id].push(JSON.parse(post.body));
122+
comments[wines1[0].id].push(Object.assign({}, JSON.parse(post.body), { date: 'today' } ));
123123
return promise({ json: () => [] });
124124
}
125125
if (url.startsWith(`/api/wines/${wines1[1].id}/comments`) && post) {
126-
comments[wines1[1].id].push(JSON.parse(post.body));
126+
comments[wines1[1].id].push(Object.assign({}, JSON.parse(post.body), { date: 'today' } ));
127127
return promise({ json: () => [] });
128128
}
129129
if (url.startsWith(`/api/wines/${wines2[0].id}/comments`) && post) {
130-
comments[wines2[0].id].push(JSON.parse(post.body));
130+
comments[wines2[0].id].push(Object.assign({}, JSON.parse(post.body), { date: 'today' } ));
131131
return promise({ json: () => [] });
132132
}
133133
if (url.startsWith(`/api/wines/${wines2[1].id}/comments`) && post) {
134-
comments[wines2[1].id].push(JSON.parse(post.body));
134+
comments[wines2[1].id].push(Object.assign({}, JSON.parse(post.body), { date: 'today' } ));
135135
return promise({ json: () => [] });
136136
}
137137
// GET sur comments
@@ -266,4 +266,56 @@ describe('<App />', () => {
266266
expect(foundGrapes.length).to.equal(2);
267267
}
268268
});
269+
270+
it('doit afficher un vin et le liker', () => {
271+
const history = createMemoryHistory(window.location);
272+
const wrapper = mount(
273+
<App history={history} />
274+
);
275+
276+
const region1 = wrapper.find('Regions').find('div').filterWhere(n => n.get(0).innerHTML === regions[0]);
277+
region1.simulate('click');
278+
279+
const wine1 = wrapper.find('WineList').find('div').filterWhere(n => n.get(0).innerHTML === wines1[0].name);
280+
wine1.simulate('click');
281+
282+
const like = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'like');
283+
expect(like.length).to.equal(1);
284+
285+
like.simulate('click');
286+
287+
const like2 = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'unlike');
288+
expect(like2.length).to.equal(1);
289+
290+
like2.simulate('click');
291+
292+
const like3 = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'like');
293+
expect(like3.length).to.equal(1);
294+
});
295+
296+
it('doit afficher un vin et poster un commentaire', () => {
297+
const history = createMemoryHistory(window.location);
298+
const wrapper = mount(
299+
<App history={history} />
300+
);
301+
302+
const region1 = wrapper.find('Regions').find('div').filterWhere(n => n.get(0).innerHTML === regions[0]);
303+
region1.simulate('click');
304+
305+
const wine1 = wrapper.find('WineList').find('div').filterWhere(n => n.get(0).innerHTML === wines1[0].name);
306+
wine1.simulate('click');
307+
308+
// find comemnts
309+
310+
let paragraphs = wrapper.find('Comments').find('p');
311+
expect(paragraphs.length).to.equals(0);
312+
313+
wrapper.find('Comments').find('input').simulate('change', { target: { value: 'Comment 1' } });
314+
wrapper.find('Comments').find('textarea').simulate('change', { target: { value: 'Comment 1 body' } });
315+
wrapper.find('Comments').find('button').simulate('click');
316+
317+
paragraphs = wrapper.find('Comments').find('p');
318+
expect(paragraphs.length).to.equals(1);
319+
expect(paragraphs.at(0).html()).to.equals('<p>Comment 1 body</p>');
320+
});
269321
});

step-5/tests/components/wine-app.spec.js

+56-4
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,19 @@ window.fetch = (url, post) => {
119119

120120
// POST sur comments
121121
if (url.startsWith(`/api/wines/${wines1[0].id}/comments`) && post) {
122-
comments[wines1[0].id].push(JSON.parse(post.body));
122+
comments[wines1[0].id].push(Object.assign({}, JSON.parse(post.body), { date: 'today' } ));
123123
return promise({ json: () => [] });
124124
}
125125
if (url.startsWith(`/api/wines/${wines1[1].id}/comments`) && post) {
126-
comments[wines1[1].id].push(JSON.parse(post.body));
126+
comments[wines1[1].id].push(Object.assign({}, JSON.parse(post.body), { date: 'today' } ));
127127
return promise({ json: () => [] });
128128
}
129129
if (url.startsWith(`/api/wines/${wines2[0].id}/comments`) && post) {
130-
comments[wines2[0].id].push(JSON.parse(post.body));
130+
comments[wines2[0].id].push(Object.assign({}, JSON.parse(post.body), { date: 'today' } ));
131131
return promise({ json: () => [] });
132132
}
133133
if (url.startsWith(`/api/wines/${wines2[1].id}/comments`) && post) {
134-
comments[wines2[1].id].push(JSON.parse(post.body));
134+
comments[wines2[1].id].push(Object.assign({}, JSON.parse(post.body), { date: 'today' } ));
135135
return promise({ json: () => [] });
136136
}
137137
// GET sur comments
@@ -266,4 +266,56 @@ describe('<App />', () => {
266266
expect(foundGrapes.length).to.equal(2);
267267
}
268268
});
269+
270+
it('doit afficher un vin et le liker', () => {
271+
const history = createMemoryHistory(window.location);
272+
const wrapper = mount(
273+
<App history={history} />
274+
);
275+
276+
const region1 = wrapper.find('Regions').find('div').filterWhere(n => n.get(0).innerHTML === regions[0]);
277+
region1.simulate('click');
278+
279+
const wine1 = wrapper.find('WineList').find('div').filterWhere(n => n.get(0).innerHTML === wines1[0].name);
280+
wine1.simulate('click');
281+
282+
const like = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'like');
283+
expect(like.length).to.equal(1);
284+
285+
like.simulate('click');
286+
287+
const like2 = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'unlike');
288+
expect(like2.length).to.equal(1);
289+
290+
like2.simulate('click');
291+
292+
const like3 = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'like');
293+
expect(like3.length).to.equal(1);
294+
});
295+
296+
it('doit afficher un vin et poster un commentaire', () => {
297+
const history = createMemoryHistory(window.location);
298+
const wrapper = mount(
299+
<App history={history} />
300+
);
301+
302+
const region1 = wrapper.find('Regions').find('div').filterWhere(n => n.get(0).innerHTML === regions[0]);
303+
region1.simulate('click');
304+
305+
const wine1 = wrapper.find('WineList').find('div').filterWhere(n => n.get(0).innerHTML === wines1[0].name);
306+
wine1.simulate('click');
307+
308+
// find comemnts
309+
310+
let paragraphs = wrapper.find('Comments').find('p');
311+
expect(paragraphs.length).to.equals(0);
312+
313+
wrapper.find('Comments').find('input').simulate('change', { target: { value: 'Comment 1' } });
314+
wrapper.find('Comments').find('textarea').simulate('change', { target: { value: 'Comment 1 body' } });
315+
wrapper.find('Comments').find('button').simulate('click');
316+
317+
paragraphs = wrapper.find('Comments').find('p');
318+
expect(paragraphs.length).to.equals(1);
319+
expect(paragraphs.at(0).html()).to.equals('<p>Comment 1 body</p>');
320+
});
269321
});

0 commit comments

Comments
 (0)