// apps/web/e2e/flows/alert-flow.spec.ts
import { test, expect } from '../fixtures/auth.fixture';
import { makeAlertRule } from '../fixtures/test-data';

test.describe('@flow 告警规则链路', () => {
  const cleanup: Array<() => Promise<void>> = [];

  test.afterEach(async () => {
    for (const fn of cleanup.reverse()) {
      await fn().catch(() => {});
    }
    cleanup.length = 0;
  });

  test('创建告警规则 → 查看列表 → 查看告警页面', async ({ api, authenticatedPage: page }) => {
    const rule = await api.createAlertRule(makeAlertRule());
    cleanup.push(() => api.deleteAlertRule(rule.id, rule.version));

    await page.goto('/#/health/alert-rules');
    await page.waitForSelector('.ant-table', { timeout: 10000 });

    const tableText = await page.locator('.ant-table-tbody').textContent();
    expect(tableText).toBeTruthy();

    await page.goto('/#/health/alerts');
    await page.waitForSelector('.ant-table, .ant-empty', { timeout: 10000 });
  });
});
