import { test, expect } from '@playwright/test'; import { login, resetToAmsterdam } from './utils/auth'; const ZT_PAGE = '/cgi-bin/luci/admin/services/zt-gateway'; test.describe('ZT Gateway switch', () => { test.describe.configure({ mode: 'serial' }); test.beforeEach(async ({ page }) => { await login(page); await resetToAmsterdam(page); await page.goto(ZT_PAGE); await page.waitForSelector('.zt-gateway-row', { timeout: 15_000 }); }); test.afterEach(async ({ page }) => { await resetToAmsterdam(page); }); test('switches active gateway to tirunelveli', async ({ page }) => { // Select tirunelveli radio button const tirunelveliRow = page.locator('tr.zt-gateway-row[data-region="tirunelveli"]'); await tirunelveliRow.locator('input[type="radio"]').click(); // Click the "Switch to selected" button const switchBtn = page.locator('button.cbi-button-positive', { hasText: 'Switch' }); await switchBtn.click(); // Wait for a notification to appear await page.waitForSelector('.alert-message', { timeout: 10_000 }); // Poll for the active gateway to change — the RPC takes 12-30s await page.waitForFunction( () => { const row = document.querySelector('tr.zt-gateway-row[data-region="tirunelveli"]'); return row?.textContent?.includes('active') ?? false; }, { timeout: 45_000, polling: 2_000 }, ); // Verify tirunelveli row now contains "active" await expect(tirunelveliRow).toContainText('active'); // Verify amsterdam row no longer contains "active" const amsterdamRow = page.locator('tr.zt-gateway-row[data-region="amsterdam"]'); await expect(amsterdamRow).not.toContainText('active'); }); });