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.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
import WidgetHeader from 'container/WidgetCard/Header';
import { mockAppLocation } from 'tests/router-mocks';
import { fireEvent, render } from 'tests/test-utils';
import { QueryTable } from '../QueryTable';
import { QueryTableProps, WidgetHeaderProps } from './mocks';
mockAppLocation({ pathname: '' });
// Mock useDashabord hook
jest.mock('hooks/useSafeNavigate', () => ({
useSafeNavigate: (): any => ({
safeNavigate: jest.fn(),
}),
}));
describe('QueryTable -', () => {
it('should render correctly with all the data rows', () => {
const { container } = render(<QueryTable {...QueryTableProps} />);
const tableRows = container.querySelectorAll('tr.ant-table-row');
expect(tableRows).toHaveLength(QueryTableProps.queryTableData.rows.length);
});
it('should render correctly with searchTerm', () => {
const { container } = render(
<QueryTable {...QueryTableProps} searchTerm="frontend" />,
);
const tableRows = container.querySelectorAll('tr.ant-table-row');
expect(tableRows).toHaveLength(3);
});
});
const setSearchTerm = jest.fn();
describe('WidgetHeader -', () => {
it('global search option should be working', () => {
const { getByText, getByTestId } = render(
<WidgetHeader {...WidgetHeaderProps} setSearchTerm={setSearchTerm} />,
);
expect(getByText('Table - Panel')).toBeInTheDocument();
const searchWidget = getByTestId('widget-header-search');
expect(searchWidget).toBeInTheDocument();
// click and open the search input
fireEvent.click(searchWidget);
// check if input is opened
const searchInput = getByTestId('widget-header-search-input');
expect(searchInput).toBeInTheDocument();
// enter search term
fireEvent.change(searchInput, { target: { value: 'frontend' } });
// check if search term is set
expect(setSearchTerm).toHaveBeenCalledWith('frontend');
expect(searchInput).toHaveValue('frontend');
});
it('global search should not be present for non-table panel', () => {
const { queryByTestId } = render(
<WidgetHeader
{...WidgetHeaderProps}
widget={{ ...WidgetHeaderProps.widget, panelTypes: 'chart' }}
/>,
);
expect(queryByTestId('widget-header-search')).not.toBeInTheDocument();
});
});