Skip to content

Commit fd497ed

Browse files
Test for every features ;-)
1 parent 51c19d5 commit fd497ed

File tree

5 files changed

+49
-15
lines changed

5 files changed

+49
-15
lines changed

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const comments = {
7272

7373
window.fetch = (url, post) => {
7474
if (url.startsWith('/api/likes')) {
75-
return promise({ json: () => ({ count: Object.keys(comments).filter(k => comments[k]).length }) });
75+
return promise({ json: () => ({ count: Object.keys(likes).filter(k => likes[k]).length }) });
7676
}
7777
if (url.startsWith('/api/comments')) {
7878
return promise({ json: () => ({ count: Object.keys(comments).map(k => comments[k].length).reduce((a, b) => a + b) }) });
@@ -267,7 +267,7 @@ describe('<App />', () => {
267267
}
268268
});
269269

270-
it('doit afficher un vin et le liker', () => {
270+
it('doit afficher un vin et le liker tout en incrémentant les stats globales', () => {
271271
const history = createMemoryHistory(window.location);
272272
const wrapper = mount(
273273
<App history={history} />
@@ -282,18 +282,23 @@ describe('<App />', () => {
282282
const like = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'like');
283283
expect(like.length).to.equal(1);
284284

285+
expect(wrapper.find('Stats').contains(<div><span>likes : </span><span>0</span></div>));
286+
285287
like.simulate('click');
286288

287289
const like2 = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'unlike');
288290
expect(like2.length).to.equal(1);
289291

292+
expect(wrapper.find('Stats').contains(<div><span>likes : </span><span>1</span></div>));
293+
290294
like2.simulate('click');
291295

292296
const like3 = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'like');
293297
expect(like3.length).to.equal(1);
298+
expect(wrapper.find('Stats').contains(<div><span>likes : </span><span>0</span></div>));
294299
});
295300

296-
it('doit afficher un vin et poster un commentaire', () => {
301+
it('doit afficher un vin et poster un commentaire tout en incrémentant les stats globales', () => {
297302
const history = createMemoryHistory(window.location);
298303
const wrapper = mount(
299304
<App history={history} />
@@ -310,12 +315,15 @@ describe('<App />', () => {
310315
let paragraphs = wrapper.find('Comments').find('p');
311316
expect(paragraphs.length).to.equals(0);
312317

318+
expect(wrapper.find('Stats').contains(<div><span>comments : </span><span>0</span></div>));
319+
313320
wrapper.find('Comments').find('input').simulate('change', { target: { value: 'Comment 1' } });
314321
wrapper.find('Comments').find('textarea').simulate('change', { target: { value: 'Comment 1 body' } });
315322
wrapper.find('Comments').find('button').simulate('click');
316323

317324
paragraphs = wrapper.find('Comments').find('p');
318325
expect(paragraphs.length).to.equals(1);
319326
expect(paragraphs.at(0).html()).to.equals('<p>Comment 1 body</p>');
327+
expect(wrapper.find('Stats').contains(<div><span>comments : </span><span>1</span></div>));
320328
});
321329
});

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const comments = {
7272

7373
window.fetch = (url, post) => {
7474
if (url.startsWith('/api/likes')) {
75-
return promise({ json: () => ({ count: Object.keys(comments).filter(k => comments[k]).length }) });
75+
return promise({ json: () => ({ count: Object.keys(likes).filter(k => likes[k]).length }) });
7676
}
7777
if (url.startsWith('/api/comments')) {
7878
return promise({ json: () => ({ count: Object.keys(comments).map(k => comments[k].length).reduce((a, b) => a + b) }) });
@@ -267,7 +267,7 @@ describe('<App />', () => {
267267
}
268268
});
269269

270-
it('doit afficher un vin et le liker', () => {
270+
it('doit afficher un vin et le liker tout en incrémentant les stats globales', () => {
271271
const history = createMemoryHistory(window.location);
272272
const wrapper = mount(
273273
<App history={history} />
@@ -282,18 +282,23 @@ describe('<App />', () => {
282282
const like = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'like');
283283
expect(like.length).to.equal(1);
284284

285+
expect(wrapper.find('Stats').contains(<div><span>likes : </span><span>0</span></div>));
286+
285287
like.simulate('click');
286288

287289
const like2 = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'unlike');
288290
expect(like2.length).to.equal(1);
289291

292+
expect(wrapper.find('Stats').contains(<div><span>likes : </span><span>1</span></div>));
293+
290294
like2.simulate('click');
291295

292296
const like3 = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'like');
293297
expect(like3.length).to.equal(1);
298+
expect(wrapper.find('Stats').contains(<div><span>likes : </span><span>0</span></div>));
294299
});
295300

296-
it('doit afficher un vin et poster un commentaire', () => {
301+
it('doit afficher un vin et poster un commentaire tout en incrémentant les stats globales', () => {
297302
const history = createMemoryHistory(window.location);
298303
const wrapper = mount(
299304
<App history={history} />
@@ -310,12 +315,15 @@ describe('<App />', () => {
310315
let paragraphs = wrapper.find('Comments').find('p');
311316
expect(paragraphs.length).to.equals(0);
312317

318+
expect(wrapper.find('Stats').contains(<div><span>comments : </span><span>0</span></div>));
319+
313320
wrapper.find('Comments').find('input').simulate('change', { target: { value: 'Comment 1' } });
314321
wrapper.find('Comments').find('textarea').simulate('change', { target: { value: 'Comment 1 body' } });
315322
wrapper.find('Comments').find('button').simulate('click');
316323

317324
paragraphs = wrapper.find('Comments').find('p');
318325
expect(paragraphs.length).to.equals(1);
319326
expect(paragraphs.at(0).html()).to.equals('<p>Comment 1 body</p>');
327+
expect(wrapper.find('Stats').contains(<div><span>comments : </span><span>1</span></div>));
320328
});
321329
});

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const comments = {
7777

7878
window.fetch = (url, post) => {
7979
if (url.startsWith('/api/likes')) {
80-
return promise({ json: () => ({ count: Object.keys(comments).filter(k => comments[k]).length }) });
80+
return promise({ json: () => ({ count: Object.keys(likes).filter(k => likes[k]).length }) });
8181
}
8282
if (url.startsWith('/api/comments')) {
8383
return promise({ json: () => ({ count: Object.keys(comments).map(k => comments[k].length).reduce((a, b) => a + b) }) });
@@ -284,7 +284,7 @@ describe('<App />', () => {
284284
});
285285
});
286286

287-
it('doit afficher un vin et le liker', () => {
287+
it('doit afficher un vin et le liker tout en incrémentant les stats globales', () => {
288288
const history = createMemoryHistory(window.location);
289289
const wrapper = mount(
290290
<App history={history} />
@@ -298,22 +298,25 @@ describe('<App />', () => {
298298

299299
const like = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'like');
300300
expect(like.length).to.equal(1);
301+
expect(wrapper.find('Stats').contains(<div><span>likes : </span><span>0</span></div>));
301302

302303
like.simulate('click');
303304

304305
const like2 = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'unlike');
305306
expect(like2.length).to.equal(1);
307+
expect(wrapper.find('Stats').contains(<div><span>likes : </span><span>1</span></div>));
306308

307309
like2.simulate('click');
308310

309311
const like3 = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'like');
310312
expect(like3.length).to.equal(1);
313+
expect(wrapper.find('Stats').contains(<div><span>likes : </span><span>0</span></div>));
311314

312315
history.goBack();
313316
history.goBack();
314317
});
315318

316-
it('doit afficher un vin et poster un commentaire', () => {
319+
it('doit afficher un vin et poster un commentaire tout en incrémentant les stats globales', () => {
317320
const history = createMemoryHistory(window.location);
318321
const wrapper = mount(
319322
<App history={history} />
@@ -329,6 +332,7 @@ describe('<App />', () => {
329332

330333
let paragraphs = wrapper.find('Comments').find('p');
331334
expect(paragraphs.length).to.equals(0);
335+
expect(wrapper.find('Stats').contains(<div><span>comments : </span><span>0</span></div>));
332336

333337
wrapper.find('Comments').find('input').simulate('change', { target: { value: 'Comment 1' } });
334338
wrapper.find('Comments').find('textarea').simulate('change', { target: { value: 'Comment 1 body' } });
@@ -337,6 +341,7 @@ describe('<App />', () => {
337341
paragraphs = wrapper.find('Comments').find('p');
338342
expect(paragraphs.length).to.equals(1);
339343
expect(paragraphs.at(0).html()).to.equals('<p>Comment 1 body</p>');
344+
expect(wrapper.find('Stats').contains(<div><span>comments : </span><span>1</span></div>));
340345

341346
history.goBack();
342347
history.goBack();

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const comments = {
7272

7373
window.fetch = (url, post) => {
7474
if (url.startsWith('/api/likes')) {
75-
return promise({ json: () => ({ count: Object.keys(comments).filter(k => comments[k]).length }) });
75+
return promise({ json: () => ({ count: Object.keys(likes).filter(k => likes[k]).length }) });
7676
}
7777
if (url.startsWith('/api/comments')) {
7878
return promise({ json: () => ({ count: Object.keys(comments).map(k => comments[k].length).reduce((a, b) => a + b) }) });
@@ -279,7 +279,7 @@ describe('<App />', () => {
279279
});
280280
});
281281

282-
it('doit afficher un vin et le liker', () => {
282+
it('doit afficher un vin et le liker tout en incrémentant les stats globales', () => {
283283
const history = createMemoryHistory(window.location);
284284
const wrapper = mount(
285285
<App history={history} />
@@ -294,18 +294,23 @@ describe('<App />', () => {
294294
const like = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'like');
295295
expect(like.length).to.equal(1);
296296

297+
expect(wrapper.find('Stats').contains(<div><span>likes : </span><span>0</span></div>));
298+
297299
like.simulate('click');
298300

299301
const like2 = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'unlike');
300302
expect(like2.length).to.equal(1);
301303

304+
expect(wrapper.find('Stats').contains(<div><span>likes : </span><span>1</span></div>));
305+
302306
like2.simulate('click');
303307

304308
const like3 = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'like');
305309
expect(like3.length).to.equal(1);
310+
expect(wrapper.find('Stats').contains(<div><span>likes : </span><span>0</span></div>));
306311
});
307312

308-
it('doit afficher un vin et poster un commentaire', () => {
313+
it('doit afficher un vin et poster un commentaire tout en incrémentant les stats globales', () => {
309314
const history = createMemoryHistory(window.location);
310315
const wrapper = mount(
311316
<App history={history} />
@@ -322,12 +327,15 @@ describe('<App />', () => {
322327
let paragraphs = wrapper.find('Comments').find('p');
323328
expect(paragraphs.length).to.equals(0);
324329

330+
expect(wrapper.find('Stats').contains(<div><span>comments : </span><span>0</span></div>));
331+
325332
wrapper.find('Comments').find('input').simulate('change', { target: { value: 'Comment 1' } });
326333
wrapper.find('Comments').find('textarea').simulate('change', { target: { value: 'Comment 1 body' } });
327334
wrapper.find('Comments').find('button').simulate('click');
328335

329336
paragraphs = wrapper.find('Comments').find('p');
330337
expect(paragraphs.length).to.equals(1);
331338
expect(paragraphs.at(0).html()).to.equals('<p>Comment 1 body</p>');
339+
expect(wrapper.find('Stats').contains(<div><span>comments : </span><span>1</span></div>));
332340
});
333341
});

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const comments = {
7777

7878
window.fetch = (url, post) => {
7979
if (url.startsWith('/api/likes')) {
80-
return promise({ json: () => ({ count: Object.keys(comments).filter(k => comments[k]).length }) });
80+
return promise({ json: () => ({ count: Object.keys(likes).filter(k => likes[k]).length }) });
8181
}
8282
if (url.startsWith('/api/comments')) {
8383
return promise({ json: () => ({ count: Object.keys(comments).map(k => comments[k].length).reduce((a, b) => a + b) }) });
@@ -284,7 +284,7 @@ describe('<App />', () => {
284284
});
285285
});
286286

287-
it('doit afficher un vin et le liker', () => {
287+
it('doit afficher un vin et le liker tout en incrémentant les stats globales', () => {
288288
const history = createMemoryHistory(window.location);
289289
const wrapper = mount(
290290
<App history={history} />
@@ -298,22 +298,25 @@ describe('<App />', () => {
298298

299299
const like = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'like');
300300
expect(like.length).to.equal(1);
301+
expect(wrapper.find('Stats').contains(<div><span>likes : </span><span>0</span></div>));
301302

302303
like.simulate('click');
303304

304305
const like2 = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'unlike');
305306
expect(like2.length).to.equal(1);
307+
expect(wrapper.find('Stats').contains(<div><span>likes : </span><span>1</span></div>));
306308

307309
like2.simulate('click');
308310

309311
const like3 = wrapper.find('Wine').find('span').filterWhere(n => n.get(0).innerHTML === 'like');
310312
expect(like3.length).to.equal(1);
313+
expect(wrapper.find('Stats').contains(<div><span>likes : </span><span>0</span></div>));
311314

312315
history.goBack();
313316
history.goBack();
314317
});
315318

316-
it('doit afficher un vin et poster un commentaire', () => {
319+
it('doit afficher un vin et poster un commentaire tout en incrémentant les stats globales', () => {
317320
const history = createMemoryHistory(window.location);
318321
const wrapper = mount(
319322
<App history={history} />
@@ -329,6 +332,7 @@ describe('<App />', () => {
329332

330333
let paragraphs = wrapper.find('Comments').find('p');
331334
expect(paragraphs.length).to.equals(0);
335+
expect(wrapper.find('Stats').contains(<div><span>comments : </span><span>0</span></div>));
332336

333337
wrapper.find('Comments').find('input').simulate('change', { target: { value: 'Comment 1' } });
334338
wrapper.find('Comments').find('textarea').simulate('change', { target: { value: 'Comment 1 body' } });
@@ -337,6 +341,7 @@ describe('<App />', () => {
337341
paragraphs = wrapper.find('Comments').find('p');
338342
expect(paragraphs.length).to.equals(1);
339343
expect(paragraphs.at(0).html()).to.equals('<p>Comment 1 body</p>');
344+
expect(wrapper.find('Stats').contains(<div><span>comments : </span><span>1</span></div>));
340345

341346
history.goBack();
342347
history.goBack();

0 commit comments

Comments
 (0)