-
Notifications
You must be signed in to change notification settings - Fork 6
/
router.spec.js
108 lines (91 loc) · 3.35 KB
/
router.spec.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { expect, test } from "@playwright/test";
import {
pauseIfVideoRecording,
waitForSelectorToBeVisible,
} from "../testUtils";
test("Verify default route loads successfully and displays expected content", async ({
page,
}) => {
// Navigate to the default route
await page.goto("/");
await page.evaluate(() => {
const config = JSON.stringify({ "vm": { "features": {"enableComponentSrcDataKey": true }}})
document.body.innerHTML = `
<near-social-viewer src="devs.near/widget/default" initialprops='{"message": "hello world!"}' config='${config}'></near-social-viewer>
`;
});
// Verify the viewer's default route
await waitForSelectorToBeVisible(
page,
'near-social-viewer[src="devs.near/widget/default"]'
);
// Get the value of the initialProps attribute
const initialProps = await page.evaluate(() => {
const viewer = document.querySelector(
'near-social-viewer[src="devs.near/widget/default"]'
);
return viewer.getAttribute("initialProps");
});
// Assert initialProps parse correctly
expect(JSON.parse(initialProps)).toEqual({ message: "hello world!" });
// Verify default component renders
await waitForSelectorToBeVisible(
page,
'div[data-component="devs.near/widget/default"]'
);
// Verify default props are active
await waitForSelectorToBeVisible(page, 'h4:has-text("hello world!")');
await pauseIfVideoRecording(page, 1000);
});
test("should load the other routes with params when provided", async ({
page,
}) => {
// // Navigate to some route
await page.goto("/efiz.near/widget/Tree?rootPath=devs.near");
// Verify route loads
await waitForSelectorToBeVisible(
page,
'body > near-social-viewer > div > div > div > div'
);
// Verify provided props are active
await waitForSelectorToBeVisible(page, 'div:has-text("devs.near")');
await pauseIfVideoRecording(page, 1000);
});
test("should be possible to set initialProps and src widget for the root path", async ({
page,
}) => {
await page.goto("/");
await page.evaluate(() => {
const config = JSON.stringify({ "vm": { "features": {"enableComponentSrcDataKey": true }}})
document.body.innerHTML = `
<near-social-viewer src="devhub.near/widget/app" initialProps='{"page": "community", "handle": "webassemblymusic"}' config='${config}'></near-social-viewer>
`;
});
await expect(
await page.getByText("WebAssembly Music", { exact: true })
).toBeVisible({ timeout: 10000 });
});
test("for supporting SEO friendly URLs, it should be possible to set initialProps and src widget from any path", async ({
page,
}) => {
await page.goto("/community/webassemblymusic");
await page.evaluate(() => {
const viewerElement = document.querySelector("near-social-viewer");
viewerElement.setAttribute("src", "devhub.near/widget/app");
const pathparts = location.pathname.split("/");
viewerElement.setAttribute(
"initialProps",
JSON.stringify({ page: pathparts[1], handle: pathparts[2] })
);
});
await expect(
await page.getByText("WebAssembly Music", { exact: true })
).toBeVisible();
});
test("should be able to load a widget from the path", async ({ page }) => {
await page.goto("/petersalomonsen.near/widget/aliens_close");
const playButton = await page
.frameLocator("iframe")
.getByRole("button", { name: "▶" });
await expect(playButton).toBeVisible();
});