-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcore.test.js
89 lines (74 loc) · 2.29 KB
/
core.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import React from "react";
import {
cleanup,
fireEvent,
render,
screen,
waitFor,
} from "@testing-library/react";
import "@testing-library/jest-dom/extend-expect";
import response from "../stories/document-1607876232180.json";
import Extract from "./extract";
import { Default, BaseWeb } from "../stories/Codelabs.stories";
afterEach(cleanup);
test("Extract parses the document", () => {
const tree = Extract.parse(response, ["nemethgergely.com"]);
expect(tree).toMatchSnapshot();
});
test("Page can be navigated using the side navigation", async () => {
render(<Default />);
fireEvent.click(screen.getByText("Getting set up"));
expect(screen.getByText("2. Getting set up")).toBeInTheDocument();
});
test("Initial page is set to Page 2", async () => {
render(<BaseWeb />);
expect(screen.getByText("2. Getting set up")).toBeInTheDocument();
});
test("Copy component displays on hover and is clickable", async () => {
render(<BaseWeb />);
const button = screen.getByRole("button", { name: "Copy" });
expect(button).not.toBeVisible();
// test hovering the snippet container
fireEvent(
screen.getByText(
"https://api.darksky.net/forecast/DARKSKY_API_KEY/40.7720232,-73.9732319"
),
new MouseEvent("mouseover", {
bubbles: true,
cancelable: true,
})
);
expect(button).toBeVisible();
// test copying
fireEvent.click(button);
expect(button.textContent).toBe("Copied");
});
test("Page can be navigated using the buttons at the bottom of the page", async () => {
render(<Default />);
// navigate to the next page
fireEvent.click(
screen.getByRole("button", {
name: "Next",
})
);
expect(screen.getByText("2. Getting set up")).toBeInTheDocument();
// navigate to the previous page
fireEvent.click(
screen.getByRole("button", {
name: "Previous",
})
);
expect(screen.getByText("1. Introduction")).toBeInTheDocument();
// now the previous button should be disabled
const button = screen.getByRole("button", { name: "Previous" });
expect(button).toBeDisabled();
});
test("In page navigation is present", async () => {
render(<Default />);
fireEvent.click(screen.getByText("Getting set up"));
expect(
screen.getByRole("link", {
name: "Get a key for the Dark Sky API",
})
).toBeInTheDocument();
});