Skip to content

Commit d83e5a4

Browse files
committed
Add test cases
1 parent 11c5fec commit d83e5a4

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/modules/comment_handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ form.onsubmit = (e) => {
6767
form.reset();
6868
};
6969

70-
export { getDescription, getComments };
70+
export { getDescription, getComments, countComments };

src/modules/count.test.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @jest-environment jsdom */
2-
2+
// import { countComments } from './comment_handler.js';
33
describe('Homepage items counter Tests', () => {
44
it('Should test if showsCount is adding all shows to the home page', () => {
55
let counter = '';
@@ -12,4 +12,41 @@ describe('Homepage items counter Tests', () => {
1212
showsCount();
1313
expect(counter).toBe('Top binge-worthy shows (2)');
1414
});
15+
16+
it('Count comments', () => {
17+
document.body.innerHTML = `
18+
<div id="posted-comments">
19+
<div>2023-02-09 Nico: Good show.</div>
20+
<div>2023-02-10 Neto: Test squid.</div>
21+
<div>2023-02-10 Neto: Test squid 2.</div>
22+
<div>2023-02-10 Neto: Test squid 3.</div></div>
23+
`;
24+
const count = document.querySelector('#posted-comments').children.length;
25+
expect(count).toBe(4);
26+
});
27+
28+
it('Count header', () => {
29+
document.body.innerHTML = `
30+
<section class="comments-section">
31+
<h3 id="comments-header">Comments(4)</h3>
32+
<div class="comments-container">
33+
<div id="posted-comments">
34+
<div>2023-02-09 Nico: Good show.</div>
35+
<div>2023-02-10 Neto: Test squid.</div>
36+
<div>2023-02-10 Neto: Test squid 2.</div>
37+
<div>2023-02-10 Neto: Test squid 3.</div>
38+
</div>
39+
</div>
40+
</section>
41+
`;
42+
43+
let commentHeader = '';
44+
const countComments = () => {
45+
const count = document.querySelector('#posted-comments').children.length;
46+
commentHeader = document.querySelector('#comments-header');
47+
commentHeader.innerHTML = `Comments(${count})`;
48+
};
49+
countComments();
50+
expect(commentHeader.innerHTML).toBe('Comments(4)');
51+
});
1552
});

0 commit comments

Comments
 (0)