From 455bc86b2659a2e05d72988e4bc50b565e816ce8 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Tue, 22 Jul 2025 13:30:03 -0600 Subject: [PATCH] fix broken unit tests --- apps/web/src/api/buster-electric/index.ts | 2 - .../lineSeriesBuilder.test.ts | 27 +++++++--- .../useSeriesOptions/pieSeriesBuilder.test.ts | 49 +++++-------------- .../charts/commonHelpers/labelHelpers.test.ts | 5 +- 4 files changed, 33 insertions(+), 50 deletions(-) delete mode 100644 apps/web/src/api/buster-electric/index.ts diff --git a/apps/web/src/api/buster-electric/index.ts b/apps/web/src/api/buster-electric/index.ts deleted file mode 100644 index d8571f775..000000000 --- a/apps/web/src/api/buster-electric/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './messages'; -export * from './chats'; diff --git a/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/lineSeriesBuilder.test.ts b/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/lineSeriesBuilder.test.ts index 3f2aa2902..2290ac1f0 100644 --- a/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/lineSeriesBuilder.test.ts +++ b/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/lineSeriesBuilder.test.ts @@ -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; // 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); diff --git a/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/pieSeriesBuilder.test.ts b/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/pieSeriesBuilder.test.ts index 55db62a8a..579bbaeda 100644 --- a/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/pieSeriesBuilder.test.ts +++ b/apps/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/pieSeriesBuilder.test.ts @@ -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', () => { diff --git a/apps/web/src/components/ui/charts/commonHelpers/labelHelpers.test.ts b/apps/web/src/components/ui/charts/commonHelpers/labelHelpers.test.ts index b79b98c42..b55456432 100644 --- a/apps/web/src/components/ui/charts/commonHelpers/labelHelpers.test.ts +++ b/apps/web/src/components/ui/charts/commonHelpers/labelHelpers.test.ts @@ -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}`) }));