Skip to content

Commit fdbff2f

Browse files
committed
reuse settings page navigation, minor fixes
1 parent b57c8bb commit fdbff2f

File tree

3 files changed

+56
-77
lines changed

3 files changed

+56
-77
lines changed

plugins/wpgraphql-logging/tests/e2e/specs/basic-usage.spec.js

Lines changed: 44 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,25 @@ import {
99
import { GET_POSTS_QUERY } from "../constants";
1010

1111
test.describe("Basic Logging Usage", () => {
12-
test.beforeEach(async ({ admin }) => {
12+
test.beforeEach(async ({ admin, page }) => {
1313
await resetPluginSettings(admin);
14+
15+
// Go to settings page
16+
await goToLoggingSettingsPage(admin);
17+
await expect(page.locator("h1")).toHaveText("WPGraphQL Logging Settings");
1418
});
1519

1620
test("enables logging and logs GraphQL queries", async ({
1721
page,
1822
admin,
1923
request,
2024
}) => {
21-
// Set up logging settings
22-
await goToLoggingSettingsPage(admin);
23-
await expect(page.locator("h1")).toHaveText("WPGraphQL Logging Settings");
24-
2525
await configureLogging(page, {
2626
enabled: true,
2727
dataSampling: "100",
2828
eventLogSelection: ["graphql_request_results"],
2929
});
3030

31-
await expect(page.locator(".notice.notice-success")).toBeVisible();
32-
3331
const response = await executeGraphQLQuery(request, GET_POSTS_QUERY);
3432
expect(response.ok()).toBeTruthy();
3533

@@ -71,19 +69,17 @@ test.describe("Basic Logging Usage", () => {
7169
});
7270

7371
test("does not log when disabled", async ({ page, admin, request }) => {
72+
await configureLogging(page, {
73+
enabled: false,
74+
dataSampling: "100",
75+
});
76+
7477
// Make sure there are no logs
7578
await goToLogsListPage(admin);
7679
await expect(
7780
page.locator('td.colspanchange:has-text("No items found.")')
7881
).toBeVisible();
7982

80-
// Disable logging
81-
await goToLoggingSettingsPage(admin);
82-
await configureLogging(page, {
83-
enabled: false,
84-
dataSampling: "100",
85-
});
86-
8783
await executeGraphQLQuery(request, GET_POSTS_QUERY);
8884

8985
// Navigate to logs and verify no new logs were created
@@ -98,18 +94,12 @@ test.describe("Basic Logging Usage", () => {
9894
admin,
9995
request,
10096
}) => {
101-
// Set up logging settings
102-
await goToLoggingSettingsPage(admin);
103-
await expect(page.locator("h1")).toHaveText("WPGraphQL Logging Settings");
104-
10597
await configureLogging(page, {
10698
enabled: true,
10799
dataSampling: "100",
108100
eventLogSelection: ["graphql_request_results"],
109101
});
110102

111-
await expect(page.locator(".notice.notice-success")).toBeVisible();
112-
113103
// Execute a GraphQL query
114104
const response = await executeGraphQLQuery(request, GET_POSTS_QUERY);
115105
expect(response.ok()).toBeTruthy();
@@ -150,42 +140,38 @@ test.describe("Basic Logging Usage", () => {
150140
expect(content).toContain("GetPosts");
151141
});
152142

153-
// test("should set data sampling to 10% and verify only 1 log is created", async ({
154-
// page,
155-
// admin,
156-
// request,
157-
// }) => {
158-
// // Set up logging settings
159-
// await goToLoggingSettingsPage(admin);
160-
// await expect(page.locator("h1")).toHaveText("WPGraphQL Logging Settings");
161-
162-
// await configureLogging(page, {
163-
// enabled: true,
164-
// dataSampling: "50",
165-
// eventLogSelection: ["graphql_request_results"],
166-
// });
167-
168-
// await expect(page.locator(".notice.notice-success")).toBeVisible();
169-
170-
// // Execute a GraphQL queries
171-
// const responses = await Promise.all(
172-
// Array.from({ length: 10 }, async () =>
173-
// executeGraphQLQuery(request, GET_POSTS_QUERY)
174-
// )
175-
// );
176-
// await Promise.all(
177-
// responses.map(async (response) => {
178-
// return expect(response.ok()).toBeTruthy();
179-
// })
180-
// );
181-
182-
// // Navigate to logs and verify no new logs were created
183-
// await goToLogsListPage(admin);
184-
// await expect(page.locator("h1")).toContainText("WPGraphQL Logs");
185-
186-
// const logRow = page.locator("#the-list tr").filter({ hasText: "GetPosts" });
187-
188-
// const logCount = await logRow.count();
189-
// expect(logCount).toBeLessThanOrEqual(5);
190-
// });
143+
test("should set data sampling to 10% and verify only 1 log is created", async ({
144+
page,
145+
admin,
146+
request,
147+
}) => {
148+
const QUERY_COUNT = 5;
149+
150+
await configureLogging(page, {
151+
enabled: true,
152+
dataSampling: "25",
153+
eventLogSelection: ["graphql_request_results"],
154+
});
155+
156+
// Execute a GraphQL queries
157+
const responses = await Promise.all(
158+
Array.from({ length: QUERY_COUNT }, async () =>
159+
executeGraphQLQuery(request, GET_POSTS_QUERY)
160+
)
161+
);
162+
await Promise.all(
163+
responses.map(async (response) => {
164+
return expect(response.ok()).toBeTruthy();
165+
})
166+
);
167+
168+
// Navigate to logs and verify no new logs were created
169+
await goToLogsListPage(admin);
170+
await expect(page.locator("h1")).toContainText("WPGraphQL Logs");
171+
172+
const logRow = page.locator("#the-list tr").filter({ hasText: "GetPosts" });
173+
174+
const logCount = await logRow.count();
175+
expect(logCount).toBeLessThan(QUERY_COUNT);
176+
});
191177
});

plugins/wpgraphql-logging/tests/e2e/specs/data-cleanup.spec.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,24 @@ import {
77
} from "../utils";
88

99
test.describe("Data Management", () => {
10-
test.beforeEach(async ({ admin }) => {
10+
test.beforeEach(async ({ admin, page }) => {
1111
await resetPluginSettings(admin);
12+
13+
// Go to settings page
14+
await goToLoggingSettingsPage(admin);
15+
await expect(page.locator("h1")).toHaveText("WPGraphQL Logging Settings");
1216
});
1317

1418
test("configures data deletion and verifies cron job", async ({
1519
page,
1620
admin,
1721
}) => {
18-
// Set up logging settings
19-
await goToLoggingSettingsPage(admin);
20-
await expect(page.locator("h1")).toHaveText("WPGraphQL Logging Settings");
21-
2222
await configureDataManagement(page, {
2323
dataDeletionEnabled: true,
2424
dataRetentionDays: "7",
2525
dataSanitizationEnabled: false,
2626
});
2727

28-
await expect(page.locator(".notice.notice-success")).toBeVisible();
29-
3028
// Reload the page to verify settings persisted
3129
await page.reload({ waitUntil: "networkidle" });
3230

plugins/wpgraphql-logging/tests/e2e/specs/exclude-and-sanitize.spec.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,31 @@ import {
66
configureDataManagement,
77
executeGraphQLQuery,
88
resetPluginSettings,
9+
switchToSettingsTab,
910
} from "../utils";
1011
import { GET_POSTS_QUERY } from "../constants";
1112

1213
test.describe("Query Filtering & Data Privacy", () => {
13-
test.beforeEach(async ({ admin }) => {
14+
test.beforeEach(async ({ admin, page }) => {
1415
await resetPluginSettings(admin);
16+
17+
// Go to settings page
18+
await goToLoggingSettingsPage(admin);
19+
await expect(page.locator("h1")).toHaveText("WPGraphQL Logging Settings");
1520
});
1621

1722
test("excludes configured queries from logs", async ({
1823
page,
1924
admin,
2025
request,
2126
}) => {
22-
// Set up logging with GetPosts excluded
23-
await goToLoggingSettingsPage(admin);
24-
await expect(page.locator("h1")).toHaveText("WPGraphQL Logging Settings");
25-
2627
await configureLogging(page, {
2728
enabled: true,
2829
dataSampling: "100",
2930
eventLogSelection: ["graphql_request_results"],
3031
excludeQueries: "GetPosts",
3132
});
3233

33-
await expect(page.locator(".notice.notice-success")).toBeVisible();
34-
3534
// Execute the excluded query
3635
const response = await executeGraphQLQuery(request, GET_POSTS_QUERY);
3736
expect(response.ok()).toBeTruthy();
@@ -46,17 +45,13 @@ test.describe("Query Filtering & Data Privacy", () => {
4645
});
4746

4847
test("sanitizes sensitive data in logs", async ({ page, admin, request }) => {
49-
// Set up logging settings and execute a GraphQL query
50-
await goToLoggingSettingsPage(admin);
51-
await expect(page.locator("h1")).toHaveText("WPGraphQL Logging Settings");
52-
5348
await configureLogging(page, {
5449
enabled: true,
5550
dataSampling: "100",
5651
eventLogSelection: ["graphql_request_results"],
5752
});
5853

59-
await goToLoggingSettingsPage(admin);
54+
await switchToSettingsTab(page, "Data Management");
6055
await configureDataManagement(page, {
6156
dataSanitizationEnabled: true,
6257
dataSanitizationMethod: "custom",

0 commit comments

Comments
 (0)