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.

3.2 KB
Raw Blame
import type { Meta, StoryObj } from '@storybook/react-vite';
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
import ROUTES from 'constants/routes';

import { storyMocks } from '@/storybook/controls/defineStoryMocks';
import type { PageStoryArgs } from '@/storybook/runtime/resolveStory';

import { integrationsMocks } from './IntegrationsModulePage.stories.mocks';
import IntegrationsModulePage from '../IntegrationsModulePage';

type IntegrationsArgs = PageStoryArgs<typeof integrationsMocks>;

const pageStory = storyMocks(integrationsMocks, {
	route: ROUTES.INTEGRATIONS,
	layout: 'app',
});

/**
 * The integrations catalogue, installed ones first.
 *
 * Route: `/integrations`.
 */
const meta = {
	title: 'Pages/Integrations/List',
	tags: ['play'],
	component: IntegrationsModulePage,
	...pageStory,
	parameters: { ...pageStory.parameters },
} satisfies Meta<IntegrationsArgs>;

export default meta;

type Story = StoryObj<IntegrationsArgs>;

/** The list fetches before it renders a row, which outlasts the 1s default. */
const untilLoaded = { timeout: 15_000 };

const search = async (
	canvasElement: HTMLElement,
	query: string,
): Promise<void> => {
	const input = await within(canvasElement).findByPlaceholderText(
		/search for an integration/i,
		undefined,
		untilLoaded,
	);

	await userEvent.type(input, query);
};

/**
 * The integrations a workspace can install: the three cloud providers SigNoz
 * sets up in one click, then every built-in integration with who published it
 * and whether it is installed.
 */
export const Default: Story = {};

/**
 * A search that matches nothing, which both sections answer for themselves.
 * The search filters what is already loaded, so no request goes out for it.
 */
export const NoSearchMatches: Story = {
	play: async ({ canvasElement }): Promise<void> => {
		await search(canvasElement, 'kafka');
		await within(canvasElement).findAllByText(/no integrations found/i);
	},
};

/**
 * The form for an integration SigNoz does not publish yet. Submitting it is a
 * telemetry event, not an endpoint.
 */
export const RequestIntegration: Story = {
	play: async ({ canvasElement }): Promise<void> => {
		await userEvent.click(
			await within(canvasElement).findByText(
				/request integration/i,
				undefined,
				untilLoaded,
			),
		);
		await userEvent.type(
			await screen.findByPlaceholderText(/enter integration name/i),
			'Kafka',
		);
	},
};

/**
 * Submitting the request form raises "Integration Request Submitted" when the
 * event is accepted. Set Request submission to `error` for the failure toast, or
 * `loading` to keep the submit button spinning.
 */
export const RequestIntegrationToast: Story = {
	play: async ({ canvasElement, args }): Promise<void> => {
		await userEvent.click(
			await within(canvasElement).findByText(
				/request integration/i,
				undefined,
				untilLoaded,
			),
		);
		await userEvent.type(
			await screen.findByPlaceholderText(/enter integration name/i),
			'Kafka',
		);
		await userEvent.click(await screen.findByRole('button', { name: /submit/i }));
		if (args.requestSubmission === 'success') {
			await waitFor(() =>
				expect(screen.getByText(/integration request submitted/i)).toBeVisible(),
			);
		}
	},
};