@@ -4,12 +4,16 @@ import {tenantName} from '../../../../utils/constants';
44import { TenantPage } from '../../TenantPage' ;
55import { Diagnostics , DiagnosticsTab } from '../Diagnostics' ;
66
7- import { setupEmptyOperationsMock , setupOperationsMock } from './operationsMocks' ;
7+ import {
8+ setupEmptyOperationsMock ,
9+ setupOperation403Mock ,
10+ setupOperationsMock ,
11+ } from './operationsMocks' ;
812
913test . describe ( 'Operations Tab - Infinite Query' , ( ) => {
1014 test ( 'loads initial page of operations on tab click' , async ( { page} ) => {
11- // Setup mocks with 30 operations (3 pages of 10 )
12- await setupOperationsMock ( page , { totalOperations : 30 } ) ;
15+ // Setup mocks with 80 operations (4 pages of 20 )
16+ await setupOperationsMock ( page , { totalOperations : 80 } ) ;
1317
1418 const pageQueryParams = {
1519 schema : tenantName ,
@@ -27,10 +31,13 @@ test.describe('Operations Tab - Infinite Query', () => {
2731 await diagnostics . operations . waitForTableVisible ( ) ;
2832 await diagnostics . operations . waitForDataLoad ( ) ;
2933
30- // Verify initial page loaded (should have some rows)
31- const rowCount = await diagnostics . operations . getRowCount ( ) ;
32- expect ( rowCount ) . toBeGreaterThan ( 0 ) ;
33- expect ( rowCount ) . toBeLessThanOrEqual ( 20 ) ; // Reasonable page size
34+ // Wait a bit for the counter to stabilize after initial load
35+ await page . waitForTimeout ( 1000 ) ;
36+
37+ // Verify initial page loaded (should show count in badge)
38+ const operationsCount = await diagnostics . operations . getOperationsCount ( ) ;
39+ expect ( operationsCount ) . toBeGreaterThan ( 0 ) ;
40+ expect ( operationsCount ) . toBeLessThanOrEqual ( 20 ) ; // Should have up to DEFAULT_PAGE_SIZE operations loaded initially
3441
3542 // Verify first row data structure
3643 const firstRowData = await diagnostics . operations . getRowData ( 0 ) ;
@@ -49,8 +56,8 @@ test.describe('Operations Tab - Infinite Query', () => {
4956 } ) ;
5057
5158 test ( 'loads more operations on scroll' , async ( { page} ) => {
52- // Setup mocks with 30 operations (3 pages of 10 )
53- await setupOperationsMock ( page , { totalOperations : 30 } ) ;
59+ // Setup mocks with 80 operations (4 pages of 20 )
60+ await setupOperationsMock ( page , { totalOperations : 80 } ) ;
5461
5562 const pageQueryParams = {
5663 schema : tenantName ,
@@ -68,26 +75,32 @@ test.describe('Operations Tab - Infinite Query', () => {
6875 await diagnostics . operations . waitForTableVisible ( ) ;
6976 await diagnostics . operations . waitForDataLoad ( ) ;
7077
71- // Get initial row count
72- const initialRowCount = await diagnostics . operations . getRowCount ( ) ;
73- expect ( initialRowCount ) . toBeGreaterThan ( 0 ) ;
78+ // Get initial operations count
79+ const initialOperationsCount = await diagnostics . operations . getOperationsCount ( ) ;
80+ expect ( initialOperationsCount ) . toBeGreaterThan ( 0 ) ;
7481
7582 // Scroll to bottom
7683 await diagnostics . operations . scrollToBottom ( ) ;
7784
78- // Wait a bit for potential loading
79- await page . waitForTimeout ( 2000 ) ;
80-
81- // Get final row count
82- const finalRowCount = await diagnostics . operations . getRowCount ( ) ;
85+ // Wait for operations count to potentially change
86+ let finalOperationsCount : number ;
87+ try {
88+ finalOperationsCount = await diagnostics . operations . waitForOperationsCountToChange (
89+ initialOperationsCount ,
90+ 3000 ,
91+ ) ;
92+ } catch ( _e ) {
93+ // If timeout, the count didn't change
94+ finalOperationsCount = await diagnostics . operations . getOperationsCount ( ) ;
95+ }
8396
84- // Check if more rows were loaded
85- if ( finalRowCount > initialRowCount ) {
86- // Infinite scroll worked - more rows were loaded
87- expect ( finalRowCount ) . toBeGreaterThan ( initialRowCount ) ;
97+ // Check if more operations were loaded
98+ if ( finalOperationsCount > initialOperationsCount ) {
99+ // Infinite scroll worked - more operations were loaded
100+ expect ( finalOperationsCount ) . toBeGreaterThan ( initialOperationsCount ) ;
88101 } else {
89- // No more data to load - row count should stay the same
90- expect ( finalRowCount ) . toBe ( initialRowCount ) ;
102+ // No more data to load - operations count should stay the same
103+ expect ( finalOperationsCount ) . toBe ( initialOperationsCount ) ;
91104 }
92105 } ) ;
93106
@@ -119,4 +132,103 @@ test.describe('Operations Tab - Infinite Query', () => {
119132 const rowCount = await diagnostics . operations . getRowCount ( ) ;
120133 expect ( rowCount ) . toBeLessThanOrEqual ( 1 ) ;
121134 } ) ;
135+
136+ test ( 'shows access denied when operations request returns 403' , async ( { page} ) => {
137+ // Setup 403 error mock
138+ await setupOperation403Mock ( page ) ;
139+
140+ const pageQueryParams = {
141+ schema : tenantName ,
142+ database : tenantName ,
143+ tenantPage : 'diagnostics' ,
144+ } ;
145+
146+ const tenantPageInstance = new TenantPage ( page ) ;
147+ await tenantPageInstance . goto ( pageQueryParams ) ;
148+
149+ const diagnostics = new Diagnostics ( page ) ;
150+ await diagnostics . clickTab ( DiagnosticsTab . Operations ) ;
151+ // Wait a bit for potential loading
152+ await page . waitForTimeout ( 2000 ) ;
153+
154+ // Wait for access denied state to be visible
155+ const isAccessDeniedVisible = await diagnostics . operations . isAccessDeniedVisible ( ) ;
156+ expect ( isAccessDeniedVisible ) . toBe ( true ) ;
157+
158+ // Verify the access denied message
159+ const accessDeniedTitle = await diagnostics . operations . getAccessDeniedTitle ( ) ;
160+ expect ( accessDeniedTitle ) . toBe ( 'Access denied' ) ;
161+ } ) ;
162+
163+ test ( 'loads all operations when scrolling to the bottom multiple times' , async ( { page} ) => {
164+ // Setup mocks with 80 operations (4 pages of 20)
165+ await setupOperationsMock ( page , { totalOperations : 80 } ) ;
166+
167+ const pageQueryParams = {
168+ schema : tenantName ,
169+ database : tenantName ,
170+ tenantPage : 'diagnostics' ,
171+ } ;
172+
173+ const tenantPageInstance = new TenantPage ( page ) ;
174+ await tenantPageInstance . goto ( pageQueryParams ) ;
175+
176+ const diagnostics = new Diagnostics ( page ) ;
177+ await diagnostics . clickTab ( DiagnosticsTab . Operations ) ;
178+
179+ // Wait for initial data
180+ await diagnostics . operations . waitForTableVisible ( ) ;
181+ await diagnostics . operations . waitForDataLoad ( ) ;
182+
183+ // Wait a bit for the counter to stabilize after initial load
184+ await page . waitForTimeout ( 2000 ) ;
185+
186+ // Get initial operations count (should be around 20)
187+ const initialOperationsCount = await diagnostics . operations . getOperationsCount ( ) ;
188+ expect ( initialOperationsCount ) . toBeGreaterThan ( 0 ) ;
189+ expect ( initialOperationsCount ) . toBeLessThanOrEqual ( 20 ) ;
190+
191+ // Keep scrolling until all operations are loaded
192+ let previousOperationsCount = initialOperationsCount ;
193+ let currentOperationsCount = initialOperationsCount ;
194+ const maxScrollAttempts = 10 ; // Safety limit to prevent infinite loop
195+ let scrollAttempts = 0 ;
196+
197+ while ( currentOperationsCount < 80 && scrollAttempts < maxScrollAttempts ) {
198+ // Scroll to bottom
199+ await diagnostics . operations . scrollToBottom ( ) ;
200+
201+ // Wait for potential loading
202+ await page . waitForTimeout ( 1000 ) ;
203+
204+ // Check if loading more is visible and wait for it to complete
205+ const isLoadingVisible = await diagnostics . operations . isLoadingMoreVisible ( ) ;
206+ if ( isLoadingVisible ) {
207+ await diagnostics . operations . waitForLoadingMoreToDisappear ( ) ;
208+ }
209+
210+ // Wait for operations count to change or timeout
211+ try {
212+ currentOperationsCount =
213+ await diagnostics . operations . waitForOperationsCountToChange (
214+ previousOperationsCount ,
215+ 3000 ,
216+ ) ;
217+ } catch ( _e ) {
218+ // If timeout, the count didn't change - we might have reached the end
219+ currentOperationsCount = await diagnostics . operations . getOperationsCount ( ) ;
220+ }
221+
222+ previousOperationsCount = currentOperationsCount ;
223+ scrollAttempts ++ ;
224+ }
225+
226+ // Verify all 80 operations were loaded
227+ expect ( currentOperationsCount ) . toBe ( 80 ) ;
228+
229+ const rowCount = await diagnostics . operations . getRowCount ( ) ;
230+ // Verify the last operation has the expected ID pattern
231+ const lastRowData = await diagnostics . operations . getRowData ( rowCount - 1 ) ;
232+ expect ( lastRowData [ 'Operation ID' ] ) . toContain ( 'ydb://' ) ;
233+ } ) ;
122234} ) ;
0 commit comments