Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to count comments on a movie #29

Merged
merged 1 commit into from May 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
});
});