1- const fs = require ( "fs" ) ;
2- const path = require ( "path" ) ;
3- const html = fs . readFileSync ( path . resolve ( __dirname , "./index.html " ) , "utf8" ) ;
1+ const fs = require ( "fs" ) ;
2+ const path = require ( "path" ) ;
3+ const css = fs . readFileSync ( path . resolve ( __dirname , "./styles.css " ) , "utf8" ) ;
44
55jest . dontMock ( "fs" ) ;
66
7- describe ( "The lists should be modified accordingly" , function ( ) {
8- beforeEach ( ( ) => {
9- //here I import the HTML into the document
10- document . documentElement . innerHTML = html . toString ( ) ;
11- } ) ;
12- afterEach ( ( ) => {
13- jest . resetModules ( ) ;
14- } ) ;
15-
16- it ( "You should not change the existing head tag elements" , function ( ) {
17- let head = document . querySelector ( 'head' ) ;
18- let title = head . querySelector ( 'title' ) . innerHTML ;
19-
20- expect ( title ) . toBe ( '04 List styling' )
21- } )
22-
23- // Test in progress:
24- // it("The lists should be correctly styled", function() {
25- // const uls = document.querySelectorAll("ul");
26- // const ols = document.querySelectorAll("ol");
27- // console.log(uls);
28- // console.log(ols);
29-
30- // var style1 = window.getComputedStyle(ols[0]);
31- // var style2 = window.getComputedStyle(uls[0]);
32- // var style3 = window.getComputedStyle(ols[1]);
33- // var style4 = window.getComputedStyle(uls[1]);
34-
35-
36- // expect(style1["listStyleType"]).toBe("lower-alpha");
37- // expect(style2["listStyleType"]).toBe("square");
38- // expect(style3["listStyleType"]).toBe("armenian");
39- // expect(style4["listStyleType"]).toBe("none");
40-
41- // });
42- } ) ;
7+ describe ( "CSS Styles" , ( ) => {
8+ beforeAll ( ( ) => {
9+ document . querySelector ( "head" ) . innerHTML = `<style>${ css . toString ( ) } </style>` ;
10+ } ) ;
11+
12+ test ( "Cocacola list style should be applied correctly" , ( ) => {
13+ const cocacolaItems = document . querySelectorAll ( ".cocacola" ) ;
14+ cocacolaItems . forEach ( item => {
15+ expect ( getComputedStyle ( item ) . listStyleType ) . toBe ( "lower-alpha" ) ;
16+ } ) ;
17+ } ) ;
18+
19+ test ( "Pepsi list style should be applied correctly" , ( ) => {
20+ const pepsiItems = document . querySelectorAll ( ".pepsi" ) ;
21+ pepsiItems . forEach ( item => {
22+ expect ( getComputedStyle ( item ) . listStyleType ) . toBe ( "square" ) ;
23+ } ) ;
24+ } ) ;
25+
26+ test ( "Healthy list style should be applied correctly" , ( ) => {
27+ const healthyItems = document . querySelectorAll ( ".healthy" ) ;
28+ healthyItems . forEach ( item => {
29+ expect ( getComputedStyle ( item ) . listStyleType ) . toBe ( "armenian" ) ;
30+ } ) ;
31+ } ) ;
32+
33+ test ( "Dev-drinks list style should be applied correctly" , ( ) => {
34+ const devDrinksItems = document . querySelectorAll ( ".dev-drinks" ) ;
35+ devDrinksItems . forEach ( item => {
36+ expect ( getComputedStyle ( item ) . listStyleType ) . toBe ( "none" ) ;
37+ } ) ;
38+ } ) ;
39+ } ) ;
0 commit comments