| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  | import { test, expect } from '@grafana/plugin-e2e'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-08 23:57:39 +08:00
										 |  |  | import longTraceResponse from '../fixtures/long-trace-response.json'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test.describe( | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |   'Trace view', | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     tag: ['@various'], | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   () => { | 
					
						
							|  |  |  |     test('Can lazy load big traces', async ({ page, selectors }) => { | 
					
						
							|  |  |  |       // Mock the API response
 | 
					
						
							| 
									
										
										
										
											2025-09-08 23:57:39 +08:00
										 |  |  |       await page.route('**/api/ds/query?ds_type=jaeger*', async (route) => { | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |         await route.fulfill({ | 
					
						
							|  |  |  |           status: 200, | 
					
						
							|  |  |  |           contentType: 'application/json', | 
					
						
							|  |  |  |           body: JSON.stringify(longTraceResponse), | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Navigate to Explore page
 | 
					
						
							|  |  |  |       await page.goto(selectors.pages.Explore.url); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Select the Jaeger data source
 | 
					
						
							|  |  |  |       const dataSourcePicker = page.getByTestId(selectors.components.DataSourcePicker.container); | 
					
						
							|  |  |  |       await dataSourcePicker.click(); | 
					
						
							|  |  |  |       const datasourceList = page.getByTestId(selectors.components.DataSourcePicker.dataSourceList); | 
					
						
							|  |  |  |       await datasourceList.getByText('gdev-jaeger').click(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Check that gdev-jaeger is visible in the query editor
 | 
					
						
							| 
									
										
										
										
											2025-10-02 16:29:10 +08:00
										 |  |  |       await expect(page.getByTestId('query-editor-row').getByText('(gdev-jaeger)')).toBeVisible(); | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // Type the query
 | 
					
						
							|  |  |  |       const queryField = page | 
					
						
							|  |  |  |         .getByTestId(selectors.components.QueryField.container) | 
					
						
							|  |  |  |         .locator('[contenteditable="true"]'); | 
					
						
							|  |  |  |       await queryField.fill('trace'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Use Shift+Enter to execute the query
 | 
					
						
							|  |  |  |       await queryField.press('Shift+Enter'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-02 16:29:10 +08:00
										 |  |  |       // Wait for the trace viewer to be ready
 | 
					
						
							|  |  |  |       await expect(page.getByRole('switch', { name: /api\-gateway GET/ })).toBeVisible(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Note the scrolling element is actually the first child of the scroll view, but we can use the scroll wheel on this anyway
 | 
					
						
							|  |  |  |       const scrollEl = page.getByTestId(selectors.pages.Explore.General.scrollView); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Assert that the last span is not visible in th page - it should be lazily rendered as the user scrolls
 | 
					
						
							|  |  |  |       const lastSpan = page.getByRole('switch', { name: /metrics\-collector\-last\-span GET/ }); | 
					
						
							|  |  |  |       await expect(lastSpan).not.toBeVisible(); | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-02 16:29:10 +08:00
										 |  |  |       // Scroll until the "metrics-collector-last-span GET" switch is visible
 | 
					
						
							|  |  |  |       await expect(async () => { | 
					
						
							|  |  |  |         await scrollEl.hover(); | 
					
						
							|  |  |  |         await page.mouse.wheel(0, 1000); | 
					
						
							|  |  |  |         await expect(lastSpan).toBeVisible({ timeout: 1 }); | 
					
						
							|  |  |  |       }).toPass(); | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | ); |