Skip to content

Commit de9406b

Browse files
committed
refactor: use semantic CSS classes for book list styling to address code review
1 parent 703b5b3 commit de9406b

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ document.addEventListener("DOMContentLoaded", () => {
4141
const list = document.getElementById("reading-list");
4242
books.forEach((book) => {
4343
const li = document.createElement("li");
44-
li.style.backgroundColor = book.alreadyRead ? "green" : "red";
44+
li.classList.add(book.alreadyRead ? "book-read" : "book-unread");
4545
li.innerHTML = `<img src="${book.bookCoverImage}" /><p>${book.title}</p><p>${book.author}</p>`;
4646
list.appendChild(li);
4747
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ describe("Reading list", () => {
6767
const firstLi = page.window.document.querySelector(
6868
"#reading-list > :first-child"
6969
);
70-
expect(firstLi).toHaveStyle({ backgroundColor: "red" });
70+
expect(firstLi).toHaveClass("book-unread");
7171

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

7777
const thirdLi = page.window.document.querySelector(
7878
"#reading-list > :nth-child(3)"
7979
);
80-
expect(thirdLi).toHaveStyle({ backgroundColor: "green" });
80+
expect(thirdLi).toHaveClass("book-read");
8181
});
8282
});

‎Sprint-3/reading-list/style.css‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,11 @@ body {
157157
max-height: 80px;
158158
}
159159
}
160+
161+
.book-read {
162+
background-color: green;
163+
}
164+
165+
.book-unread {
166+
background-color: red;
167+
}

0 commit comments

Comments
 (0)