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.

1.7 KB
Raw Blame
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { mockAppParams } from 'tests/router-mocks';

import { APPLICATION_SETTINGS } from '../constants';
import { thresholdMockData } from './__mock__/thresholdMockData';
import ApDexApplication from './ApDexApplication';

mockAppParams({ servicename: 'mockServiceName' });

jest.mock('hooks/apDex/useGetApDexSettings', () => ({
	__esModule: true,
	useGetApDexSettings: jest.fn().mockReturnValue({
		data: thresholdMockData,
		isLoading: false,
		error: null,
		refetch: jest.fn(),
	}),
}));

jest.mock('hooks/apDex/useSetApDexSettings', () => ({
	__esModule: true,
	useSetApDexSettings: jest.fn().mockReturnValue({
		mutateAsync: jest.fn(),
		isLoading: false,
		error: null,
	}),
}));

describe('ApDexApplication', () => {
	it('should render the component', () => {
		render(<ApDexApplication />);

		expect(screen.getByText('Settings')).toBeInTheDocument();
	});

	it('should open the popover when the settings button is clicked', async () => {
		render(<ApDexApplication />);

		const button = screen.getByText('Settings');
		fireEvent.click(button);
		await waitFor(() => {
			expect(screen.getByText(APPLICATION_SETTINGS)).toBeInTheDocument();
		});
	});

	it('should close the popover when the close button is clicked', async () => {
		render(<ApDexApplication />);

		const button = screen.getByText('Settings');
		fireEvent.click(button);
		await waitFor(() => {
			expect(screen.getByText(APPLICATION_SETTINGS)).toBeInTheDocument();
		});

		const closeButton = screen.getByText('Cancel');
		fireEvent.click(closeButton);
		await waitFor(() => {
			expect(screen.queryByText(APPLICATION_SETTINGS)).not.toBeInTheDocument();
		});
	});
});