Skip to content

Commit 0356599

Browse files
fix(app): type the useChartScales test fixtures instead of asserting
Main ratcheted the app warning ceiling from 740 to 663, and the four assertions this test file used to sidestep typing put the branch over it. Typed the LineData fixture properly, asserted the whole y-domain rather than destructuring a cast, and narrowed the annotation elements with isValidElement so a rename of `x` would be a type error rather than a silently passing test.
1 parent ab54781 commit 0356599

2 files changed

Lines changed: 29 additions & 21 deletions

File tree

‎packages/app/src/HDXMultiSeriesTimeChart/__tests__/useChartScales.test.ts‎

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { isValidElement } from 'react';
12
import { DisplayType } from '@hyperdx/common-utils/dist/types';
23
import { renderHook } from '@testing-library/react';
34

5+
import { type LineData } from '@/ChartUtils';
46
import { ChartAnnotation } from '@/components/charts/chartAnnotations';
57
import { useChartScales } from '@/HDXMultiSeriesTimeChart/useChartScales';
68

@@ -10,10 +12,16 @@ import { useChartScales } from '@/HDXMultiSeriesTimeChart/useChartScales';
1012
* used to be buried in MemoChart — fit-to-data, legend selection, zero-anchored
1113
* bars, the half-bucket bar padding — is what these cases pin.
1214
*/
13-
const lineData = [
14-
{ dataKey: 'a', displayName: 'A' },
15-
{ dataKey: 'b', displayName: 'B' },
16-
] as any;
15+
const series = (dataKey: string, displayName: string): LineData => ({
16+
dataKey,
17+
displayName,
18+
currentPeriodKey: dataKey,
19+
previousPeriodKey: `${dataKey}-prev`,
20+
valueColumnName: dataKey,
21+
color: '#000000',
22+
});
23+
24+
const lineData: LineData[] = [series('a', 'A'), series('b', 'B')];
1725

1826
const baseArgs = {
1927
annotations: undefined as ChartAnnotation[] | undefined,
@@ -45,22 +53,19 @@ describe('useChartScales y-domain', () => {
4553

4654
it('fits the lower bound to the data minimum, less padding', () => {
4755
// min 10, max 40 -> 5% padding is 1.5.
48-
const [lower, upper] = scales({ fitYAxisToData: true }).yAxisDomain as [
49-
number,
50-
number,
51-
];
52-
expect(lower).toBe(8.5);
53-
expect(upper).toBe(41.5);
56+
expect(scales({ fitYAxisToData: true }).yAxisDomain).toEqual([8.5, 41.5]);
5457
});
5558

5659
it('does not let the padding drag the axis below zero', () => {
57-
// A chart of durations whose axis starts at -4ms reads as broken, so the
58-
// clamp only lifts when the data itself never goes negative.
59-
const [lower] = scales({
60-
fitYAxisToData: true,
61-
graphResults: [{ a: 1, b: 100 }],
62-
}).yAxisDomain as [number, number];
63-
expect(lower).toBe(0);
60+
// min 1, max 100 -> padding 4.95 would put the floor at -3.95, and a chart of
61+
// durations whose axis starts below zero reads as broken. The clamp only
62+
// lifts when the data itself goes negative.
63+
expect(
64+
scales({
65+
fitYAxisToData: true,
66+
graphResults: [{ a: 1, b: 100 }],
67+
}).yAxisDomain,
68+
).toEqual([0, 104.95]);
6469
});
6570

6671
it('follows the data minimum when fitting and the data is negative', () => {
@@ -136,8 +141,10 @@ describe('useChartScales annotations', () => {
136141
// non-null result passes even when the time is read from the wrong field and
137142
// every marker lands on NaN.
138143
const markerX = (annotations: ChartAnnotation[]) =>
139-
(scales({ annotations }).annotationElements ?? []).map(
140-
el => (el.props as { x: number }).x,
144+
(scales({ annotations }).annotationElements ?? []).map(el =>
145+
// A guard rather than a cast: the elements come back as ReactElement with
146+
// unknown props, and asserting the shape would hide a rename of `x`.
147+
isValidElement<{ x: number }>(el) ? el.props.x : undefined,
141148
);
142149

143150
it('renders nothing when there are none', () => {

‎packages/app/src/components/DBTimeChart/__tests__/searchUrl.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ jest.mock('@/ChartUtils', () => ({
2626
/** Args the function handed to buildEventsSearchUrl on its first call. */
2727
const delegatedArgs = () => mockBuildEventsSearchUrl.mock.calls[0][0];
2828

29-
const source = {
29+
const source: TSource = {
3030
id: 'src-1',
3131
kind: SourceKind.Log,
3232
name: 'logs',
3333
connection: 'conn-1',
3434
from: { databaseName: 'default', tableName: 'otel_logs' },
3535
timestampValueExpression: 'Timestamp',
36-
} as unknown as TSource;
36+
defaultTableSelectExpression: 'Body',
37+
};
3738

3839
const clicked = new Date('2026-01-01T00:00:00Z');
3940

0 commit comments

Comments
 (0)