Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"build:clickhouse": "NEXT_PUBLIC_IS_LOCAL_MODE=true NEXT_PUBLIC_CLICKHOUSE_BUILD=true next build --webpack && node scripts/prepare-clickhouse-build-export.js",
"run:clickhouse": "test -d out && npx rimraf tmp && mkdir tmp && cp -r out tmp/clickstack && echo 'visit http://localhost:3000/clickstack to start' && npx serve tmp -l 3000 || echo 'run build:clickhouse first'",
"start": "next start",
"lint": "node ../../scripts/ci/oxlint-warnings.mjs --max-warnings 534 && yarn run -T oxfmt --check '**/*.{ts,tsx,css,scss}'",
"lint": "node ../../scripts/ci/oxlint-warnings.mjs --max-warnings 468 && yarn run -T oxfmt --check '**/*.{ts,tsx,css,scss}'",
"lint:fix": "yarn run -T oxlint --fix && yarn run -T oxfmt '**/*.{ts,tsx,css,scss}'",
"lint:styles": "stylelint **/*/*.{css,scss}",
"ci:lint": "yarn lint && yarn tsc --noEmit && yarn lint:styles --quiet",
Expand Down
8 changes: 2 additions & 6 deletions packages/app/src/__tests__/SessionSidePanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,8 @@ jest.mock('@mantine/notifications', () => {
};
});

const mockedCopy = copyTextToClipboard as jest.MockedFunction<
typeof copyTextToClipboard
>;
const mockedShow = notifications.show as jest.MockedFunction<
typeof notifications.show
>;
const mockedCopy = jest.mocked(copyTextToClipboard);
const mockedShow = jest.mocked(notifications.show);

