|
| 1 | +/** |
| 2 | + * E2E Tests: Gateway Control |
| 3 | + * |
| 4 | + * Test Cases Covered: |
| 5 | + * - TC-GW-001: Gateway Status Display |
| 6 | + * - TC-GW-002: Gateway Running on Startup |
| 7 | + * - TC-GW-003: Dashboard Shows Gateway Status |
| 8 | + * - TC-GW-006: Gateway URL Display |
| 9 | + * - TC-GW-007: Copy Client Config |
| 10 | + * - TC-GW-008: Dashboard Statistics |
| 11 | + */ |
| 12 | + |
| 13 | +// Helper to find element by test ID or fallback |
| 14 | +async function findElement(testId: string, fallbackSelector: string) { |
| 15 | + const byTestId = await $(`[data-testid="${testId}"]`); |
| 16 | + const testIdExists = await byTestId.isExisting().catch(() => false); |
| 17 | + if (testIdExists) { |
| 18 | + return byTestId; |
| 19 | + } |
| 20 | + return $(fallbackSelector); |
| 21 | +} |
| 22 | + |
| 23 | +describe('Gateway Status - Dashboard', () => { |
| 24 | + before(async () => { |
| 25 | + // Navigate to Dashboard |
| 26 | + const dashboardBtn = await findElement('nav-dashboard', 'button*=Dashboard'); |
| 27 | + await dashboardBtn.click(); |
| 28 | + await browser.pause(2000); |
| 29 | + }); |
| 30 | + |
| 31 | + it('TC-GW-001: Gateway status is displayed in status bar', async () => { |
| 32 | + await browser.saveScreenshot('./tests/e2e/screenshots/gw-01-status-bar.png'); |
| 33 | + |
| 34 | + const pageSource = await browser.getPageSource(); |
| 35 | + |
| 36 | + // Status bar should show gateway status |
| 37 | + const hasGatewayStatus = |
| 38 | + pageSource.includes('Gateway Active') || |
| 39 | + pageSource.includes('Gateway Stopped') || |
| 40 | + pageSource.includes('Gateway'); |
| 41 | + |
| 42 | + expect(hasGatewayStatus).toBe(true); |
| 43 | + }); |
| 44 | + |
| 45 | + it('TC-GW-002: Gateway is running on startup', async () => { |
| 46 | + // Check gateway status card |
| 47 | + const statusCard = await findElement('gateway-status-card', '.border-green-500'); |
| 48 | + const isDisplayed = await statusCard.isDisplayed().catch(() => false); |
| 49 | + |
| 50 | + await browser.saveScreenshot('./tests/e2e/screenshots/gw-02-gateway-running.png'); |
| 51 | + |
| 52 | + const pageSource = await browser.getPageSource(); |
| 53 | + |
| 54 | + // Gateway should be running by default |
| 55 | + const isRunning = |
| 56 | + pageSource.includes('Gateway: Running') || |
| 57 | + pageSource.includes('border-green-500'); |
| 58 | + |
| 59 | + console.log('[DEBUG] Gateway running:', isRunning); |
| 60 | + expect(isRunning).toBe(true); |
| 61 | + }); |
| 62 | + |
| 63 | + it('TC-GW-003: Dashboard shows gateway status banner', async () => { |
| 64 | + // Verify gateway status content via page source |
| 65 | + const pageSource = await browser.getPageSource(); |
| 66 | + |
| 67 | + // Check for gateway status card |
| 68 | + const hasGatewayCard = |
| 69 | + pageSource.includes('Gateway: Running') || |
| 70 | + pageSource.includes('Gateway: Stopped') || |
| 71 | + pageSource.includes('gateway-status-card'); |
| 72 | + |
| 73 | + expect(hasGatewayCard).toBe(true); |
| 74 | + |
| 75 | + // Verify toggle button exists |
| 76 | + const hasToggleBtn = |
| 77 | + pageSource.includes('Stop') || |
| 78 | + pageSource.includes('Start'); |
| 79 | + |
| 80 | + expect(hasToggleBtn).toBe(true); |
| 81 | + }); |
| 82 | + |
| 83 | + it('TC-GW-006: Gateway URL is displayed', async () => { |
| 84 | + const pageSource = await browser.getPageSource(); |
| 85 | + |
| 86 | + // Gateway URL should be visible (localhost:3100 or similar) |
| 87 | + const hasGatewayUrl = |
| 88 | + pageSource.includes('localhost:') || |
| 89 | + pageSource.includes('http://127.0.0.1'); |
| 90 | + |
| 91 | + console.log('[DEBUG] Has gateway URL:', hasGatewayUrl); |
| 92 | + expect(hasGatewayUrl).toBe(true); |
| 93 | + }); |
| 94 | + |
| 95 | + it('TC-GW-007: Copy client config button exists', async () => { |
| 96 | + const copyBtn = await findElement('copy-config-btn', 'button*=Copy'); |
| 97 | + const isDisplayed = await copyBtn.isDisplayed().catch(() => false); |
| 98 | + |
| 99 | + await browser.saveScreenshot('./tests/e2e/screenshots/gw-07-copy-config.png'); |
| 100 | + |
| 101 | + expect(isDisplayed).toBe(true); |
| 102 | + }); |
| 103 | + |
| 104 | + it('TC-GW-008: Dashboard statistics are displayed', async () => { |
| 105 | + // Check stats grid exists |
| 106 | + const statsGrid = await findElement('dashboard-stats-grid', '.grid'); |
| 107 | + const gridDisplayed = await statsGrid.isDisplayed().catch(() => false); |
| 108 | + |
| 109 | + await browser.saveScreenshot('./tests/e2e/screenshots/gw-08-dashboard-stats.png'); |
| 110 | + |
| 111 | + // Verify individual stat cards |
| 112 | + const pageSource = await browser.getPageSource(); |
| 113 | + |
| 114 | + const hasServersCard = pageSource.includes('Servers'); |
| 115 | + const hasFeatureSetsCard = pageSource.includes('FeatureSets'); |
| 116 | + const hasClientsCard = pageSource.includes('Clients'); |
| 117 | + const hasActiveSpaceCard = pageSource.includes('Active Space'); |
| 118 | + |
| 119 | + console.log('[DEBUG] Stats - Servers:', hasServersCard); |
| 120 | + console.log('[DEBUG] Stats - FeatureSets:', hasFeatureSetsCard); |
| 121 | + console.log('[DEBUG] Stats - Clients:', hasClientsCard); |
| 122 | + console.log('[DEBUG] Stats - Active Space:', hasActiveSpaceCard); |
| 123 | + |
| 124 | + expect(hasServersCard).toBe(true); |
| 125 | + expect(hasFeatureSetsCard).toBe(true); |
| 126 | + expect(hasClientsCard).toBe(true); |
| 127 | + expect(hasActiveSpaceCard).toBe(true); |
| 128 | + }); |
| 129 | +}); |
| 130 | + |
| 131 | +describe('Gateway Toggle', () => { |
| 132 | + before(async () => { |
| 133 | + // Navigate to Dashboard |
| 134 | + const dashboardBtn = await findElement('nav-dashboard', 'button*=Dashboard'); |
| 135 | + await dashboardBtn.click(); |
| 136 | + await browser.pause(2000); |
| 137 | + }); |
| 138 | + |
| 139 | + it('TC-GW-004/005: Toggle gateway button exists and is clickable', async () => { |
| 140 | + const toggleBtn = await findElement('gateway-toggle-btn', 'button*=Stop'); |
| 141 | + const isDisplayed = await toggleBtn.isDisplayed().catch(() => false); |
| 142 | + |
| 143 | + if (!isDisplayed) { |
| 144 | + // Try finding Start button instead |
| 145 | + const startBtn = await findElement('gateway-toggle-btn', 'button*=Start'); |
| 146 | + const startDisplayed = await startBtn.isDisplayed().catch(() => false); |
| 147 | + expect(startDisplayed).toBe(true); |
| 148 | + } else { |
| 149 | + expect(isDisplayed).toBe(true); |
| 150 | + } |
| 151 | + |
| 152 | + await browser.saveScreenshot('./tests/e2e/screenshots/gw-toggle-button.png'); |
| 153 | + }); |
| 154 | +}); |
0 commit comments