@@ -97,4 +97,100 @@ test.describe("Configure WPGraphQL Logging Plugin and Verify Logging Works", ()
9797 page . locator ( 'td.colspanchange:has-text("No items found.")' )
9898 ) . toBeVisible ( ) ;
9999 } ) ;
100+
101+ test ( "should download the log as CSV and verify the content" , async ( {
102+ page,
103+ admin,
104+ request,
105+ } ) => {
106+ // Set up logging settings
107+ await goToLoggingSettingsPage ( admin ) ;
108+ await expect ( page . locator ( "h1" ) ) . toHaveText ( "WPGraphQL Logging Settings" ) ;
109+
110+ await configureLogging ( page , {
111+ enabled : true ,
112+ dataSampling : "100" ,
113+ eventLogSelection : [ "graphql_request_results" ] ,
114+ } ) ;
115+
116+ await expect ( page . locator ( ".notice.notice-success" ) ) . toBeVisible ( ) ;
117+
118+ // Execute a GraphQL query
119+ const response = await executeGraphQLQuery ( request , GET_POSTS_QUERY ) ;
120+ expect ( response . ok ( ) ) . toBeTruthy ( ) ;
121+
122+ // Check that the log appears in the logs list
123+ await goToLogsListPage ( admin ) ;
124+ await expect ( page . locator ( "h1" ) ) . toContainText ( "WPGraphQL Logs" ) ;
125+
126+ const logRow = page
127+ . locator ( "#the-list tr" )
128+ . filter ( { hasText : "GetPosts" } )
129+ . first ( ) ;
130+ await expect ( logRow ) . toBeVisible ( { timeout : 10000 } ) ;
131+
132+ // View log details
133+ const downloadButton = logRow . locator ( ".row-actions .download a" ) ;
134+ await expect ( downloadButton ) . toBeVisible ( ) ;
135+
136+ const downloadPromise = page . waitForEvent ( "download" ) ;
137+ await downloadButton . focus ( ) ;
138+ await downloadButton . click ( ) ;
139+ const download = await downloadPromise ;
140+
141+ // Verify download properties
142+ expect ( download . suggestedFilename ( ) ) . toMatch ( / g r a p h q l _ l o g _ \d + \. c s v / ) ;
143+ expect ( download . suggestedFilename ( ) ) . toContain ( ".csv" ) ;
144+
145+ // Optionally save and verify the content
146+ const path = await download . path ( ) ;
147+ const fs = require ( "fs" ) ;
148+ const content = fs . readFileSync ( path , "utf8" ) ;
149+
150+ // Verify CSV contains expected data
151+ expect ( content ) . toContain ( "ID" ) ;
152+ expect ( content ) . toContain ( "Date" ) ;
153+ expect ( content ) . toContain ( "Level" ) ;
154+ expect ( content ) . toContain ( "Message" ) ;
155+ expect ( content ) . toContain ( "GetPosts" ) ;
156+ } ) ;
157+
158+ // test("should set data sampling to 10% and verify only 1 log is created", async ({
159+ // page,
160+ // admin,
161+ // request,
162+ // }) => {
163+ // // Set up logging settings
164+ // await goToLoggingSettingsPage(admin);
165+ // await expect(page.locator("h1")).toHaveText("WPGraphQL Logging Settings");
166+
167+ // await configureLogging(page, {
168+ // enabled: true,
169+ // dataSampling: "50",
170+ // eventLogSelection: ["graphql_request_results"],
171+ // });
172+
173+ // await expect(page.locator(".notice.notice-success")).toBeVisible();
174+
175+ // // Execute a GraphQL queries
176+ // const responses = await Promise.all(
177+ // Array.from({ length: 10 }, async () =>
178+ // executeGraphQLQuery(request, GET_POSTS_QUERY)
179+ // )
180+ // );
181+ // await Promise.all(
182+ // responses.map(async (response) => {
183+ // return expect(response.ok()).toBeTruthy();
184+ // })
185+ // );
186+
187+ // // Navigate to logs and verify no new logs were created
188+ // await goToLogsListPage(admin);
189+ // await expect(page.locator("h1")).toContainText("WPGraphQL Logs");
190+
191+ // const logRow = page.locator("#the-list tr").filter({ hasText: "GetPosts" });
192+
193+ // const logCount = await logRow.count();
194+ // expect(logCount).toBeLessThanOrEqual(5);
195+ // });
100196} ) ;
0 commit comments