Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

test(e2e): cover the notification channel list, create and delete flows (#13216)

Ashwin Bhatkal9fc6fbb9fab6
diff --git a/tests/e2e/drivers/channels.ts b/tests/e2e/drivers/channels.ts
new file mode 100644
index 0000000000..d8f1ce3bb6
--- /dev/null
+++ b/tests/e2e/drivers/channels.ts
@@ -0,0 +1,369 @@
+/**
+ * AI-owned. Generated and maintained by coding agents alongside the specs that
+ * use it. Do not hand-edit: regenerate it with the spec that needs the change.
+ */
+import { expect, type Locator, type Page } from '@playwright/test';
+
+import { authToken } from '../helpers/common';
+
+import { driver, kit, seeded } from './kit';
+
+// Search and the type filter are both served by the API, so every assertion on
+// the list is also a guard on the query the list sends.
+
+export const PATH = {
+ list: '/alerts?tab=Channels',
+ new: '/alerts/channels/new',
+ /** Matches any channel's edit route. */
+ edit: /\/alerts\/channels\/edit\//,
+} as const;
+
+const CHANNELS_API = '/api/v2/notification_channels';
+
+/**
+ * One entry per channel type the form offers. `fields` carries only what the
+ * validator refuses to save without, and `spec` is the same channel as the API
+ * takes it, for specs that seed rather than type.
+ */
+export const CHANNEL_TYPES: ChannelType[] = [
+ {
+ label: 'Slack',
+ kind: 'slack',
+ fields: [['webhook-url-textbox', 'https://hooks.slack.com/services/T/B/X']],
+ edit: ['webhook-url-textbox', 'https://hooks.slack.com/services/T/B/edited'],
+ spec: { apiUrl: 'https://hooks.slack.com/services/T/B/X' },
+ },
+ {
+ label: 'Webhook',
+ kind: 'webhook',
+ fields: [['webhook-url-textbox', 'https://example.test/e2e-hook']],
+ edit: ['webhook-url-textbox', 'https://example.test/e2e-hook-edited'],
+ spec: { url: 'https://example.test/e2e-hook' },
+ },
+ {
+ label: 'Pagerduty',
+ kind: 'pagerduty',
+ fields: [['pager-routing-key-textbox', 'e2e-routing-key']],
+ edit: ['pager-routing-key-textbox', 'e2e-routing-key-edited'],
+ spec: { routingKey: 'e2e-routing-key' },
+ },
+ {
+ label: 'Opsgenie',
+ kind: 'opsgenie',
+ fields: [['opsgenie-api-key-textbox', 'e2e-api-key']],
+ edit: ['opsgenie-api-key-textbox', 'e2e-api-key-edited'],
+ spec: { apiKey: 'e2e-api-key' },
+ },
+ {
+ label: 'Email',
+ kind: 'email',
+ fields: [['email-to-textbox', '[email protected]']],
+ edit: ['email-to-textbox', '[email protected]'],
+ spec: { to: '[email protected]' },
+ },
+ {
+ label: 'Microsoft Teams',
+ kind: 'msteams',
+ fields: [
+ ['webhook-url-textbox', 'https://outlook.office.com/webhook/e2e-teams'],
+ ],
+ edit: [
+ 'webhook-url-textbox',
+ 'https://outlook.office.com/webhook/e2e-teams-edited',
+ ],
+ spec: { webhookUrl: 'https://outlook.office.com/webhook/e2e-teams' },
+ },
+ {
+ label: 'Google Chat',
+ kind: 'googlechat',
+ // the validator accepts https on chat.googleapis.com and nothing else
+ fields: [
+ [
+ 'webhook-url-textbox',
+ 'https://chat.googleapis.com/v1/spaces/AAA/messages?key=k&token=t',
+ ],
+ ],
+ edit: [
+ 'webhook-url-textbox',
+ 'https://chat.googleapis.com/v1/spaces/AAA/messages?key=k&token=edited',
+ ],
+ spec: {
+ webhookUrl:
+ 'https://chat.googleapis.com/v1/spaces/AAA/messages?key=k&token=t',
+ },
+ },
+ {
+ label: 'Jira',
+ kind: 'jira',
+ // the site has to be an https atlassian.net host
+ fields: [
+ ['jira-site-textbox', 'https://e2e.atlassian.net'],
+ ['jira-email-textbox', '[email protected]'],
+ ['jira-api-token-textbox', 'e2e-api-token'],
+ ['jira-project-textbox', 'E2E'],
+ ['jira-issue-type-textbox', 'Task'],
+ ],
+ edit: ['jira-project-textbox', 'E2EEDIT'],
+ spec: {
+ site: 'https://e2e.atlassian.net',
+ email: '[email protected]',
+ apiToken: 'e2e-api-token',
+ project: 'E2E',
+ issueType: 'Task',
+ },
+ },
+ {
+ label: 'Jira Service Management Ops',
+ kind: 'jsmops',
+ fields: [['jsmops-api-key-textbox', 'e2e-api-key']],
+ edit: ['jsmops-api-key-textbox', 'e2e-api-key-edited'],
+ spec: { apiKey: 'e2e-api-key' },
+ },
+ {
+ label: 'incident.io',
+ kind: 'incidentio',
+ // the path has to carry an id after /v2/alert_events/http/
+ fields: [
+ [
+ 'incidentio-url-textbox',
+ 'https://api.incident.io/v2/alert_events/http/e2e-source',
+ ],
+ ['incidentio-token-textbox', 'e2e-token'],
+ ],
+ edit: ['incidentio-token-textbox', 'e2e-token-edited'],
+ spec: {
+ url: 'https://api.incident.io/v2/alert_events/http/e2e-source',
+ token: 'e2e-token',
+ },
+ },
+ {
+ label: 'Telegram',
+ kind: 'telegram',
+ // the API rejects a chat id of 0, so this one is deliberately non-zero
+ fields: [
+ ['telegram-bot-token-textbox', '123456:e2e-bot-token'],
+ ['telegram-chat-id-textbox', '-1001234567890'],
+ ],
+ edit: ['telegram-bot-token-textbox', '123456:e2e-bot-token-edited'],
+ spec: { botToken: '123456:e2e-bot-token', chatId: -1001234567890 },
+ },
+];
+
+export interface SeededChannel {
+ id: string;
+ name: string;
+}
+
+/** Everything a channel spec needs: the form labels, and the API equivalent. */
+export interface ChannelType {
+ label: string;
+ kind: string;
+ /** Only what the form refuses to save without, in the order it is filled. */
+ fields: [string, string][];
+ /**
+ * The field an edit pass changes, and the value to change it to. Spelled out
+ * per type rather than derived: appending to a Jira site or a Google Chat
+ * webhook breaks the format its validator demands, and the save then never
+ * leaves the page.
+ */
+ edit: [string, string];
+ spec: Record<string, unknown>;
+}
+
+export interface Channels {
+ list: ChannelList;
+ form: ChannelForm;
+ api: ChannelApi;
+}
+
+interface ChannelApi {
+ create(
+ name: string,
+ kind?: string,
+ spec?: Record<string, unknown>,
+ ): Promise<SeededChannel>;
+ remove(id: string | undefined): Promise<void>;
+}
+
+interface ChannelList {
+ goto(options?: { search?: string; kind?: string }): Promise<void>;
+ search(): Locator;
+ rows(): Locator;
+ row(name: string): Locator;
+ openRowMenu(name: string): Promise<void>;
+ chooseMenuItem(name: string): Promise<void>;
+ jsonDialog(): Locator;
+ noResults(): Locator;
+ deletePrompt(name: string): Locator;
+ confirmDelete(): Promise<void>;
+ clearSearch(): Promise<void>;
+}
+
+interface ChannelForm {
+ gotoNew(): Promise<void>;
+ name(): Locator;
+ pickType(label: string): Promise<void>;
+ fillField(testId: string, value: string): Promise<void>;
+ /** Saves and returns the id the API assigned, so the test can clean up. */
+ saveAndReturnId(): Promise<string>;
+ /** Saves an existing channel and waits for the write to land. */
+ saveEdit(): Promise<void>;
+ save(): Promise<void>;
+}
+
+/**
+ * Seeds a channel through the v2 API. The spec only has to be valid enough for
+ * the API to store it: nothing is ever delivered.
+ */
+async function createViaApi(
+ page: Page,
+ name: string,
+ kind = 'slack',
+ spec: Record<string, unknown> = {
+ apiUrl: 'https://hooks.slack.com/services/T/B/X',
+ channel: '#e2e',
+ },
+): Promise<SeededChannel> {
+ const token = await authToken(page);
+ const res = await page.request.post(CHANNELS_API, {
+ data: { generateName: true, displayName: name, config: { kind, spec } },
+ headers: { Authorization: `Bearer ${token}` },
+ });
+ if (!res.ok()) {
+ throw new Error(`POST ${CHANNELS_API} ${res.status()}: ${await res.text()}`);
+ }
+ const json = (await res.json()) as { data: { id: string } };
+ return { id: String(json.data.id), name };
+}
+
+/**
+ * Tolerates an empty id and an already-deleted channel, so a cleanup block
+ * never has to branch on whether the seed got that far.
+ */
+async function removeViaApi(page: Page, id: string | undefined): Promise<void> {
+ if (!id) {
+ return;
+ }
+
+ // A test that already failed often leaves a closed page behind, and a throw
+ // here would replace its error with one about the cleanup.
+ try {
+ const token = await authToken(page);
+ await page.request.delete(`${CHANNELS_API}/${id}`, {
+ headers: { Authorization: `Bearer ${token}` },
+ });
+ } catch {
+ /* the channel outlives the run rather than hiding why it failed */
+ }
+}
+
+function channelsDriver(page: Page): Channels {
+ const rows = (): Locator => page.locator('tbody tr');
+
+ const list: ChannelList = {
+ async goto({ search, kind } = {}) {
+ const url = new URL(PATH.list, 'http://localhost');
+ if (search) {
+ url.searchParams.set('search', search);
+ }
+ if (kind) {
+ url.searchParams.set('kind', kind);
+ }
+
+ await page.goto(`${url.pathname}${url.search}`);
+ await expect(list.search()).toBeVisible();
+ },
+ search: () => page.getByTestId('channels-search'),
+ rows,
+ row: (name) => rows().filter({ hasText: name }),
+ async openRowMenu(name) {
+ await page.getByRole('button', { name: `Actions for ${name}` }).click();
+ await expect(page.getByRole('menu')).toBeVisible();
+ },
+ async chooseMenuItem(name) {
+ await page.getByRole('menuitem', { name }).click();
+ },
+ jsonDialog: () => page.getByTestId('channel-json-dialog'),
+ noResults: () => page.getByText('No matching channels'),
+ deletePrompt: (name) =>
+ page.getByText(`Are you sure you want to delete the ${name} channel?`),
+ async confirmDelete() {
+ await Promise.all([
+ page.waitForResponse(
+ (r) => r.url().includes(CHANNELS_API) && r.request().method() === 'DELETE',
+ ),
+ page.getByRole('button', { name: 'Delete', exact: true }).click(),
+ ]);
+ },
+ async clearSearch() {
+ await page.getByRole('button', { name: 'Clear Search' }).click();
+ await expect(list.search()).toHaveValue('');
+ },
+ };
+
+ const form: ChannelForm = {
+ async gotoNew() {
+ await page.goto(PATH.new);
+ await expect(form.name()).toBeVisible();
+ },
+ name: () => page.getByTestId('channel-name-textbox'),
+ async pickType(label) {
+ await page.getByTestId('channel-type-select').click();
+ await page.getByRole('option', { name: label, exact: true }).click();
+ },
+ async fillField(testId, value) {
+ await page.getByTestId(testId).fill(value);
+ },
+ async saveAndReturnId() {
+ const [response] = await Promise.all([
+ page.waitForResponse(
+ (r) => r.url().includes(CHANNELS_API) && r.request().method() === 'POST',
+ ),
+ page.getByTestId('save-channel-button').click(),
+ ]);
+ return ((await response.json()) as { data: { id: string } }).data.id;
+ },
+ async saveEdit() {
+ await Promise.all([
+ page.waitForResponse(
+ (r) => r.url().includes(CHANNELS_API) && r.request().method() === 'PUT',
+ ),
+ page.getByTestId('save-channel-button').click(),
+ ]);
+ },
+ async save() {
+ await page.getByTestId('save-channel-button').click();
+ },
+ };
+
+ const api: ChannelApi = {
+ create: (name, kind, spec) => createViaApi(page, name, kind, spec),
+ remove: (id) => removeViaApi(page, id),
+ };
+
+ return { list, form, api };
+}
+
+const withChannels = driver('channels', ({ page }) => channelsDriver(page));
+
+// One slack and one email channel sharing a prefix, so a search can hold both
+// and the type filter has something to tell apart.
+const withChannelSet = seeded(
+ 'channelSet',
+ async ({ page, workerIndex }) => {
+ const prefix = `e2e-nc-${workerIndex}-${Date.now()}`;
+ const slack = await createViaApi(page, `${prefix}-slack`);
+ const email = await createViaApi(page, `${prefix}-email`, 'email', {
+ });
+ return { prefix, slack, email };
+ },
+ async ({ page, value }) => {
+ await removeViaApi(page, value.slack.id);
+ await removeViaApi(page, value.email.id);
+ },
+);
+
+export const test = withChannelSet(withChannels(kit));
+
+export { expect, onAdminPage } from './kit';
diff --git a/tests/e2e/tests/alerts/channels/create-each-type.spec.ts b/tests/e2e/tests/alerts/channels/create-each-type.spec.ts
new file mode 100644
index 0000000000..b1526b89ce
--- /dev/null
+++ b/tests/e2e/tests/alerts/channels/create-each-type.spec.ts
@@ -0,0 +1,36 @@
+import { CHANNEL_TYPES, expect, test } from '../../../drivers/channels';
+
+// One pass per channel type, filling only what the form refuses to save
+// without. The point is that every type can be created at all: a type whose
+// settings component or validator drifts fails here rather than in support.
+test.describe('Notification channels — create one of each type', () => {
+ CHANNEL_TYPES.forEach(({ label, fields }, index) => {
+ const number = String(index + 1).padStart(2, '0');
+
+ test(`TC-${number} a ${label} channel saves and shows up in the list`, async ({
+ channels,
+ }) => {
+ const slug = label.toLowerCase().replace(/[^a-z0-9]+/g, '-');
+ const name = `e2e-nct-${slug}-${Date.now()}`;
+ let id: string | undefined;
+
+ try {
+ await channels.form.gotoNew();
+ await channels.form.name().fill(name);
+ await channels.form.pickType(label);
+
+ for (const [testId, value] of fields) {
+ // eslint-disable-next-line no-await-in-loop
+ await channels.form.fillField(testId, value);
+ }
+
+ id = await channels.form.saveAndReturnId();
+
+ await channels.list.goto({ search: name });
+ await expect(channels.list.row(name)).toBeVisible();
+ } finally {
+ await channels.api.remove(id);
+ }
+ });
+ });
+});
diff --git a/tests/e2e/tests/alerts/channels/create.spec.ts b/tests/e2e/tests/alerts/channels/create.spec.ts
new file mode 100644
index 0000000000..2910407e11
--- /dev/null
+++ b/tests/e2e/tests/alerts/channels/create.spec.ts
@@ -0,0 +1,43 @@
+import { expect, test } from '../../../drivers/channels';
+
+test.describe('Notification channels — create', () => {
+ test('TC-01 a webhook channel saves and shows up in the list', async ({
+ channels,
+ }) => {
+ const name = `e2e-ncc-${Date.now()}`;
+ let id: string | undefined;
+
+ try {
+ await channels.form.gotoNew();
+ await channels.form.name().fill(name);
+ await channels.form.pickType('Webhook');
+ await channels.form.fillField(
+ 'webhook-url-textbox',
+ 'https://example.test/e2e-hook',
+ );
+
+ id = await channels.form.saveAndReturnId();
+
+ await channels.list.goto({ search: name });
+ await expect(channels.list.row(name)).toBeVisible();
+ } finally {
+ await channels.api.remove(id);
+ }
+ });
+
+ test('TC-02 saving without a name reports the missing field', async ({
+ channels,
+ authedPage,
+ }) => {
+ await channels.form.gotoNew();
+ // Save stays off until the form is touched, so the webhook goes in first and
+ // the name is what is left missing.
+ await channels.form.fillField(
+ 'webhook-url-textbox',
+ 'https://hooks.slack.com/services/T/B/X',
+ );
+ await channels.form.save();
+
+ await expect(authedPage.getByText('Channel name is mandatory')).toBeVisible();
+ });
+});
diff --git a/tests/e2e/tests/alerts/channels/delete.spec.ts b/tests/e2e/tests/alerts/channels/delete.spec.ts
new file mode 100644
index 0000000000..7b985d1f59
--- /dev/null
+++ b/tests/e2e/tests/alerts/channels/delete.spec.ts
@@ -0,0 +1,24 @@
+import { expect, test } from '../../../drivers/channels';
+
+test.describe('Notification channels — delete', () => {
+ test('TC-01 deleting from the row menu takes the channel out of the list', async ({
+ channels,
+ }) => {
+ const name = `e2e-ncd-${Date.now()}`;
+ const { id } = await channels.api.create(name);
+
+ try {
+ await channels.list.goto({ search: name });
+ await channels.list.openRowMenu(name);
+ await channels.list.chooseMenuItem('Delete');
+
+ await expect(channels.list.deletePrompt(name)).toBeVisible();
+ await channels.list.confirmDelete();
+
+ await expect(channels.list.row(name)).toHaveCount(0);
+ } finally {
+ // the test deletes it; this only catches a run that stopped earlier
+ await channels.api.remove(id);
+ }
+ });
+});
diff --git a/tests/e2e/tests/alerts/channels/edit-each-type.spec.ts b/tests/e2e/tests/alerts/channels/edit-each-type.spec.ts
new file mode 100644
index 0000000000..a44b2aaf7d
--- /dev/null
+++ b/tests/e2e/tests/alerts/channels/edit-each-type.spec.ts
@@ -0,0 +1,39 @@
+import { CHANNEL_TYPES, expect, test } from '../../../drivers/channels';
+
+// The mirror of the create pass: seed a channel of each type through the API,
+// open it, change the field its table entry nominates and check the change
+// survives a reload. A prefill or a save that drops a type's fields fails here.
+test.describe('Notification channels — edit one of each type', () => {
+ CHANNEL_TYPES.forEach(({ label, kind, fields, edit, spec }, index) => {
+ const number = String(index + 1).padStart(2, '0');
+ const [testId, edited] = edit;
+ // every entry nominates one of its own required fields, so a miss here
+ // fails the assertion below rather than skipping it
+ const original = fields.find(([id]) => id === testId)?.[1] ?? '';
+
+ test(`TC-${number} an edited ${label} channel keeps its change`, async ({
+ channels,
+ authedPage,
+ }) => {
+ const slug = label.toLowerCase().replace(/[^a-z0-9]+/g, '-');
+ const name = `e2e-nte-${slug}-${Date.now()}`;
+ let id: string | undefined;
+
+ try {
+ ({ id } = await channels.api.create(name, kind, spec));
+
+ await authedPage.goto(`/alerts/channels/edit/${id}`);
+ const field = authedPage.getByTestId(testId);
+ await expect(field).toHaveValue(original);
+
+ await field.fill(edited);
+ await channels.form.saveEdit();
+
+ await authedPage.goto(`/alerts/channels/edit/${id}`);
+ await expect(authedPage.getByTestId(testId)).toHaveValue(edited);
+ } finally {
+ await channels.api.remove(id);
+ }
+ });
+ });
+});
diff --git a/tests/e2e/tests/alerts/channels/list.spec.ts b/tests/e2e/tests/alerts/channels/list.spec.ts
new file mode 100644
index 0000000000..a2de48f3d0
--- /dev/null
+++ b/tests/e2e/tests/alerts/channels/list.spec.ts
@@ -0,0 +1,63 @@
+import { expect, test } from '../../../drivers/channels';
+
+test.describe('Notification channels — list', () => {
+ test('TC-01 search narrows the list to the matching channel', async ({
+ channels,
+ channelSet,
+ }) => {
+ await channels.list.goto({ search: channelSet.prefix });
+ await expect(channels.list.rows()).toHaveCount(2);
+
+ await channels.list.search().fill(channelSet.slack.name);
+ await expect(channels.list.row(channelSet.slack.name)).toBeVisible();
+ await expect(channels.list.row(channelSet.email.name)).toHaveCount(0);
+ });
+
+ test('TC-02 the kind filter keeps only channels of that kind', async ({
+ channels,
+ channelSet,
+ }) => {
+ await channels.list.goto({ search: channelSet.prefix, kind: 'email' });
+
+ await expect(channels.list.row(channelSet.email.name)).toBeVisible();
+ await expect(channels.list.row(channelSet.slack.name)).toHaveCount(0);
+ });
+
+ test('TC-03 a search matching nothing offers to clear itself', async ({
+ channels,
+ channelSet,
+ }) => {
+ await channels.list.goto({ search: `${channelSet.prefix}-nothing-matches` });
+
+ await expect(channels.list.noResults()).toBeVisible();
+ await channels.list.clearSearch();
+ });
+
+ test('TC-04 clicking a row opens that channel for editing', async ({
+ channels,
+ channelSet,
+ authedPage,
+ }) => {
+ await channels.list.goto({ search: channelSet.slack.name });
+ await channels.list.row(channelSet.slack.name).click();
+
+ await authedPage.waitForURL(/\/alerts\/channels\/edit\//);
+ await expect(channels.form.name()).toHaveValue(channelSet.slack.name);
+ });
+
+ test('TC-05 View JSON shows the channel with its secrets masked', async ({
+ channels,
+ channelSet,
+ authedPage,
+ }) => {
+ await channels.list.goto({ search: channelSet.slack.name });
+ await channels.list.openRowMenu(channelSet.slack.name);
+ await channels.list.chooseMenuItem('View JSON');
+
+ await expect(channels.list.jsonDialog()).toBeVisible();
+ await expect(channels.list.jsonDialog()).toContainText('"kind": "slack"');
+ await expect(
+ authedPage.getByTestId('channel-json-toggle-secrets'),
+ ).toBeVisible();
+ });
+});