@@ -21,7 +21,7 @@ test.describe('Test Plan to SVG functionality', async () => {
2121 await tenantPage . goto ( pageQueryParams ) ;
2222 } ) ;
2323
24- test ( 'Plan to SVG experiment shows execution plan in new tab' , async ( { page} ) => {
24+ test ( 'Plan to SVG dropdown shows options and opens plan in new tab' , async ( { page} ) => {
2525 const queryEditor = new QueryEditor ( page ) ;
2626
2727 // 1. Turn on Plan to SVG experiment
@@ -37,17 +37,111 @@ test.describe('Test Plan to SVG functionality', async () => {
3737 expect ( status ) . toBe ( 'Completed' ) ;
3838 } ) . toPass ( ) ;
3939
40- // 4. Check if Execution Plan button appears and click it
40+ // 4. Check if Execution Plan button appears and click it to open dropdown
4141 const executionPlanButton = page . locator ( 'button:has-text("Execution plan")' ) ;
4242 await expect ( executionPlanButton ) . toBeVisible ( ) ;
4343 await executionPlanButton . click ( ) ;
44+
45+ // 5. Verify dropdown menu items are visible
46+ const openInNewTabOption = page . locator ( 'text="Open in new tab"' ) ;
47+ const downloadOption = page . locator ( 'text="Download"' ) ;
48+ await expect ( openInNewTabOption ) . toBeVisible ( ) ;
49+ await expect ( downloadOption ) . toBeVisible ( ) ;
50+
51+ // 6. Click "Open in new tab" option
52+ await openInNewTabOption . click ( ) ;
4453 await page . waitForTimeout ( 1000 ) ; // Wait for new tab to open
4554
46- // 5 . Verify we're taken to a new tab with SVG content
55+ // 7 . Verify we're taken to a new tab with SVG content
4756 const svgElement = page . locator ( 'svg' ) . first ( ) ;
4857 await expect ( svgElement ) . toBeVisible ( ) ;
4958 } ) ;
5059
60+ test ( 'Plan to SVG download option triggers file download' , async ( { page} ) => {
61+ const queryEditor = new QueryEditor ( page ) ;
62+
63+ // 1. Turn on Plan to SVG experiment
64+ await toggleExperiment ( page , 'on' , 'Execution plan' ) ;
65+
66+ // 2. Set query and run it
67+ await queryEditor . setQuery ( testQuery ) ;
68+ await queryEditor . clickRunButton ( ) ;
69+
70+ // 3. Wait for query execution to complete
71+ await expect ( async ( ) => {
72+ const status = await queryEditor . getExecutionStatus ( ) ;
73+ expect ( status ) . toBe ( 'Completed' ) ;
74+ } ) . toPass ( ) ;
75+
76+ // 4. Click execution plan button to open dropdown
77+ const executionPlanButton = page . locator ( 'button:has-text("Execution plan")' ) ;
78+ await executionPlanButton . click ( ) ;
79+
80+ // 5. Setup download listener before clicking download
81+ const downloadPromise = page . waitForEvent ( 'download' ) ;
82+
83+ // 6. Click download option
84+ const downloadOption = page . locator ( 'text="Download"' ) ;
85+ await downloadOption . click ( ) ;
86+
87+ // 7. Wait for download to start and verify filename
88+ const download = await downloadPromise ;
89+ expect ( download . suggestedFilename ( ) ) . toBe ( 'query-plan.svg' ) ;
90+ } ) ;
91+
92+ test ( 'Plan to SVG handles API errors correctly' , async ( { page} ) => {
93+ const queryEditor = new QueryEditor ( page ) ;
94+
95+ // 1. Turn on Plan to SVG experiment
96+ await toggleExperiment ( page , 'on' , 'Execution plan' ) ;
97+
98+ // 2. Set query and run it
99+ await queryEditor . setQuery ( testQuery ) ;
100+ await queryEditor . clickRunButton ( ) ;
101+
102+ // 3. Wait for query execution to complete
103+ await expect ( async ( ) => {
104+ const status = await queryEditor . getExecutionStatus ( ) ;
105+ expect ( status ) . toBe ( 'Completed' ) ;
106+ } ) . toPass ( ) ;
107+
108+ // 4. Mock the plan2svg API to return an error
109+ await page . route ( '**/plan2svg**' , ( route ) => {
110+ route . fulfill ( {
111+ status : 500 ,
112+ contentType : 'application/json' ,
113+ body : JSON . stringify ( { message : 'Failed to generate SVG' } ) ,
114+ } ) ;
115+ } ) ;
116+
117+ // 5. Click execution plan button to open dropdown
118+ const executionPlanButton = page . locator ( 'button:has-text("Execution plan")' ) ;
119+ await executionPlanButton . click ( ) ;
120+
121+ // 6. Click "Open in new tab" option and wait for error state
122+ const openInNewTabOption = page . locator ( 'text="Open in new tab"' ) ;
123+ await openInNewTabOption . click ( ) ;
124+ await page . waitForTimeout ( 1000 ) ; // Wait for error to be processed
125+
126+ // 7. Close the dropdown
127+ await page . keyboard . press ( 'Escape' ) ;
128+
129+ // 8. Verify error state
130+ await expect ( executionPlanButton ) . toHaveClass ( / f l a t - d a n g e r / ) ;
131+
132+ // 9. Verify error tooltip
133+ await executionPlanButton . hover ( ) ;
134+ await page . waitForTimeout ( 500 ) ; // Wait for tooltip animation
135+ const tooltipText = await page . textContent ( '.g-tooltip' ) ;
136+ expect ( tooltipText ) . toContain ( 'Error' ) ;
137+ expect ( tooltipText ) . toContain ( 'Failed to generate SVG' ) ;
138+
139+ // 10. Verify dropdown is disabled after error
140+ await executionPlanButton . click ( ) ;
141+ await expect ( openInNewTabOption ) . not . toBeVisible ( ) ;
142+ await expect ( page . locator ( 'text="Download"' ) ) . not . toBeVisible ( ) ;
143+ } ) ;
144+
51145 test ( 'Statistics setting becomes disabled when execution plan experiment is enabled' , async ( {
52146 page,
53147 } ) => {
0 commit comments