Skip to content

Commit b0cd681

Browse files
committed
#3414 webpage: algolia and matomo tests
Signed-off-by: Patrizio Bekerle <[email protected]>
1 parent b8ce427 commit b0cd681

File tree

2 files changed

+162
-0
lines changed

2 files changed

+162
-0
lines changed

webpage/tests/algolia.spec.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// @ts-check
2+
import { test, expect } from "./fixtures.js";
3+
4+
test("overview page has Algolia search field", async ({ page, config }) => {
5+
await page.goto(config.baseURL + "/getting-started/overview.html");
6+
7+
// Check Algolia search input exists
8+
const searchInput = page.locator("#algolia-search-input");
9+
await expect(searchInput).toBeVisible();
10+
11+
// Verify it has the correct Algolia DocSearch classes
12+
await expect(searchInput).toHaveClass(/search-query/);
13+
await expect(searchInput).toHaveClass(/ds-input/);
14+
15+
// Verify the search input is a combobox
16+
await expect(
17+
page.getByRole("combobox", { name: "search input" }),
18+
).toBeVisible();
19+
});
20+
21+
test("frontpage has Algolia search field", async ({ page, config }) => {
22+
await page.goto(config.baseURL);
23+
24+
// Check Algolia search input exists on frontpage
25+
const searchInput = page.locator("#algolia-search-input");
26+
await expect(searchInput).toBeVisible();
27+
28+
// Verify it's a combobox
29+
await expect(
30+
page.getByRole("combobox", { name: "search input" }),
31+
).toBeVisible();
32+
});
33+
34+
test("blog page has Algolia search field", async ({ page, config }) => {
35+
await page.goto(config.baseURL + "/blog/");
36+
37+
// Check Algolia search input exists on blog page
38+
const searchInput = page.locator("#algolia-search-input");
39+
await expect(searchInput).toBeVisible();
40+
});

webpage/tests/matomo.spec.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// @ts-check
2+
import { test, expect } from "./fixtures.js";
3+
4+
test("Matomo tracking script is loaded", async ({ page, config }) => {
5+
await page.goto(config.baseURL);
6+
7+
// Check if _paq object exists (Matomo tracking array)
8+
const hasPaq = await page.evaluate(() => typeof window._paq !== "undefined");
9+
expect(hasPaq).toBeTruthy();
10+
});
11+
12+
test("Matomo tracking requests are sent", async ({ page, config }) => {
13+
// Track all network requests
14+
const matomoRequests = [];
15+
16+
page.on("request", (request) => {
17+
const url = request.url();
18+
// Check for Matomo tracking requests (matomo.php or piwik.php)
19+
if (url.includes("matomo.php") || url.includes("piwik.php")) {
20+
matomoRequests.push({
21+
url: url,
22+
method: request.method(),
23+
postData: request.postData(),
24+
});
25+
}
26+
});
27+
28+
// Navigate to the page
29+
await page.goto(config.baseURL);
30+
31+
// Wait a bit for tracking to be sent
32+
await page.waitForTimeout(2000);
33+
34+
// Verify that at least one Matomo tracking request was sent
35+
expect(matomoRequests.length).toBeGreaterThan(0);
36+
37+
// Verify the tracking request contains expected parameters
38+
const firstRequest = matomoRequests[0];
39+
expect(firstRequest.url).toMatch(/matomo\.php|piwik\.php/);
40+
});
41+
42+
test("Matomo tracking includes site ID", async ({ page, config }) => {
43+
// Track Matomo requests
44+
let matomoRequestUrl = null;
45+
46+
page.on("request", (request) => {
47+
const url = request.url();
48+
if (url.includes("matomo.php") || url.includes("piwik.php")) {
49+
matomoRequestUrl = url;
50+
}
51+
});
52+
53+
await page.goto(config.baseURL);
54+
await page.waitForTimeout(2000);
55+
56+
expect(matomoRequestUrl).not.toBeNull();
57+
58+
// Check if the request contains idsite parameter
59+
expect(matomoRequestUrl).toMatch(/idsite=\d+/);
60+
});
61+
62+
test("Matomo tracking includes page URL", async ({ page, config }) => {
63+
let matomoRequestUrl = null;
64+
65+
page.on("request", (request) => {
66+
const url = request.url();
67+
if (url.includes("matomo.php") || url.includes("piwik.php")) {
68+
matomoRequestUrl = url;
69+
}
70+
});
71+
72+
await page.goto(config.baseURL);
73+
await page.waitForTimeout(2000);
74+
75+
expect(matomoRequestUrl).not.toBeNull();
76+
77+
// Check if the request contains url parameter
78+
expect(matomoRequestUrl).toMatch(/url=/);
79+
});
80+
81+
test("Matomo tracking on blog page", async ({ page, config }) => {
82+
const matomoRequests = [];
83+
84+
page.on("request", (request) => {
85+
const url = request.url();
86+
if (url.includes("matomo.php") || url.includes("piwik.php")) {
87+
matomoRequests.push(url);
88+
}
89+
});
90+
91+
// Navigate to a blog page
92+
await page.goto(
93+
config.baseURL + "/blog/2024-05-17-AI-support-was-added-to-QOwnNotes.html",
94+
);
95+
await page.waitForTimeout(2000);
96+
97+
// Verify tracking request was sent for blog page
98+
expect(matomoRequests.length).toBeGreaterThan(0);
99+
100+
// Verify the URL in the tracking request contains the blog page path
101+
const trackingUrl = matomoRequests[0];
102+
expect(trackingUrl).toMatch(/AI-support-was-added-to-QOwnNotes/);
103+
});
104+
105+
test("Matomo server responds successfully", async ({ page, config }) => {
106+
let matomoResponse = null;
107+
108+
page.on("response", (response) => {
109+
const url = response.url();
110+
if (url.includes("matomo.php") || url.includes("piwik.php")) {
111+
matomoResponse = response;
112+
}
113+
});
114+
115+
await page.goto(config.baseURL);
116+
await page.waitForTimeout(2000);
117+
118+
expect(matomoResponse).not.toBeNull();
119+
120+
// Verify the Matomo server responds with a successful status
121+
expect(matomoResponse.status()).toBeLessThan(400);
122+
});

0 commit comments

Comments
 (0)