| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  | import { test, expect } from '@grafana/plugin-e2e'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const APP_ID = 'sandbox-app-test'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test.describe( | 
					
						
							|  |  |  |   'Datasource sandbox', | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     tag: ['@various'], | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   () => { | 
					
						
							|  |  |  |     test.beforeEach(async ({ page }) => { | 
					
						
							|  |  |  |       await page.request.post(`/api/plugins/${APP_ID}/settings`, { | 
					
						
							|  |  |  |         data: { | 
					
						
							|  |  |  |           enabled: true, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test.describe('App Page', () => { | 
					
						
							|  |  |  |       test.describe('Sandbox disabled', () => { | 
					
						
							|  |  |  |         test.beforeEach(async ({ page }) => { | 
					
						
							|  |  |  |           await page.evaluate(() => { | 
					
						
							|  |  |  |             localStorage.setItem('grafana.featureToggles', 'pluginsFrontendSandbox=0'); | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('Loads the app page without the sandbox div wrapper', async ({ page }) => { | 
					
						
							|  |  |  |           await page.goto(`/a/${APP_ID}`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           const sandboxDiv = page.locator('div[data-plugin-sandbox="sandbox-app-test"]'); | 
					
						
							|  |  |  |           await expect(sandboxDiv).toBeHidden(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           const appPage = page.getByTestId('sandbox-app-test-page-one'); | 
					
						
							| 
									
										
										
										
											2025-07-25 17:54:07 +08:00
										 |  |  |           await expect(appPage).toBeVisible(); | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('Loads the app configuration without the sandbox div wrapper', async ({ page }) => { | 
					
						
							|  |  |  |           await page.goto(`/plugins/${APP_ID}`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           const sandboxDiv = page.locator('div[data-plugin-sandbox="sandbox-app-test"]'); | 
					
						
							|  |  |  |           await expect(sandboxDiv).toBeHidden(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           const configPage = page.getByTestId('sandbox-app-test-config-page'); | 
					
						
							| 
									
										
										
										
											2025-07-25 17:54:07 +08:00
										 |  |  |           await expect(configPage).toBeVisible(); | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test.describe('Sandbox enabled', () => { | 
					
						
							|  |  |  |         test.beforeEach(async ({ page }) => { | 
					
						
							|  |  |  |           await page.evaluate(() => { | 
					
						
							|  |  |  |             localStorage.setItem('grafana.featureToggles', 'pluginsFrontendSandbox=1'); | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('Loads the app page with the sandbox div wrapper', async ({ page }) => { | 
					
						
							|  |  |  |           await page.goto(`/a/${APP_ID}`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           const sandboxDiv = page.locator('div[data-plugin-sandbox="sandbox-app-test"]'); | 
					
						
							|  |  |  |           await expect(sandboxDiv).toBeVisible(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           const appPage = page.getByTestId('sandbox-app-test-page-one'); | 
					
						
							| 
									
										
										
										
											2025-07-25 17:54:07 +08:00
										 |  |  |           await expect(appPage).toBeVisible(); | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('Loads the app configuration with the sandbox div wrapper', async ({ page }) => { | 
					
						
							|  |  |  |           await page.goto(`/plugins/${APP_ID}`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           const sandboxDiv = page.locator('div[data-plugin-sandbox="sandbox-app-test"]'); | 
					
						
							|  |  |  |           await expect(sandboxDiv).toBeVisible(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           const configPage = page.getByTestId('sandbox-app-test-config-page'); | 
					
						
							| 
									
										
										
										
											2025-07-25 17:54:07 +08:00
										 |  |  |           await expect(configPage).toBeVisible(); | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | ); |