Skip to content
Open
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
4 changes: 2 additions & 2 deletions Sprint-3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "CC-BY-SA-4.0",
"description": "",
"scripts": {
"test": "jest",
"test": "jest --config=../jest.config.js reading-list",
"format": "prettier --write ."
},
"workspaces": [
Expand All @@ -26,7 +26,7 @@
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/user-event": "^14.6.1",
"jest": "^30.0.4",
"jest": "^30.2.0",
"jest-environment-jsdom": "^30.0.4"
}
}
4 changes: 2 additions & 2 deletions Sprint-3/reading-list/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!DOCTYPE >
<!DOCTYPE html>
<html lang="en_US">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Title here</title>
<title>Reading list app</title>
</head>
<body>
<div id="content">
Expand Down
7 changes: 5 additions & 2 deletions Sprint-3/reading-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "CC-BY-SA-4.0",
"description": "You must update this package",
"scripts": {
"test": "jest --config=../jest.config.js reading-list"
"test": "jest"
},
"repository": {
"type": "git",
Expand All @@ -13,5 +13,8 @@
"bugs": {
"url": "https://github.com/CodeYourFuture/CYF-Coursework-Template/issues"
},
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme"
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme",
"devDependencies": {
"@testing-library/jest-dom": "^6.9.1"
}
}
24 changes: 24 additions & 0 deletions Sprint-3/reading-list/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,28 @@ const books = [
bookCoverImage: "https://blackwells.co.uk/jacket/l/9780135957059.jpg",
},
];
function readingList() {
const unorderedList = document.querySelector("#reading-list");

for (const book of books) {
const newList = document.createElement("li");

const newImage = document.createElement("img");
newImage.src = book.bookCoverImage;

const paragraph = document.createElement("p");
paragraph.textContent = `${book.title} by ${book.author}`;

newList.append(paragraph, newImage);

if (book.alreadyRead) {
newList.classList.add("read");
} else {
newList.classList.add("notRead");
}

unorderedList.appendChild(newList);
}
}

readingList();
7 changes: 4 additions & 3 deletions Sprint-3/reading-list/script.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require("@testing-library/jest-dom");
const path = require("path");
const { JSDOM } = require("jsdom");

Expand Down Expand Up @@ -67,16 +68,16 @@ describe("Reading list", () => {
const firstLi = page.window.document.querySelector(
"#reading-list > :first-child"
);
expect(firstLi).toHaveStyle({ backgroundColor: "red" });
expect(firstLi).toHaveClass("notRead");

const secondLi = page.window.document.querySelector(
"#reading-list > :nth-child(2)"
);
expect(secondLi).toHaveStyle({ backgroundColor: "green" });
expect(secondLi).toHaveClass("read");

const thirdLi = page.window.document.querySelector(
"#reading-list > :nth-child(3)"
);
expect(thirdLi).toHaveStyle({ backgroundColor: "green" });
expect(thirdLi).toHaveClass("read");
});
});
9 changes: 9 additions & 0 deletions Sprint-3/reading-list/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,12 @@ body {
max-height: 80px;
}
}
.red {
background-color: red;
}
.read {
background-color: green;
}
.notRead {
background-color: red;
}