Skip to content

Commit a4d9794

Browse files
committed
Merge remote-tracking branch 'upstream/task-html-css' into solved-html-css
2 parents 42b33db + 4d43d7a commit a4d9794

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"build": "react-scripts build",
2121
"test": "react-scripts test",
2222
"test:cov": "react-scripts test --coverage --watchAll",
23+
"test:json": "react-scripts test --json --watchAll=false --outputFile jest-output.json --coverage",
2324
"eject": "react-scripts eject",
2425
"lint": "eslint ./src --ext .tsx --ext .ts --max-warnings 0",
2526
"eslint-output": "eslint-output ./src --ext .tsx --ext .ts --max-warnings 0",

public/tasks/task-html-css.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Task - HTML/CSS
2+
3+
Version: 0.0.1
4+
5+
Add in some HTML and CSS, including a fancy looking button.

src/HtmlCss.test.tsx

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import React from "react";
2+
import { render, screen } from "@testing-library/react";
3+
import App from "./App";
4+
import userEvent from "@testing-library/user-event";
5+
6+
describe("Some HTML Elements are added.", () => {
7+
test("(2 pts) There is a header", () => {
8+
render(<App />);
9+
const header = screen.getByRole("heading");
10+
expect(header).toBeInTheDocument();
11+
});
12+
13+
test("(2 pts) There is an image with alt text", () => {
14+
render(<App />);
15+
const image = screen.getByRole("img");
16+
expect(image).toBeInTheDocument();
17+
expect(image).toHaveAttribute("alt");
18+
});
19+
20+
test("(2 pts) There is a list with at least three elements", () => {
21+
render(<App />);
22+
const list = screen.getByRole("list");
23+
expect(list).toBeInTheDocument();
24+
expect(list.children.length).toBeGreaterThanOrEqual(3);
25+
});
26+
});
27+
28+
describe("(2 pts) Some basic CSS is added.", () => {
29+
test("The background color of the header area is different", () => {
30+
render(<App />);
31+
const banner = screen.getByRole("banner");
32+
expect(banner).not.toHaveStyle({
33+
"background-color": "rgb(40, 44, 52)",
34+
});
35+
});
36+
});
37+
38+
describe("(2 pts) Some Bootstrap Elements are added", () => {
39+
test("There is one bootstrap button with the text 'Log Hello World'", () => {
40+
render(<App />);
41+
const button = screen.getByRole("button", { name: /Log Hello World/i });
42+
expect(button).toBeInTheDocument();
43+
expect(button).toHaveClass("btn");
44+
expect(button).toHaveClass("btn-primary");
45+
});
46+
47+
test("(2 pts) Not clicking the bootstrap button does not logs 'Hello World!'", () => {
48+
const consoleSpy = jest.spyOn(console, "log");
49+
render(<App />);
50+
expect(consoleSpy).not.toHaveBeenCalledWith("Hello World!");
51+
});
52+
53+
test("(2 pts) Clicking the bootstrap button logs 'Hello World!'", () => {
54+
const consoleSpy = jest.spyOn(console, "log");
55+
render(<App />);
56+
const button = screen.getByRole("button", { name: /Log Hello World/i });
57+
userEvent.click(button);
58+
expect(consoleSpy).toHaveBeenCalledWith("Hello World!");
59+
});
60+
});
61+
62+
describe("Some additional CSS was added", () => {
63+
test("(2 pts) checks if any element has a background color of red", () => {
64+
const { container } = render(<App />);
65+
// Get all elements in the rendered container
66+
const elements = container.querySelectorAll("*");
67+
68+
// Check if any element has a background color of red
69+
let foundRedBackground = false;
70+
71+
elements.forEach((element) => {
72+
const style = getComputedStyle(element);
73+
if (
74+
style.backgroundColor === "red" ||
75+
style.backgroundColor === "rgb(255, 0, 0)"
76+
) {
77+
foundRedBackground = true;
78+
}
79+
});
80+
81+
expect(foundRedBackground).toBe(true);
82+
});
83+
});

0 commit comments

Comments
 (0)