function setLocationHref(url: string) {
const parsed = new URL(url, 'http://localhost');
Expand Down
18 changes: 10 additions & 8 deletions packages/app/src/__tests__/Spotlights.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { DisplayType } from '@hyperdx/common-utils/dist/types';
import { spotlight } from '@mantine/spotlight';
import { act, renderHook, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { fromPartial } from '@total-typescript/shoehorn';

import { useDashboards } from '@/dashboard';
import { useSavedSearches } from '@/savedSearch';
Expand Down Expand Up @@ -30,8 +32,8 @@ jest.mock('next/router', () => ({
jest.mock('../savedSearch');
jest.mock('../dashboard');

const mockUseSavedSearches = useSavedSearches as jest.Mock;
const mockUseDashboards = useDashboards as jest.Mock;
const mockUseSavedSearches = jest.mocked(useSavedSearches);
const mockUseDashboards = jest.mocked(useDashboards);

describe('useSpotlightActions', () => {
const mockSavedSearches = {
Expand All @@ -42,7 +44,7 @@ describe('useSpotlightActions', () => {
name: 'save template1',
select: '',
where: '200',
whereLanguage: 'lucene',
whereLanguage: 'lucene' as const,
orderBy: '',
source: '67c25aeee3b6d5e2f24437b3',
tags: [],
Expand Down Expand Up @@ -71,13 +73,13 @@ describe('useSpotlightActions', () => {
{
aggFn: 'count',
aggCondition: '200',
aggConditionLanguage: 'lucene',
aggConditionLanguage: 'lucene' as const,
valueExpression: '',
},
],
where: '',
whereLanguage: 'lucene',
displayType: 'line',
whereLanguage: 'lucene' as const,
displayType: DisplayType.Line,
granularity: 'auto',
source: '67c25aeee3b6d5e2f24437b3',
},
Expand All @@ -97,8 +99,8 @@ describe('useSpotlightActions', () => {
beforeEach(() => {
jest.clearAllMocks();
window.localStorage.clear();
mockUseSavedSearches.mockReturnValue(mockSavedSearches);
mockUseDashboards.mockReturnValue(mockSavedDashboard);
mockUseSavedSearches.mockReturnValue(fromPartial(mockSavedSearches));
mockUseDashboards.mockReturnValue(fromPartial(mockSavedDashboard));
});
it('saved searches and dashboards should be loaded', () => {
const { result } = renderHook(() => useSpotlightActions());
Expand Down
51 changes: 38 additions & 13 deletions packages/app/src/__tests__/dashboard.remote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jest.mock('@tanstack/react-query', () => ({
jest.mock('@/utils', () => ({ hashCode: jest.fn(() => 0) }));

import { LEGACY_CHART_PALETTE_TOKEN_MAP } from '@hyperdx/common-utils/dist/types';
import { fromPartial } from '@total-typescript/shoehorn';

import { hdxServer } from '@/api';
import {
Expand All @@ -47,7 +48,7 @@ import {
useUpdateDashboard,
} from '@/dashboard';

const hdxServerMock = hdxServer as jest.Mock;
const hdxServerMock = jest.mocked(hdxServer);

const LEGACY_TO_HUE_CASES = Object.entries(LEGACY_CHART_PALETTE_TOKEN_MAP);

Expand All @@ -61,9 +62,11 @@ const remoteDashboardWithTileColor = (color: unknown) => [
];

const setRemotePayload = (payload: unknown) => {
hdxServerMock.mockReturnValue({
json: jest.fn().mockResolvedValue(payload),
});
hdxServerMock.mockReturnValue(
fromPartial({
json: jest.fn().mockResolvedValue(payload),
}),
);
};

beforeEach(() => {
Expand Down Expand Up @@ -145,9 +148,11 @@ describe('useCreateDashboard / useUpdateDashboard write-time normalization', ()
beforeEach(() => {
// hdxServer is invoked as `hdxServer(url, opts).json<T>()` for POST
// but as `hdxServer(url, opts)` for PATCH; mock to handle both.
hdxServerMock.mockReturnValue({
json: jest.fn().mockResolvedValue({ id: 'a' }),
});
hdxServerMock.mockReturnValue(
fromPartial({
json: jest.fn().mockResolvedValue({ id: 'a' }),
}),
);
});

it('rewrites legacy chart-N to hue tokens before POST in useCreateDashboard', async () => {
Expand Down Expand Up @@ -192,10 +197,21 @@ describe('useCreateDashboard / useUpdateDashboard write-time normalization', ()
tags: [],
});

const call = hdxServerMock.mock.calls[0];
expect(call[1].json.tiles[0].config).toMatchObject({
color: 'chart-future-magenta',
});
expect(hdxServerMock).toHaveBeenNthCalledWith(
1,
'dashboards',
expect.objectContaining({
json: expect.objectContaining({
tiles: [
expect.objectContaining({
config: expect.objectContaining({
color: 'chart-future-magenta',
}),
}),
],
}),
}),
);
});

it('rewrites legacy chart-N to hue tokens before PATCH in useUpdateDashboard', async () => {
Expand Down Expand Up @@ -236,8 +252,17 @@ describe('useCreateDashboard / useUpdateDashboard write-time normalization', ()
],
});

const call = hdxServerMock.mock.calls[0];
expect(call[1].json.tiles[0].config).toEqual({ color: 'chart-orange' });
expect(hdxServerMock).toHaveBeenNthCalledWith(
1,
'dashboards/a',
expect.objectContaining({
json: expect.objectContaining({
tiles: [
expect.objectContaining({ config: { color: 'chart-orange' } }),
],
}),
}),
);
});
});

Expand Down
31 changes: 18 additions & 13 deletions packages/app/src/__tests__/source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@hyperdx/common-utils/dist/types';
import { notifications } from '@mantine/notifications';
import { renderHook } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';

import {
getBuilderValueColumnCount,
Expand Down Expand Up @@ -318,19 +319,21 @@ describe('useUpdateSource', () => {
});

describe('useSources validation notifications', () => {
const mockUseQuery = useQuery as jest.Mock;
const mockHdxServer = hdxServer as jest.Mock;
const mockShow = notifications.show as jest.Mock;
const mockUseQuery = jest.mocked(useQuery);
const mockHdxServer = jest.mocked(hdxServer);
const mockShow = jest.mocked(notifications.show);

beforeEach(() => {
jest.clearAllMocks();
});

it('reuses the same notification id for repeated validation errors', async () => {
let capturedQueryFn: (() => Promise<unknown>) | undefined;
let capturedQueryFn: (() => unknown) | undefined;
mockUseQuery.mockImplementation(({ queryFn }) => {
capturedQueryFn = queryFn;
return { data: [] };
if (typeof queryFn === 'function') {
capturedQueryFn = () => queryFn(fromPartial({}));
}
return fromPartial({ data: [] });
});

const invalidSource = {
Expand All @@ -344,9 +347,11 @@ describe('useSources validation notifications', () => {
serviceNameExpression: 42,
};

mockHdxServer.mockReturnValue({
json: jest.fn().mockResolvedValue([invalidSource]),
});
mockHdxServer.mockReturnValue(
fromPartial({
json: jest.fn().mockResolvedValue([invalidSource]),
}),
);

useSources();
expect(capturedQueryFn).toBeDefined();
Expand Down Expand Up @@ -411,11 +416,11 @@ function makeRawSqlConfig(
}

describe('useSingleSeriesNumberFormat', () => {
const mockUseQuery = useQuery as jest.Mock;
const mockUseQuery = jest.mocked(useQuery);

beforeEach(() => {
jest.clearAllMocks();
mockUseQuery.mockReturnValue({ data: TRACE_SOURCE });
mockUseQuery.mockReturnValue(fromPartial({ data: TRACE_SOURCE }));
});

it.each<{
Expand Down Expand Up @@ -519,14 +524,14 @@ describe('useSingleSeriesNumberFormat', () => {
});

describe('useChartNumberFormats', () => {
const mockUseQuery = useQuery as jest.Mock;
const mockUseQuery = jest.mocked(useQuery);

const META_A = { name: 'col_a', type: 'Float64' } as ColumnMetaType;
const META_B = { name: 'col_b', type: 'Float64' } as ColumnMetaType;

beforeEach(() => {
jest.clearAllMocks();
mockUseQuery.mockReturnValue({ data: TRACE_SOURCE });
mockUseQuery.mockReturnValue(fromPartial({ data: TRACE_SOURCE }));
});

// --- chartFormat resolution ---
Expand Down
20 changes: 15 additions & 5 deletions packages/app/src/components/ServiceMap/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import router from 'next/router';
import { SourceKind, TTraceSource } from '@hyperdx/common-utils/dist/types';
import { fromPartial } from '@total-typescript/shoehorn';

import {
buildServiceMapErrorWhere,
Expand Down Expand Up @@ -68,6 +69,15 @@ describe('navigateToTraceSearch', () => {
jest.clearAllMocks();
});

// router.push accepts a UrlObject too; navigateToTraceSearch always passes a string.
function getPushedUrl(): string {
const callArg = jest.mocked(router.push).mock.calls[0]?.[0];
if (typeof callArg !== 'string') {
throw new Error('Expected router.push to be called with a string URL');
}
return callArg;
}

it('should navigate to search page with correct query parameters', () => {
const dateRange: [Date, Date] = [
new Date('2024-01-15T10:00:00.000Z'),
Expand All @@ -82,7 +92,7 @@ describe('navigateToTraceSearch', () => {

expect(router.push).toHaveBeenCalledTimes(1);

const callArg = (router.push as jest.Mock).mock.calls[0][0];
const callArg = getPushedUrl();
expect(callArg).toContain('/search?');

// Parse query params
Expand All @@ -109,7 +119,7 @@ describe('navigateToTraceSearch', () => {
where: 'status_code = 500',
});

const callArg = (router.push as jest.Mock).mock.calls[0][0];
const callArg = getPushedUrl();
const url = new URL(callArg, 'http://localhost');
const params = url.searchParams;

Expand All @@ -132,7 +142,7 @@ describe('navigateToTraceSearch', () => {
where: complexWhere,
});

const callArg = (router.push as jest.Mock).mock.calls[0][0];
const callArg = getPushedUrl();
const url = new URL(callArg, 'http://localhost');
const params = url.searchParams;

Expand All @@ -153,7 +163,7 @@ describe('navigateToTraceSearch', () => {
where: whereWithSpecialChars,
});

const callArg = (router.push as jest.Mock).mock.calls[0][0];
const callArg = getPushedUrl();
const url = new URL(callArg, 'http://localhost');
const params = url.searchParams;

Expand Down Expand Up @@ -649,7 +659,7 @@ describe('getNodeSize', () => {
});

describe('deriveDisplayMetrics', () => {
const source = { durationPrecision: 9 } as unknown as TTraceSource;
const source = fromPartial<TTraceSource>({ durationPrecision: 9 });
const oneHour: [Date, Date] = [
new Date('2024-01-01T00:00:00.000Z'),
new Date('2024-01-01T01:00:00.000Z'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('TimelineMinimap', () => {
fireEvent.pointerUp(minimap, { clientX: 600, pointerId: 1 });

expect(controller.zoomToRange).toHaveBeenCalledTimes(1);
const [start, end] = (controller.zoomToRange as jest.Mock).mock.calls[0];
const [start, end] = jest.mocked(controller.zoomToRange).mock.calls[0];
expect(start).toBeCloseTo(0.2, 5);
expect(end).toBeCloseTo(0.6, 5);
});
Expand All @@ -158,9 +158,10 @@ describe('TimelineMinimap', () => {
fireEvent.pointerMove(minimap, { clientX: 475, pointerId: 1 });

expect(controller.panToOffset).toHaveBeenCalled();
const lastCall = (controller.panToOffset as jest.Mock).mock.calls.at(-1);
const lastCall = jest.mocked(controller.panToOffset).mock.calls.at(-1);
// moved +0.1 frac → offset 0.25 -> ~0.35
expect(lastCall[0]).toBeCloseTo(0.35, 5);
expect(lastCall).toBeDefined();
expect(lastCall?.[0]).toBeCloseTo(0.35, 5);
expect(controller.zoomToRange).not.toHaveBeenCalled();
});

Expand All @@ -178,9 +179,10 @@ describe('TimelineMinimap', () => {
fireEvent.pointerMove(minimap, { clientX: 700, pointerId: 1 });

expect(controller.zoomToRange).toHaveBeenCalled();
const lastCall = (controller.zoomToRange as jest.Mock).mock.calls.at(-1);
expect(lastCall[0]).toBeCloseTo(0.25, 5); // start unchanged
expect(lastCall[1]).toBeCloseTo(0.7, 5); // end pushed to 0.7
const lastCall = jest.mocked(controller.zoomToRange).mock.calls.at(-1);
expect(lastCall).toBeDefined();
expect(lastCall?.[0]).toBeCloseTo(0.25, 5); // start unchanged
expect(lastCall?.[1]).toBeCloseTo(0.7, 5); // end pushed to 0.7
});

it('double-click resets when zoomed', () => {
Expand Down
Loading
Loading