|
| 1 | +import { test, expect } from '../fixtures'; |
| 2 | +import grafanaApiClient from '../utils/clients/grafana'; |
| 3 | +import { clickButton, generateRandomValue } from '../utils/forms'; |
| 4 | +import { goToOnCallPage } from '../utils/navigation'; |
| 5 | +import { checkWebhookPresenceInTable } from '../utils/outgoingWebhooks'; |
| 6 | + |
| 7 | +const WEBHOOK_NAME = generateRandomValue(); |
| 8 | +const TRIGGER_TYPE = 'Personal Notification'; |
| 9 | + |
| 10 | +let webhookID: string; |
| 11 | + |
| 12 | +test.afterAll(async ({ request }) => { |
| 13 | + // Delete the created webhook |
| 14 | + if (webhookID) { |
| 15 | + await grafanaApiClient.makeRequest( |
| 16 | + request, |
| 17 | + `resources/webhooks/${webhookID}/`, |
| 18 | + 'delete', |
| 19 | + ) |
| 20 | + } |
| 21 | +}); |
| 22 | + |
| 23 | +test('Connects a personal notification webhook', async ({ adminRolePage: { page } }) => { |
| 24 | + // Create a new webhook |
| 25 | + await goToOnCallPage(page, 'outgoing_webhooks'); |
| 26 | + await page.getByRole('button', { name: 'New Outgoing Webhook' }).click(); |
| 27 | + |
| 28 | + // Choose Advanced webhook |
| 29 | + await page.getByTestId('create-outgoing-webhook-modal').locator('div').filter({ hasText: 'AdvancedAn advanced webhook' }).first().click(); |
| 30 | + |
| 31 | + // Give it a name |
| 32 | + await page.locator('input[name="name"]').fill(WEBHOOK_NAME); |
| 33 | + |
| 34 | + // Choose a trigger type |
| 35 | + await page.getByTestId('triggerType-selector').locator('div').nth(1).click(); |
| 36 | + await page.getByLabel('Select options menu').getByText(TRIGGER_TYPE).click(); |
| 37 | + |
| 38 | + // Set a URL |
| 39 | + await page.locator('#OutgoingWebhook div').locator('.monaco-editor').first().click(); |
| 40 | + await page.keyboard.insertText('https://example.com'); |
| 41 | + |
| 42 | + // Create and check it has been created |
| 43 | + const responsePromise = page.waitForResponse('**/resources/webhooks/'); |
| 44 | + await clickButton({ page, buttonText: 'Create' }); |
| 45 | + await checkWebhookPresenceInTable({ page, webhookName: WEBHOOK_NAME, expectedTriggerType: TRIGGER_TYPE }); |
| 46 | + |
| 47 | + // save the ID so we can delete the webhook after the tests have run |
| 48 | + const response = await responsePromise; |
| 49 | + const wh = await response.json(); |
| 50 | + webhookID = wh?.id; |
| 51 | + |
| 52 | + await goToOnCallPage(page, 'users/me'); |
| 53 | + await page.getByRole('tab', { name: 'Webhook connection' }).click(); |
| 54 | + |
| 55 | + // Select webhook |
| 56 | + await page.getByRole('dialog').locator('svg').nth(2).click(); |
| 57 | + await page.getByLabel('Select options menu').getByText(WEBHOOK_NAME).click(); |
| 58 | + |
| 59 | + // Add some context |
| 60 | + await page.getByRole('textbox').fill('{ "test": true }'); |
| 61 | + |
| 62 | + // Connect |
| 63 | + await page.getByRole('button', { name: 'Connect' }).click(); |
| 64 | + |
| 65 | + // Check connection on User Info tab |
| 66 | + await page.getByRole('tab', { name: 'User info' }).click(); |
| 67 | + expect(page.getByText(WEBHOOK_NAME)).toBeVisible(); |
| 68 | + |
| 69 | + // Disconnect |
| 70 | + await page.getByRole('tab', { name: 'Webhook connection' }).click(); |
| 71 | + await page.getByRole('button', { name: 'Disconnect' }).click(); |
| 72 | + await page.getByTestId('data-testid Confirm Modal Danger Button').click(); |
| 73 | + |
| 74 | + // Check connection is no longer shown |
| 75 | + await page.getByRole('tab', { name: 'User info' }).click(); |
| 76 | + expect(page.getByText(WEBHOOK_NAME)).not.toBeVisible(); |
| 77 | +}) |
0 commit comments