File tree Expand file tree Collapse file tree 6 files changed +47
-9
lines changed
Expand file tree Collapse file tree 6 files changed +47
-9
lines changed Original file line number Diff line number Diff line change 44 "license" : " CC-BY-SA-4.0" ,
55 "description" : " " ,
66 "scripts" : {
7- "test" : " jest" ,
7+ "test" : " jest --config=../jest.config.js reading-list " ,
88 "format" : " prettier --write ."
99 },
1010 "workspaces" : [
2626 "@testing-library/dom" : " ^10.4.0" ,
2727 "@testing-library/jest-dom" : " ^6.6.3" ,
2828 "@testing-library/user-event" : " ^14.6.1" ,
29- "jest" : " ^30.0.4 " ,
29+ "jest" : " ^30.2.0 " ,
3030 "jest-environment-jsdom" : " ^30.0.4"
3131 }
3232}
Original file line number Diff line number Diff line change 1- <!DOCTYPE >
1+ <!DOCTYPE html >
22< html lang ="en_US ">
33 < head >
44 < meta charset ="utf-8 " />
55 < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
66 < link rel ="stylesheet " href ="style.css " />
7- < title > Title here </ title >
7+ < title > Reading list app </ title >
88 </ head >
99 < body >
1010 < div id ="content ">
Original file line number Diff line number Diff line change 44 "license" : " CC-BY-SA-4.0" ,
55 "description" : " You must update this package" ,
66 "scripts" : {
7- "test" : " jest --config=../jest.config.js reading-list "
7+ "test" : " jest"
88 },
99 "repository" : {
1010 "type" : " git" ,
1313 "bugs" : {
1414 "url" : " https://github.com/CodeYourFuture/CYF-Coursework-Template/issues"
1515 },
16- "homepage" : " https://github.com/CodeYourFuture/CYF-Coursework-Template#readme"
16+ "homepage" : " https://github.com/CodeYourFuture/CYF-Coursework-Template#readme" ,
17+ "devDependencies" : {
18+ "@testing-library/jest-dom" : " ^6.9.1"
19+ }
1720}
Original file line number Diff line number Diff line change @@ -20,4 +20,29 @@ const books = [
2020 bookCoverImage : "https://blackwells.co.uk/jacket/l/9780135957059.jpg" ,
2121 } ,
2222] ;
23+ function readingList ( ) {
24+ const unorderedList = document . querySelector ( "#reading-list" ) ;
2325
26+ for ( const book of books ) {
27+ const newList = document . createElement ( "li" ) ;
28+
29+ const newImage = document . createElement ( "img" ) ;
30+ newImage . src = book . bookCoverImage ;
31+
32+ const paragraph = document . createElement ( "p" ) ;
33+ paragraph . textContent = `${ book . title } by ${ book . author } ` ;
34+
35+ newList . append ( paragraph , newImage ) ;
36+
37+ // Apply classes expected by the test
38+ if ( book . alreadyRead ) {
39+ newList . classList . add ( "read" ) ;
40+ } else {
41+ newList . classList . add ( "notRead" ) ;
42+ }
43+
44+ unorderedList . appendChild ( newList ) ;
45+ }
46+ }
47+
48+ readingList ( ) ;
Original file line number Diff line number Diff line change 1+ require ( "@testing-library/jest-dom" ) ;
12const path = require ( "path" ) ;
23const { JSDOM } = require ( "jsdom" ) ;
34
@@ -67,16 +68,16 @@ describe("Reading list", () => {
6768 const firstLi = page . window . document . querySelector (
6869 "#reading-list > :first-child"
6970 ) ;
70- expect ( firstLi ) . toHaveStyle ( { backgroundColor : "red" } ) ;
71+ expect ( firstLi ) . toHaveClass ( "notRead" ) ;
7172
7273 const secondLi = page . window . document . querySelector (
7374 "#reading-list > :nth-child(2)"
7475 ) ;
75- expect ( secondLi ) . toHaveStyle ( { backgroundColor : "green" } ) ;
76+ expect ( secondLi ) . toHaveClass ( "read" ) ;
7677
7778 const thirdLi = page . window . document . querySelector (
7879 "#reading-list > :nth-child(3)"
7980 ) ;
80- expect ( thirdLi ) . toHaveStyle ( { backgroundColor : "green" } ) ;
81+ expect ( thirdLi ) . toHaveClass ( "read" ) ;
8182 } ) ;
8283} ) ;
Original file line number Diff line number Diff line change @@ -157,3 +157,12 @@ body {
157157 max-height : 80px ;
158158 }
159159}
160+ .red {
161+ background-color : red;
162+ }
163+ .read {
164+ background-color : green;
165+ }
166+ .notRead {
167+ background-color : red;
168+ }
You can’t perform that action at this time.
0 commit comments