@@ -9,27 +9,25 @@ import {
99import { GET_POSTS_QUERY } from "../constants" ;
1010
1111test . 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} ) ;
0 commit comments