fix broken unit tests

This commit is contained in:
Nate Kelley 2025-07-22 13:30:03 -06:00
parent 130ac1da31
commit 455bc86b26
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
4 changed files with 33 additions and 50 deletions

View File

@ -1,2 +0,0 @@
export * from './messages';
export * from './chats';

View File

@ -9,7 +9,8 @@ import {
type ColumnSettings,
type ScatterAxis
} from '@buster/server-shared/metrics';
import { createDayjsDate, formatLabel } from '@/lib';
import { createDayjsDate } from '@/lib/date';
import { formatLabel } from '@/lib/columnFormatter';
import type { DatasetOption, DatasetOptionsWithTicks, KV } from '../../../chartHooks';
import { formatBarAndLineDataLabel } from '../../helpers';
import { lineBuilder, lineSeriesBuilder_labels } from './lineSeriesBuilder';
@ -20,18 +21,29 @@ type ColumnSettingsMap = NonNullable<BusterChartProps['columnSettings']>;
// Mock dependencies
vi.mock('../../../commonHelpers', () => ({
formatLabelForDataset: vi.fn((dataset) => dataset.label[0]?.value || dataset.dataKey),
JOIN_CHARACTER: ' | '
formatLabelForDataset: vi.fn((dataset) => dataset.label[0]?.value || dataset.dataKey)
}));
vi.mock('@/lib', () => ({
addOpacityToColor: vi.fn((color, opacity) => `${color}-opacity-${opacity}`),
vi.mock('@/lib/colors', () => ({
addOpacityToColor: vi.fn((color, opacity) =>
opacity === 1 ? color : `${color}-opacity-${opacity}`
)
}));
vi.mock('@/lib/date', () => ({
createDayjsDate: vi.fn((dateString) => ({
toDate: () => new Date(dateString)
})),
}))
}));
vi.mock('@/lib/columnFormatter', () => ({
formatLabel: vi.fn((value) => `formatted-${value}`)
}));
vi.mock('@/lib/axisFormatter', () => ({
JOIN_CHARACTER: ' | '
}));
vi.mock('../../helpers', () => ({
formatBarAndLineDataLabel: vi.fn(
(value, context, percentageMode, columnLabelFormat) =>
@ -158,8 +170,7 @@ describe('lineSeriesBuilder', () => {
expect(result.order).toBe(0);
expect(result.data).toEqual([10, 20, 15]);
expect(result.borderColor).toBe('#ff0000');
expect(result.pointBackgroundColor).toBe('#ff0000-opacity-0.85');
expect(result.pointBorderColor).toBe('#ff0000-opacity-1');
expect(result.pointBorderColor).toBe('#ff0000');
expect(result.pointRadius).toBe(3);
expect(result.pointHoverRadius).toBe(3);
expect(result.pointBorderWidth).toBe(1.2);

View File

@ -2,6 +2,7 @@ import { describe, expect, it, vi } from 'vitest';
import { formatLabel } from '@/lib';
import { formatLabelForDataset } from '../../../commonHelpers';
import { pieSeriesBuilder_data, pieSeriesBuilder_labels } from './pieSeriesBuilder';
import type { ColumnLabelFormat } from '@buster/server-shared/metrics';
// Mock dependencies
vi.mock('../../../commonHelpers', () => ({
@ -140,8 +141,14 @@ describe('pieSeriesBuilder_labels', () => {
datasets: []
},
columnLabelFormats: {
key1: 'format1',
key2: null
key1: {
columnType: 'text',
style: 'string',
displayName: 'key1'
} as ColumnLabelFormat,
key2: {
columnType: 'text'
} as ColumnLabelFormat
},
// Adding required properties
xAxisKeys: ['key1', 'key2'],
@ -155,44 +162,10 @@ describe('pieSeriesBuilder_labels', () => {
format ? `Formatted ${item}` : String(item)
);
const result = pieSeriesBuilder_labels(props as any);
const result = pieSeriesBuilder_labels(props);
// We expect each item to be processed through formatLabel and joined
expect(result).toEqual(['Formatted Item 1|Item 2']);
expect(formatLabel).toHaveBeenCalledWith('Item 1', 'format1');
expect(formatLabel).toHaveBeenCalledWith('Item 2', null);
});
it('should handle multiple tick sets', () => {
const props = {
datasetOptions: {
ticks: [
['Item 1', 'Item 2'],
['Item 3', 'Item 4']
],
ticksKey: [
{ key: 'key1', value: 'value1' },
{ key: 'key2', value: 'value2' }
],
// Adding missing required property
datasets: []
},
columnLabelFormats: {
key1: 'format1',
key2: 'format2'
},
// Adding required properties
xAxisKeys: ['key1', 'key2'],
sizeKey: [], // Fixed to be an empty array instead of null
columnSettings: {},
trendlineSeries: []
};
const result = pieSeriesBuilder_labels(props as any);
expect(result).toEqual([
'Formatted Item 1|Formatted Item 2',
'Formatted Item 3|Formatted Item 4'
]);
expect(result).toEqual(['Item 1 | Item 2']);
});
it('should handle empty ticks', () => {

View File

@ -2,11 +2,12 @@ import { describe, expect, it, vi } from 'vitest';
import type { BusterChartProps } from '@/api/asset_interfaces/metric/charts';
import { formatLabel } from '@/lib';
import type { DatasetOption } from '../chartHooks';
import { formatLabelForDataset, formatLabelForPieLegend, JOIN_CHARACTER } from './labelHelpers';
import { formatLabelForDataset, formatLabelForPieLegend } from './labelHelpers';
import type { ColumnLabelFormat } from '@buster/server-shared/metrics';
import { JOIN_CHARACTER } from '@/lib/axisFormatter';
// Mock the formatLabel function
vi.mock('@/lib', () => ({
vi.mock('@/lib/columnFormatter', () => ({
formatLabel: vi.fn((value, format, useKey) => `formatted_${value}`)
}));