towerops/e2e/tests/status-indicator.spec.ts
Graham McIntire 17bf1f83e8
feat: add Playwright e2e test suite
- Set up Playwright in dedicated e2e directory
- Multi-environment support (local, staging)
- TOTP authentication handling with otplib
- Test coverage for organizations, devices, alerts, status indicators
- Helper utilities for common test operations
- Comprehensive README with setup and usage instructions
- Setup script for quick initialization
2026-03-06 15:02:56 -06:00

69 lines
2.3 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { selectFirstOrganization, getStatusEmoji } from './helpers';
test.describe('Status Indicator', () => {
test.beforeEach(async ({ page }) => {
await selectFirstOrganization(page);
});
test('page title shows status emoji', async ({ page }) => {
// Navigate to devices page
await page.goto('/devices');
// Get current status emoji from title
const emoji = await getStatusEmoji(page);
// Should have a status emoji (🔴, 🟡, or 🟢)
expect(['🔴', '🟡', '🟢']).toContain(emoji);
});
test('status emoji appears on all pages', async ({ page }) => {
const pages = ['/devices', '/alerts', '/sites'];
for (const path of pages) {
await page.goto(path);
await page.waitForLoadState('networkidle');
const emoji = await getStatusEmoji(page);
expect(['🔴', '🟡', '🟢', null]).toContain(emoji);
// If there's an organization context, should have emoji
const hasOrgContext = await page.locator('[data-test="organization-selector"], .organization-name').count() > 0;
if (hasOrgContext) {
expect(emoji).not.toBeNull();
}
}
});
test('status emoji matches organization health', async ({ page }) => {
await page.goto('/devices');
const emoji = await getStatusEmoji(page);
// Navigate to alerts to check if status makes sense
await page.goto('/alerts');
// If there are critical alerts, emoji should be red
const hasCriticalAlerts = await page.locator('[data-severity="critical"], [data-alert-type="device_down"]').count() > 0;
const hasWarningAlerts = await page.locator('[data-severity="warning"]').count() > 0;
if (hasCriticalAlerts) {
expect(emoji).toBe('🔴');
} else if (hasWarningAlerts) {
expect(emoji).toBe('🟡');
} else {
// If no alerts, should be green (or might still be yellow/red if we just resolved them)
expect(['🟢', '🟡', '🔴']).toContain(emoji);
}
});
test('favicon is static stoplight', async ({ page }) => {
await page.goto('/devices');
// Get favicon link element
const faviconHref = await page.locator('link[rel="icon"]').first().getAttribute('href');
// Should point to our stoplight favicon
expect(faviconHref).toContain('favicon');
});
});