Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from GedeonTS/create-comment-counter-test
Add test to count comments on a movie
- Loading branch information
Showing
2 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const comments = (commentList) => { | ||
let counter; | ||
commentList.forEach((comment, index) => { | ||
counter = index + 1; | ||
}); | ||
return counter; | ||
}; | ||
|
||
export default comments; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |