mirror of
https://github.com/SigNoz/signoz.git
synced 2026-11-22 16:20:58 +00:00
Compare commits
2 Commits
docs/css-m
...
feat/trace
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fbd0a1875f | ||
|
|
6793315a27 |
@@ -1,13 +1,20 @@
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { Provider } from 'react-redux';
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { message } from 'antd';
|
||||
import configureStore from 'redux-mock-store';
|
||||
import { PANEL_TYPES } from 'constants/queryBuilder';
|
||||
import store from 'store';
|
||||
import { Query } from 'types/api/queryBuilder/queryBuilderData';
|
||||
import { TelemetryFieldKey } from 'types/api/v5/queryRange';
|
||||
import { EQueryType } from 'types/common/dashboard';
|
||||
import { DataSource, StringOperators } from 'types/common/queryBuilder';
|
||||
import {
|
||||
fireEvent,
|
||||
render,
|
||||
screen,
|
||||
userEvent,
|
||||
waitFor,
|
||||
} from 'tests/test-utils';
|
||||
|
||||
import '@testing-library/jest-dom';
|
||||
|
||||
@@ -36,6 +43,12 @@ jest.mock('hooks/queryBuilder/useQueryBuilder', () => ({
|
||||
useQueryBuilder: (): any => mockUseQueryBuilder(),
|
||||
}));
|
||||
|
||||
const statusColumn: TelemetryFieldKey = {
|
||||
name: 'http.status',
|
||||
fieldDataType: 'int64',
|
||||
fieldContext: 'attribute',
|
||||
};
|
||||
|
||||
const mockStore = configureStore([]);
|
||||
const createMockReduxStore = (): any =>
|
||||
mockStore({
|
||||
@@ -79,11 +92,21 @@ const createMockStagedQuery = (dataSource: DataSource): Query => ({
|
||||
clickhouse_sql: [],
|
||||
});
|
||||
|
||||
const renderWithStore = (dataSource: DataSource): void => {
|
||||
const renderWithStore = (
|
||||
dataSource: DataSource,
|
||||
{
|
||||
panelType,
|
||||
selectedColumns,
|
||||
}: { panelType?: PANEL_TYPES; selectedColumns?: TelemetryFieldKey[] } = {},
|
||||
): void => {
|
||||
const mockReduxStore = createMockReduxStore();
|
||||
render(
|
||||
<Provider store={mockReduxStore}>
|
||||
<DownloadOptionsMenu dataSource={dataSource} />
|
||||
<DownloadOptionsMenu
|
||||
dataSource={dataSource}
|
||||
panelType={panelType}
|
||||
selectedColumns={selectedColumns}
|
||||
/>
|
||||
</Provider>,
|
||||
);
|
||||
};
|
||||
@@ -118,11 +141,7 @@ describe.each([
|
||||
expect(screen.getByText('FORMAT')).toBeInTheDocument();
|
||||
expect(screen.getByText('Number of Rows')).toBeInTheDocument();
|
||||
|
||||
if (dataSource === DataSource.TRACES) {
|
||||
expect(screen.queryByText('Columns')).not.toBeInTheDocument();
|
||||
} else {
|
||||
expect(screen.getByText('Columns')).toBeInTheDocument();
|
||||
}
|
||||
expect(screen.getByTestId('export-columns-scope-item-all')).toBeChecked();
|
||||
});
|
||||
|
||||
it('allows changing export format', () => {
|
||||
@@ -152,17 +171,6 @@ describe.each([
|
||||
});
|
||||
|
||||
it('allows changing columns scope', () => {
|
||||
if (dataSource === DataSource.TRACES) {
|
||||
renderWithStore(dataSource);
|
||||
fireEvent.click(screen.getByTestId(testId));
|
||||
|
||||
expect(screen.queryByRole('radio', { name: 'All' })).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByRole('radio', { name: 'Selected' }),
|
||||
).not.toBeInTheDocument();
|
||||
return;
|
||||
}
|
||||
|
||||
renderWithStore(dataSource);
|
||||
fireEvent.click(screen.getByTestId(testId));
|
||||
|
||||
@@ -239,20 +247,14 @@ describe.each([
|
||||
|
||||
it('keeps selectColumns when column scope is Selected', async () => {
|
||||
const mockQuery = createMockStagedQuery(dataSource);
|
||||
mockQuery.builder.queryData[0].selectColumns = [
|
||||
{ name: 'http.status', fieldDataType: 'int64', fieldContext: 'attribute' },
|
||||
] as any;
|
||||
mockQuery.builder.queryData[0].selectColumns = [statusColumn];
|
||||
|
||||
const user = userEvent.setup({ pointerEventsCheck: 0 });
|
||||
mockUseQueryBuilder.mockReturnValue({ stagedQuery: mockQuery });
|
||||
renderWithStore(dataSource);
|
||||
fireEvent.click(screen.getByTestId(testId));
|
||||
|
||||
// For traces, column scope is always Selected and the radio is hidden
|
||||
if (dataSource !== DataSource.TRACES) {
|
||||
fireEvent.click(screen.getByRole('radio', { name: 'Selected' }));
|
||||
}
|
||||
|
||||
fireEvent.click(screen.getByText('Export'));
|
||||
await user.click(screen.getByTestId(testId));
|
||||
await user.click(screen.getByTestId('export-columns-scope-item-selected'));
|
||||
await user.click(screen.getByTestId('export-options-submit'));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockDownloadExportData).toHaveBeenCalledTimes(1);
|
||||
@@ -268,15 +270,15 @@ describe.each([
|
||||
});
|
||||
|
||||
it('sends no selectFields when column scope is All', async () => {
|
||||
// For traces, column scope is always Selected — this test only applies to other sources
|
||||
if (dataSource === DataSource.TRACES) {
|
||||
return;
|
||||
}
|
||||
const user = userEvent.setup({ pointerEventsCheck: 0 });
|
||||
const mockQuery = createMockStagedQuery(dataSource);
|
||||
mockQuery.builder.queryData[0].selectColumns = [statusColumn];
|
||||
|
||||
mockUseQueryBuilder.mockReturnValue({ stagedQuery: mockQuery });
|
||||
renderWithStore(dataSource);
|
||||
fireEvent.click(screen.getByTestId(testId));
|
||||
fireEvent.click(screen.getByRole('radio', { name: 'All' }));
|
||||
fireEvent.click(screen.getByText('Export'));
|
||||
await user.click(screen.getByTestId(testId));
|
||||
await user.click(screen.getByTestId('export-columns-scope-item-all'));
|
||||
await user.click(screen.getByTestId('export-options-submit'));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockDownloadExportData).toHaveBeenCalledTimes(1);
|
||||
@@ -286,6 +288,37 @@ describe.each([
|
||||
});
|
||||
});
|
||||
|
||||
it('exports all fields by default when the view has columns selected', async () => {
|
||||
const user = userEvent.setup({ pointerEventsCheck: 0 });
|
||||
renderWithStore(dataSource, { selectedColumns: [statusColumn] });
|
||||
await user.click(screen.getByTestId(testId));
|
||||
await user.click(screen.getByTestId('export-options-submit'));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockDownloadExportData).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
const query =
|
||||
mockDownloadExportData.mock.calls[0][0].body.compositeQuery.queries[0];
|
||||
expect(query.spec.selectFields).toBeUndefined();
|
||||
});
|
||||
|
||||
it("exports the view's selected columns when column scope is Selected", async () => {
|
||||
const user = userEvent.setup({ pointerEventsCheck: 0 });
|
||||
renderWithStore(dataSource, { selectedColumns: [statusColumn] });
|
||||
await user.click(screen.getByTestId(testId));
|
||||
await user.click(screen.getByTestId('export-columns-scope-item-selected'));
|
||||
await user.click(screen.getByTestId('export-options-submit'));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockDownloadExportData).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
const query =
|
||||
mockDownloadExportData.mock.calls[0][0].body.compositeQuery.queries[0];
|
||||
expect(query.spec.selectFields).toStrictEqual([
|
||||
expect.objectContaining({ name: 'http.status', fieldDataType: 'int64' }),
|
||||
]);
|
||||
});
|
||||
|
||||
it('handles successful export with success message', async () => {
|
||||
renderWithStore(dataSource);
|
||||
fireEvent.click(screen.getByTestId(testId));
|
||||
@@ -340,6 +373,44 @@ describe.each([
|
||||
});
|
||||
});
|
||||
|
||||
describe('DownloadOptionsMenu in the trace view', () => {
|
||||
const testId = `periscope-btn-download-${DataSource.TRACES}`;
|
||||
|
||||
beforeEach(() => {
|
||||
mockDownloadExportData.mockReset().mockResolvedValue(undefined);
|
||||
});
|
||||
|
||||
it('hides columns scope', async () => {
|
||||
const user = userEvent.setup({ pointerEventsCheck: 0 });
|
||||
mockUseQueryBuilder.mockReturnValue({
|
||||
stagedQuery: createMockStagedQuery(DataSource.TRACES),
|
||||
});
|
||||
renderWithStore(DataSource.TRACES, { panelType: PANEL_TYPES.TRACE });
|
||||
await user.click(screen.getByTestId(testId));
|
||||
|
||||
expect(screen.queryByTestId('export-columns-scope')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps the query's stored columns", async () => {
|
||||
const user = userEvent.setup({ pointerEventsCheck: 0 });
|
||||
const query = createMockStagedQuery(DataSource.TRACES);
|
||||
query.builder.queryData[0].selectColumns = [statusColumn];
|
||||
mockUseQueryBuilder.mockReturnValue({ stagedQuery: query });
|
||||
renderWithStore(DataSource.TRACES, { panelType: PANEL_TYPES.TRACE });
|
||||
await user.click(screen.getByTestId(testId));
|
||||
await user.click(screen.getByTestId('export-options-submit'));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockDownloadExportData).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
const exported =
|
||||
mockDownloadExportData.mock.calls[0][0].body.compositeQuery.queries[0];
|
||||
expect(exported.spec.selectFields).toStrictEqual([
|
||||
expect.objectContaining({ name: 'http.status', fieldDataType: 'int64' }),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('DownloadOptionsMenu for traces with queryTraceOperator', () => {
|
||||
const dataSource = DataSource.TRACES;
|
||||
const testId = `periscope-btn-download-${dataSource}`;
|
||||
|
||||
@@ -46,7 +46,7 @@ export default function DownloadOptionsMenu({
|
||||
format: exportFormat,
|
||||
rowLimit,
|
||||
clearSelectColumns:
|
||||
dataSource !== DataSource.TRACES &&
|
||||
panelType !== PANEL_TYPES.TRACE &&
|
||||
columnsScope === DownloadColumnsScopes.ALL,
|
||||
selectedColumns,
|
||||
});
|
||||
@@ -56,7 +56,7 @@ export default function DownloadOptionsMenu({
|
||||
columnsScope,
|
||||
selectedColumns,
|
||||
handleExportRawData,
|
||||
dataSource,
|
||||
panelType,
|
||||
]);
|
||||
|
||||
const popoverContent = useMemo(
|
||||
@@ -96,7 +96,7 @@ export default function DownloadOptionsMenu({
|
||||
/>
|
||||
</div>
|
||||
|
||||
{dataSource !== DataSource.TRACES && (
|
||||
{panelType !== PANEL_TYPES.TRACE && (
|
||||
<>
|
||||
<div className="horizontal-line" />
|
||||
|
||||
@@ -104,6 +104,7 @@ export default function DownloadOptionsMenu({
|
||||
<Typography.Text className="title">Columns</Typography.Text>
|
||||
<RadioGroup
|
||||
color="primary"
|
||||
testId="export-columns-scope"
|
||||
value={columnsScope}
|
||||
onChange={setColumnsScope}
|
||||
items={[
|
||||
@@ -123,6 +124,7 @@ export default function DownloadOptionsMenu({
|
||||
width="100%"
|
||||
onClick={handleExport}
|
||||
loading={isDownloading}
|
||||
testId="export-options-submit"
|
||||
>
|
||||
Export
|
||||
</Button>
|
||||
@@ -134,7 +136,7 @@ export default function DownloadOptionsMenu({
|
||||
columnsScope,
|
||||
isDownloading,
|
||||
handleExport,
|
||||
dataSource,
|
||||
panelType,
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ export function useExportRawData({
|
||||
setIsDownloading(true);
|
||||
|
||||
const selectColumnsOverride = clearSelectColumns
|
||||
? {}
|
||||
? { selectColumns: [] }
|
||||
: selectedColumns?.length
|
||||
? { selectColumns: selectedColumns }
|
||||
: {};
|
||||
|
||||
@@ -7,6 +7,7 @@ import { type TracesArgs, tracesMocks } from './TracesModulePage.stories.mocks';
|
||||
import {
|
||||
dirtyQuickFiltersSettings,
|
||||
loadNextListPage,
|
||||
openDownloadOptions,
|
||||
openQuickFiltersSettings,
|
||||
showRootSpansNextPage,
|
||||
suggestBooleanValues,
|
||||
@@ -67,6 +68,15 @@ export const ListNextPage: Story = {
|
||||
play: loadNextListPage,
|
||||
};
|
||||
|
||||
/**
|
||||
* The List view's export menu: format, row count, and whether to export all
|
||||
* span fields or only the selected columns. The Trace view's menu has no
|
||||
* columns choice.
|
||||
*/
|
||||
export const DownloadOptions: Story = {
|
||||
play: openDownloadOptions,
|
||||
};
|
||||
|
||||
/** The charted view of the same trace query. */
|
||||
export const Timeseries: Story = {
|
||||
args: { view: ExplorerViews.TIMESERIES },
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
} from 'components/QueryBuilderV2/QueryV2/QuerySearch/stories/__story_mockdata__/querySearch.play';
|
||||
import { QuickFilterManagePermissions } from 'lib/authz/hooks/useAuthZ/permissions/quick-filter.permissions';
|
||||
import { ExplorerViews } from 'pages/LogsExplorer/utils';
|
||||
import { DataSource } from 'types/common/queryBuilder';
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
|
||||
import { grantsAll } from '@/storybook/access/access';
|
||||
@@ -87,6 +88,35 @@ export const loadNextListPage = async ({
|
||||
}, untilLoaded);
|
||||
};
|
||||
|
||||
export const openDownloadOptions = async ({
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
const inTraceView = showsView(args, ExplorerViews.TRACE);
|
||||
if (!inTraceView && !showsView(args, ExplorerViews.LIST)) {
|
||||
return;
|
||||
}
|
||||
|
||||
await userEvent.click(
|
||||
await screen.findByTestId(
|
||||
`periscope-btn-download-${DataSource.TRACES}`,
|
||||
{},
|
||||
untilLoaded,
|
||||
),
|
||||
);
|
||||
await screen.findByRole('dialog', { name: 'Export options' });
|
||||
|
||||
if (inTraceView) {
|
||||
await expect(
|
||||
screen.queryByTestId('export-columns-scope'),
|
||||
).not.toBeInTheDocument();
|
||||
return;
|
||||
}
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('export-columns-scope')).toBeVisible(),
|
||||
);
|
||||
};
|
||||
|
||||
export const openQuickFiltersSettings = async ({
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
|
||||
Reference in New Issue
Block a user