|
1 | 1 | import { AlertsPage } from '../page-objects/AlertsPage'; |
| 2 | +import { DashboardPage } from '../page-objects/DashboardPage'; |
| 3 | +import { SearchPage } from '../page-objects/SearchPage'; |
2 | 4 | import { expect, test } from '../utils/base-test'; |
3 | 5 |
|
4 | | -test.skip('Alerts Functionality', { tag: ['@alerts', '@full-stack'] }, () => { |
| 6 | +test.describe('Alert Creation', { tag: ['@alerts', '@full-stack'] }, () => { |
| 7 | + let searchPage: SearchPage; |
| 8 | + let dashboardPage: DashboardPage; |
5 | 9 | let alertsPage: AlertsPage; |
6 | 10 |
|
7 | 11 | test.beforeEach(async ({ page }) => { |
| 12 | + searchPage = new SearchPage(page); |
| 13 | + dashboardPage = new DashboardPage(page); |
8 | 14 | alertsPage = new AlertsPage(page); |
9 | | - await alertsPage.goto(); |
10 | 15 | }); |
11 | 16 |
|
12 | | - test('should load alerts page', async () => { |
13 | | - await test.step('Navigate to alerts page', async () => { |
14 | | - await alertsPage.goto(); |
15 | | - }); |
| 17 | + test( |
| 18 | + 'should create an alert from a saved search and verify on the alerts page', |
| 19 | + { tag: '@full-stack' }, |
| 20 | + async () => { |
| 21 | + const ts = Date.now(); |
| 22 | + const savedSearchName = `E2E Alert Search ${ts}`; |
| 23 | + const webhookName = `E2E Webhook SS ${ts}`; |
| 24 | + const webhookUrl = `https://example.com/ss-${ts}`; |
16 | 25 |
|
17 | | - await test.step('Verify alerts page loads with content', async () => { |
18 | | - await expect(alertsPage.pageContainer).toBeVisible(); |
| 26 | + await test.step('Create a saved search', async () => { |
| 27 | + await searchPage.goto(); |
| 28 | + await searchPage.openSaveSearchModal(); |
| 29 | + await searchPage.savedSearchModal.saveSearchAndWaitForNavigation( |
| 30 | + savedSearchName, |
| 31 | + ); |
| 32 | + }); |
19 | 33 |
|
20 | | - // Verify there are alert cards using web-first assertion |
21 | | - const alertCards = alertsPage.getAlertCards(); |
22 | | - try { |
23 | | - await expect(alertCards).toHaveCount(1, { timeout: 10000 }); |
24 | | - } catch { |
25 | | - // If there are no alerts, just verify the container is visible |
| 34 | + await test.step('Open the alerts modal from the saved search page', async () => { |
| 35 | + await expect(searchPage.alertsButton).toBeVisible(); |
| 36 | + await searchPage.openAlertsModal(); |
| 37 | + await expect(searchPage.alertModal.addNewWebhookButton).toBeVisible(); |
| 38 | + }); |
| 39 | + |
| 40 | + await test.step('Create a new incoming webhook for the alert channel', async () => { |
| 41 | + await searchPage.alertModal.addWebhookAndWait( |
| 42 | + 'Generic', |
| 43 | + webhookName, |
| 44 | + webhookUrl, |
| 45 | + ); |
| 46 | + }); |
| 47 | + |
| 48 | + await test.step('Create the alert (webhook is auto-selected after creation)', async () => { |
| 49 | + // The webhook is automatically selected in the form after webhook creation |
| 50 | + // (handleWebhookCreated calls field.onChange(webhookId) before closing modal) |
| 51 | + await searchPage.alertModal.createAlert(); |
| 52 | + }); |
| 53 | + |
| 54 | + await test.step('Verify the alert is visible on the alerts page', async () => { |
| 55 | + await alertsPage.goto(); |
26 | 56 | await expect(alertsPage.pageContainer).toBeVisible(); |
27 | | - } |
28 | | - }); |
29 | | - |
30 | | - await test.step('Verify alert links are accessible', async () => { |
31 | | - const firstAlertLink = alertsPage.getAlertLink(0); |
32 | | - // Only verify if alerts exist |
33 | | - const isVisible = await firstAlertLink |
34 | | - .isVisible({ timeout: 2000 }) |
35 | | - .catch(() => false); |
36 | | - if (isVisible) { |
37 | | - await expect(firstAlertLink).toBeVisible(); |
38 | | - } |
39 | | - }); |
40 | | - }); |
| 57 | + await expect( |
| 58 | + alertsPage.pageContainer |
| 59 | + .getByRole('link') |
| 60 | + .filter({ hasText: savedSearchName }), |
| 61 | + ).toBeVisible({ timeout: 10000 }); |
| 62 | + }); |
| 63 | + }, |
| 64 | + ); |
41 | 65 |
|
42 | | - test('should handle alerts creation from search', async () => { |
43 | | - await test.step('Navigate to search page', async () => { |
44 | | - await alertsPage.page.goto('/search'); |
45 | | - }); |
| 66 | + test( |
| 67 | + 'should create an alert from a dashboard tile and verify on the alerts page', |
| 68 | + { tag: '@full-stack' }, |
| 69 | + async ({ page }) => { |
| 70 | + const ts = Date.now(); |
| 71 | + const tileName = `E2E Alert Tile ${ts}`; |
| 72 | + const webhookName = `E2E Webhook Tile ${ts}`; |
| 73 | + const webhookUrl = `https://example.com/tile-${ts}`; |
46 | 74 |
|
47 | | - await test.step('Open alerts creation modal', async () => { |
48 | | - await expect(alertsPage.createButton).toBeVisible(); |
49 | | - await alertsPage.openAlertsModal(); |
50 | | - }); |
| 75 | + await test.step('Create a new dashboard', async () => { |
| 76 | + await dashboardPage.goto(); |
| 77 | + await dashboardPage.createNewDashboard(); |
| 78 | + }); |
51 | 79 |
|
52 | | - await test.step('Verify alerts modal opens', async () => { |
53 | | - await expect(alertsPage.modal).toBeVisible(); |
54 | | - }); |
55 | | - }); |
| 80 | + await test.step('Add a tile to the dashboard', async () => { |
| 81 | + await dashboardPage.addTile(); |
| 82 | + await expect(dashboardPage.chartEditor.nameInput).toBeVisible(); |
| 83 | + await dashboardPage.chartEditor.waitForDataToLoad(); |
| 84 | + await dashboardPage.chartEditor.setChartName(tileName); |
| 85 | + await dashboardPage.chartEditor.runQuery(); |
| 86 | + }); |
| 87 | + |
| 88 | + await test.step('Enable and configure an alert on the tile', async () => { |
| 89 | + await expect(dashboardPage.chartEditor.alertButton).toBeVisible(); |
| 90 | + await dashboardPage.chartEditor.clickAddAlert(); |
| 91 | + await expect( |
| 92 | + dashboardPage.chartEditor.addNewWebhookButton, |
| 93 | + ).toBeVisible(); |
| 94 | + await dashboardPage.chartEditor.addNewWebhookButton.click(); |
| 95 | + // Verify webhook form opened by checking for its inner input |
| 96 | + await expect(page.getByTestId('webhook-name-input')).toBeVisible(); |
| 97 | + await dashboardPage.chartEditor.webhookAlertModal.addWebhook( |
| 98 | + 'Generic', |
| 99 | + webhookName, |
| 100 | + webhookUrl, |
| 101 | + ); |
| 102 | + await expect(page.getByTestId('alert-modal')).toBeHidden(); |
| 103 | + // The webhook is automatically selected in the form after creation |
| 104 | + // (handleWebhookCreated calls field.onChange(webhookId) before closing modal) |
| 105 | + }); |
| 106 | + |
| 107 | + await test.step('Save the tile with the alert configured', async () => { |
| 108 | + await dashboardPage.chartEditor.save(); |
| 109 | + await expect(dashboardPage.getTiles()).toHaveCount(1, { |
| 110 | + timeout: 10000, |
| 111 | + }); |
| 112 | + }); |
| 113 | + |
| 114 | + await test.step('Verify the alert is visible on the alerts page', async () => { |
| 115 | + await alertsPage.goto(); |
| 116 | + await expect(alertsPage.pageContainer).toBeVisible(); |
| 117 | + await expect( |
| 118 | + alertsPage.pageContainer |
| 119 | + .getByRole('link') |
| 120 | + .filter({ hasText: tileName }), |
| 121 | + ).toBeVisible({ timeout: 10000 }); |
| 122 | + }); |
| 123 | + }, |
| 124 | + ); |
56 | 125 | }); |
0 commit comments