11/** @jest -environment jsdom */
2-
2+ // import { countComments } from './comment_handler.js';
33describe ( '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