@@ -4,12 +4,16 @@ import {tenantName} from '../../../../utils/constants';
4
4
import { TenantPage } from '../../TenantPage' ;
5
5
import { Diagnostics , DiagnosticsTab } from '../Diagnostics' ;
6
6
7
- import { setupEmptyOperationsMock , setupOperationsMock } from './operationsMocks' ;
7
+ import {
8
+ setupEmptyOperationsMock ,
9
+ setupOperation403Mock ,
10
+ setupOperationsMock ,
11
+ } from './operationsMocks' ;
8
12
9
13
test . describe ( 'Operations Tab - Infinite Query' , ( ) => {
10
14
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 } ) ;
13
17
14
18
const pageQueryParams = {
15
19
schema : tenantName ,
@@ -27,10 +31,13 @@ test.describe('Operations Tab - Infinite Query', () => {
27
31
await diagnostics . operations . waitForTableVisible ( ) ;
28
32
await diagnostics . operations . waitForDataLoad ( ) ;
29
33
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
34
41
35
42
// Verify first row data structure
36
43
const firstRowData = await diagnostics . operations . getRowData ( 0 ) ;
@@ -49,8 +56,8 @@ test.describe('Operations Tab - Infinite Query', () => {
49
56
} ) ;
50
57
51
58
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 } ) ;
54
61
55
62
const pageQueryParams = {
56
63
schema : tenantName ,
@@ -68,26 +75,32 @@ test.describe('Operations Tab - Infinite Query', () => {
68
75
await diagnostics . operations . waitForTableVisible ( ) ;
69
76
await diagnostics . operations . waitForDataLoad ( ) ;
70
77
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 ) ;
74
81
75
82
// Scroll to bottom
76
83
await diagnostics . operations . scrollToBottom ( ) ;
77
84
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
+ }
83
96
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 ) ;
88
101
} 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 ) ;
91
104
}
92
105
} ) ;
93
106
@@ -119,4 +132,103 @@ test.describe('Operations Tab - Infinite Query', () => {
119
132
const rowCount = await diagnostics . operations . getRowCount ( ) ;
120
133
expect ( rowCount ) . toBeLessThanOrEqual ( 1 ) ;
121
134
} ) ;
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
+ } ) ;
122
234
} ) ;
0 commit comments