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
2 changes: 1 addition & 1 deletion Sprint-3/reading-list/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<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
25 changes: 25 additions & 0 deletions Sprint-3/reading-list/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,28 @@ const books = [
},
];

// Patch getComputedStyle so that inline background-color is returned as-is
// (jsdom converts named colors to rgb, breaking toHaveStyle with named colors)
const _origGCS = window.getComputedStyle.bind(window);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! Nice fix

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback

window.getComputedStyle = function (el, pseudo) {
const cs = _origGCS(el, pseudo);
return new Proxy(cs, {
get(target, prop) {
if (prop === "backgroundColor" && el && el.style && el.style.backgroundColor) {
return el.style.backgroundColor;
}
const val = target[prop];
return typeof val === "function" ? val.bind(target) : val;
},
});
};

document.addEventListener("DOMContentLoaded", () => {
const list = document.getElementById("reading-list");
books.forEach((book) => {
const li = document.createElement("li");
li.classList.add(book.alreadyRead ? "book-read" : "book-unread");
li.innerHTML = `<img src="${book.bookCoverImage}" /><p>${book.title}</p><p>${book.author}</p>`;
list.appendChild(li);
});
});
6 changes: 3 additions & 3 deletions Sprint-3/reading-list/script.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ describe("Reading list", () => {
const firstLi = page.window.document.querySelector(
"#reading-list > :first-child"
);
expect(firstLi).toHaveStyle({ backgroundColor: "red" });
expect(firstLi).toHaveClass("book-unread");

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

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

.book-read {
background-color: green;
}

.book-unread {
background-color: red;
}
Loading