Skip to content

Commit 095d5f3

Browse files
committed
add e2e tests for blog page
1 parent afa8f04 commit 095d5f3

1 file changed

Lines changed: 174 additions & 0 deletions

File tree

tests/e2e/blog.spec.js

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
const url = "http://localhost:3000/blog";
4+
5+
/*
6+
Try to Grab the title from the post Hello, World!
7+
Expected title: Hello, World!
8+
*/
9+
test("Hello, World!", async ({ page }) => {
10+
await page.goto(url);
11+
12+
/*
13+
1) <a href="/blog/hello-world" class="sidebarItemLink_node_modules-@docusaurus-theme-classic-lib-theme-BlogSidebar-Desktop-styles-module">Hello, World!</a> aka getByLabel('Blog recent posts navigation').getByRole('link', { name: 'Hello, World!' })
14+
2) <a itemprop="url" href="/blog/hello-world">Hello, World!</a> aka getByRole('main').getByRole('link', { name: 'Hello, World!' })
15+
*/
16+
const HelloWorldLink = page
17+
.getByRole("link", {
18+
name: "Hello, World!",
19+
})
20+
.nth(1);
21+
22+
await expect(HelloWorldLink).toBeVisible();
23+
24+
await HelloWorldLink.click();
25+
await page.waitForURL(/.*\/blog\/hello-world/);
26+
27+
const HelloWorldTitle = page.getByRole("heading", {
28+
name: "Hello, World!",
29+
level: 1,
30+
});
31+
await expect(HelloWorldTitle).toBeVisible();
32+
33+
const title = await HelloWorldTitle.textContent();
34+
expect(title).toBe("Hello, World!");
35+
});
36+
37+
/*
38+
Try to Grab the title from the post Grid.js v3
39+
Expected title: Grid.js v3
40+
*/
41+
test.describe("Blog post: Grid.js v3", async () => {
42+
test.beforeEach(async ({ page }) => {
43+
await page.goto(url);
44+
45+
/*
46+
1) <a href="/blog/gridjs-v3" class="sidebarItemLink_node_modules-@docusaurus-theme-classic-lib-theme-BlogSidebar-Desktop-styles-module">Grid.js v3</a> aka getByLabel('Blog recent posts navigation').getByRole('link', { name: 'Grid.js v3' })
47+
2) <a itemprop="url" href="/blog/gridjs-v3">Grid.js v3</a> aka getByRole('main').getByRole('link', { name: 'Grid.js v3' })
48+
*/
49+
const GridjsLink = page
50+
.getByRole("link", {
51+
name: "Grid.js v3",
52+
})
53+
.nth(1);
54+
55+
await expect(GridjsLink).toBeVisible();
56+
57+
await GridjsLink.click();
58+
await page.waitForURL(/.*\/blog\/gridjs-v3/);
59+
});
60+
61+
// Grad the h1 title "Grid.js v3"
62+
test("1. Grab the h1 title: Grid.js v3", async ({ page }) => {
63+
const GridjsTitle = page.getByRole("heading", {
64+
name: "Grid.js v3",
65+
level: 1,
66+
});
67+
await expect(GridjsTitle).toBeVisible();
68+
69+
await expect(GridjsTitle).toHaveText("Grid.js v3");
70+
});
71+
72+
// Grad the h2 title "Selection plugin"
73+
test("2. Grab the h2 title: Selection plugin", async ({ page }) => {
74+
const SelectionPluginTitle = page.getByRole("heading", {
75+
name: "Selection plugin",
76+
level: 2,
77+
});
78+
await expect(SelectionPluginTitle).toBeVisible();
79+
80+
await expect(SelectionPluginTitle).toHaveText("Selection plugin");
81+
});
82+
83+
// Grad the h2 title "Lerna"
84+
test("3. Grab the h2 title: Lerna", async ({ page }) => {
85+
const LernaTitle = page.getByRole("heading", {
86+
name: "Lerna",
87+
level: 2,
88+
});
89+
await expect(LernaTitle).toBeVisible();
90+
91+
await expect(LernaTitle).toHaveText("Lerna");
92+
});
93+
94+
test("4. Grab the h2 title: Table width algorithm", async ({ page }) => {
95+
const TableWidthAlgorithmTitle = page.getByRole("heading", {
96+
name: "Table width algorithm",
97+
level: 2,
98+
});
99+
await expect(TableWidthAlgorithmTitle).toBeVisible();
100+
101+
await expect(TableWidthAlgorithmTitle).toHaveText(
102+
"Table width algorithm",
103+
);
104+
});
105+
});
106+
107+
test.describe("Clicks all links on the blog post page: Grid.js v3", async () => {
108+
test.beforeEach(async ({ page }) => {
109+
await page.goto(url);
110+
111+
const GridjsLink = page
112+
.getByRole("link", {
113+
name: "Grid.js v3",
114+
})
115+
.nth(1);
116+
117+
await expect(GridjsLink).toBeVisible();
118+
119+
await GridjsLink.click();
120+
await page.waitForURL(/.*\/blog\/gridjs-v3/);
121+
});
122+
123+
test("1. The Github links of the author: Afshin Mehrabani", async ({
124+
page,
125+
}) => {
126+
const Authorlink = page
127+
.getByRole("link", {
128+
name: "Afshin Mehrabani",
129+
})
130+
.nth(1);
131+
await expect(Authorlink).toBeVisible();
132+
133+
const [newPage] = await Promise.all([
134+
page.context().waitForEvent("page"),
135+
Authorlink.click(),
136+
]);
137+
138+
await newPage.waitForLoadState();
139+
140+
await expect(newPage).toHaveURL("https://github.com/afshinm");
141+
});
142+
143+
test("2. selection plugin here", async ({ page }) => {
144+
const link = page.getByRole("link", { name: "selection plugin here" });
145+
await expect(link).toBeVisible();
146+
147+
await link.click();
148+
149+
// Page Not Found
150+
await expect(page).toHaveURL(
151+
"http://localhost:3000/docs/plugins/selection/index",
152+
);
153+
154+
const h1title = page.getByRole("heading", {
155+
name: "Page Not Found",
156+
level: 1,
157+
});
158+
await expect(h1title).toBeVisible();
159+
await expect(h1title).toHaveText("Page Not Found");
160+
});
161+
162+
test("3. Lerna", async ({ page }) => {
163+
const link = page.getByRole("link", { name: "Lerna" }).first();
164+
await expect(link).toBeVisible();
165+
166+
const [newPage] = await Promise.all([
167+
page.context().waitForEvent("page"),
168+
link.click(),
169+
]);
170+
171+
await newPage.waitForLoadState();
172+
await expect(newPage).toHaveURL("https://lerna.js.org/");
173+
});
174+
});

0 commit comments

Comments
 (0)