Skip to content

Commit d71a842

Browse files
committed
Refactor reading list functionality and update styles for read/unread books
1 parent 805fee7 commit d71a842

File tree

6 files changed

+47
-9
lines changed

6 files changed

+47
-9
lines changed

Sprint-3/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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": [
@@ -26,7 +26,7 @@
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
}

Sprint-3/reading-list/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
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">

Sprint-3/reading-list/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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",
@@ -13,5 +13,8 @@
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
}

Sprint-3/reading-list/script.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff 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();

Sprint-3/reading-list/script.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require("@testing-library/jest-dom");
12
const path = require("path");
23
const { 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
});

Sprint-3/reading-list/style.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)