Skip to content

Commit

Permalink
Merge pull request #29 from GedeonTS/create-comment-counter-test
Browse files Browse the repository at this point in the history
Add test to count comments on a movie
  • Loading branch information
Lembani committed May 21, 2022
2 parents 7937c34 + f596287 commit df4b7d7
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 0 deletions.
9 changes: 9 additions & 0 deletions __mocks__/commentsCount.js
@@ -0,0 +1,9 @@
const comments = (commentList) => {
let counter;
commentList.forEach((comment, index) => {
counter = index + 1;
});
return counter;
};

export default comments;
132 changes: 132 additions & 0 deletions commentsCount.test.js
@@ -0,0 +1,132 @@
import comments from './__mocks__/commentsCount.js';

const listOne = [
{
username: 'Jane',
comment: 'Nice movie',
},
{
username: 'Sam',
comment: 'Nice movie',
},
{
username: 'John',
comment: 'Nice movie',
},
{
username: 'Ruth',
comment: 'Nice movie',
},
{
username: 'Mary',
comment: 'Nice movie',
},
{
username: 'James',
comment: 'Nice movie',
},
];

const listTwo = [
{
username: 'John',
comment: 'Nice movie',
},
{
username: 'Ruth',
comment: 'Nice movie',
},
{
username: 'Mary',
comment: 'Nice movie',
},
{
username: 'James',
comment: 'Nice movie',
},
{
username: 'Sam',
comment: 'Nice movie',
},
{
username: 'John',
comment: 'Nice movie',
},
{
username: 'Ruth',
comment: 'Nice movie',
},
{
username: 'Mary',
comment: 'Nice movie',
},
{
username: 'Natasha',
comment: 'Nice movie',
},
];

const listThree = [
{
username: 'Jane',
comment: 'Nice movie',
},
{
username: 'Ruth',
comment: 'Nice movie',
},
{
username: 'Mary',
comment: 'Nice movie',
},
];

const listFour = [
{
username: 'Josh',
comment: 'Nice movie',
},
{
username: 'John',
comment: 'Nice movie',
},
{
username: 'Ruth',
comment: 'Nice movie',
},
{
username: 'Mary',
comment: 'Nice movie',
},
{
username: 'James',
comment: 'Nice movie',
},
{
username: 'Sam',
comment: 'Nice movie',
},
{
username: 'John',
comment: 'Nice movie',
},
{
username: 'Ruth',
comment: 'Nice movie',
},
];

describe('Should test the number of comments on each movie', () => {
test('Test the number of comments', () => {
expect(comments(listOne)).toBe(6);
});
test('Test the number of comments', () => {
expect(comments(listTwo)).toBe(9);
});
test('Test the number of comments', () => {
expect(comments(listThree)).toBe(3);
});
test('Test the number of comments', () => {
expect(comments(listFour)).toBe(8);
});
});

0 comments on commit df4b7d7

Please sign in to comment.