|
| 1 | +import {expect, test} from '@playwright/test'; |
| 2 | + |
| 3 | +import {tenantName} from '../../../../utils/constants'; |
| 4 | +import {TenantPage} from '../../TenantPage'; |
| 5 | +import {Diagnostics, DiagnosticsTab} from '../Diagnostics'; |
| 6 | + |
| 7 | +import {setupEmptyOperationsMock, setupOperationsMock} from './operationsMocks'; |
| 8 | + |
| 9 | +test.describe('Operations Tab - Infinite Query', () => { |
| 10 | + 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}); |
| 13 | + |
| 14 | + const pageQueryParams = { |
| 15 | + schema: tenantName, |
| 16 | + database: tenantName, |
| 17 | + tenantPage: 'diagnostics', |
| 18 | + }; |
| 19 | + |
| 20 | + const tenantPageInstance = new TenantPage(page); |
| 21 | + await tenantPageInstance.goto(pageQueryParams); |
| 22 | + |
| 23 | + const diagnostics = new Diagnostics(page); |
| 24 | + await diagnostics.clickTab(DiagnosticsTab.Operations); |
| 25 | + |
| 26 | + // Wait for table to be visible and data to load |
| 27 | + await diagnostics.operations.waitForTableVisible(); |
| 28 | + await diagnostics.operations.waitForDataLoad(); |
| 29 | + |
| 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 | + |
| 35 | + // Verify first row data structure |
| 36 | + const firstRowData = await diagnostics.operations.getRowData(0); |
| 37 | + expect(firstRowData['Operation ID']).toBeTruthy(); |
| 38 | + expect(firstRowData['Operation ID']).toContain('ydb://'); |
| 39 | + expect(firstRowData['Status']).toBeTruthy(); |
| 40 | + expect(['SUCCESS', 'GENERIC_ERROR', 'CANCELLED', 'ABORTED']).toContain( |
| 41 | + firstRowData['Status'], |
| 42 | + ); |
| 43 | + expect(firstRowData['State']).toBeTruthy(); |
| 44 | + expect(firstRowData['Progress']).toBeTruthy(); |
| 45 | + |
| 46 | + // Verify loading more indicator is not visible initially |
| 47 | + const isLoadingVisible = await diagnostics.operations.isLoadingMoreVisible(); |
| 48 | + expect(isLoadingVisible).toBe(false); |
| 49 | + }); |
| 50 | + |
| 51 | + test('loads more operations on scroll', async ({page}) => { |
| 52 | + // Setup mocks with 30 operations (3 pages of 10) |
| 53 | + await setupOperationsMock(page, {totalOperations: 30}); |
| 54 | + |
| 55 | + const pageQueryParams = { |
| 56 | + schema: tenantName, |
| 57 | + database: tenantName, |
| 58 | + tenantPage: 'diagnostics', |
| 59 | + }; |
| 60 | + |
| 61 | + const tenantPageInstance = new TenantPage(page); |
| 62 | + await tenantPageInstance.goto(pageQueryParams); |
| 63 | + |
| 64 | + const diagnostics = new Diagnostics(page); |
| 65 | + await diagnostics.clickTab(DiagnosticsTab.Operations); |
| 66 | + |
| 67 | + // Wait for initial data |
| 68 | + await diagnostics.operations.waitForTableVisible(); |
| 69 | + await diagnostics.operations.waitForDataLoad(); |
| 70 | + |
| 71 | + // Get initial row count |
| 72 | + const initialRowCount = await diagnostics.operations.getRowCount(); |
| 73 | + expect(initialRowCount).toBeGreaterThan(0); |
| 74 | + |
| 75 | + // Scroll to bottom |
| 76 | + await diagnostics.operations.scrollToBottom(); |
| 77 | + |
| 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(); |
| 83 | + |
| 84 | + // Check if more rows were loaded |
| 85 | + if (finalRowCount > initialRowCount) { |
| 86 | + // Infinite scroll worked - more rows were loaded |
| 87 | + expect(finalRowCount).toBeGreaterThan(initialRowCount); |
| 88 | + } else { |
| 89 | + // No more data to load - row count should stay the same |
| 90 | + expect(finalRowCount).toBe(initialRowCount); |
| 91 | + } |
| 92 | + }); |
| 93 | + |
| 94 | + test('shows empty state when no operations', async ({page}) => { |
| 95 | + // Setup empty operations mock |
| 96 | + await setupEmptyOperationsMock(page); |
| 97 | + |
| 98 | + const pageQueryParams = { |
| 99 | + schema: tenantName, |
| 100 | + database: tenantName, |
| 101 | + tenantPage: 'diagnostics', |
| 102 | + }; |
| 103 | + |
| 104 | + const tenantPageInstance = new TenantPage(page); |
| 105 | + await tenantPageInstance.goto(pageQueryParams); |
| 106 | + |
| 107 | + const diagnostics = new Diagnostics(page); |
| 108 | + await diagnostics.clickTab(DiagnosticsTab.Operations); |
| 109 | + |
| 110 | + // Wait for table to be visible |
| 111 | + await diagnostics.operations.waitForTableVisible(); |
| 112 | + await diagnostics.operations.waitForDataLoad(); |
| 113 | + |
| 114 | + // Verify empty state is shown |
| 115 | + const isEmptyVisible = await diagnostics.operations.isEmptyStateVisible(); |
| 116 | + expect(isEmptyVisible).toBe(true); |
| 117 | + |
| 118 | + // Verify no data rows (or possibly one empty row) |
| 119 | + const rowCount = await diagnostics.operations.getRowCount(); |
| 120 | + expect(rowCount).toBeLessThanOrEqual(1); |
| 121 | + }); |
| 122 | +}); |
0 commit comments