Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/modules/comment_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ form.onsubmit = (e) => {
form.reset();
};

export { getDescription, getComments };
export { getDescription, getComments, countComments };
39 changes: 38 additions & 1 deletion src/modules/count.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @jest-environment jsdom */

// import { countComments } from './comment_handler.js';
describe('Homepage items counter Tests', () => {
it('Should test if showsCount is adding all shows to the home page', () => {
let counter = '';
Expand All @@ -12,4 +12,41 @@ describe('Homepage items counter Tests', () => {
showsCount();
expect(counter).toBe('Top binge-worthy shows (2)');
});

it('Count comments', () => {
document.body.innerHTML = `
<div id="posted-comments">
<div>2023-02-09 Nico: Good show.</div>
<div>2023-02-10 Neto: Test squid.</div>
<div>2023-02-10 Neto: Test squid 2.</div>
<div>2023-02-10 Neto: Test squid 3.</div></div>
`;
const count = document.querySelector('#posted-comments').children.length;
expect(count).toBe(4);
});

it('Count header', () => {
document.body.innerHTML = `
<section class="comments-section">
<h3 id="comments-header">Comments(4)</h3>
<div class="comments-container">
<div id="posted-comments">
<div>2023-02-09 Nico: Good show.</div>
<div>2023-02-10 Neto: Test squid.</div>
<div>2023-02-10 Neto: Test squid 2.</div>
<div>2023-02-10 Neto: Test squid 3.</div>
</div>
</div>
</section>
`;

let commentHeader = '';
const countComments = () => {
const count = document.querySelector('#posted-comments').children.length;
commentHeader = document.querySelector('#comments-header');
commentHeader.innerHTML = `Comments(${count})`;
};
countComments();
expect(commentHeader.innerHTML).toBe('Comments(4)');
});
});