From 8de76b8d581fe7b5317efc5a6e8fdfb1c2bc0ed4 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Fri, 21 Mar 2025 22:30:27 -0600 Subject: [PATCH] update tests --- .../helpers/hasMappedMetrics.test.ts | 15 ++++++--------- .../helpers/normalizeMetric.test.ts | 3 +-- .../helpers/normalizeMetric.ts | 13 ++++++------- .../useMetricRunSQL/helpers.test.ts | 12 ------------ .../DashboardThreeDotMenu.tsx | 7 +++++-- 5 files changed, 18 insertions(+), 32 deletions(-) diff --git a/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/helpers/hasMappedMetrics.test.ts b/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/helpers/hasMappedMetrics.test.ts index c9fff3ad6..b58786b13 100644 --- a/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/helpers/hasMappedMetrics.test.ts +++ b/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/helpers/hasMappedMetrics.test.ts @@ -1,12 +1,9 @@ import { hasUnmappedMetrics, hasRemovedMetrics } from './hasMappedMetrics'; import { DashboardConfig } from '@/api/asset_interfaces/dashboard'; -import { BusterMetric } from '@/api/asset_interfaces/metric'; -import { BusterResizeableGridRow } from '@/components/ui/grid/interfaces'; -import { VerificationStatus } from '@/api/asset_interfaces/share'; import { createMockMetric } from '@/mocks/metric'; import { NUMBER_OF_COLUMNS } from '@/components/ui/grid/helpers'; -const createMockRow = (itemIds: string[]): BusterResizeableGridRow => ({ +const createMockRow = (itemIds: string[]): NonNullable[0] => ({ id: `row-${itemIds[0]}`, columnSizes: Array(itemIds.length).fill(NUMBER_OF_COLUMNS / itemIds.length), items: itemIds.map((id) => ({ id })) @@ -70,7 +67,7 @@ describe('hasRemovedMetrics', () => { '3': mockMetric3 }; - const configRows: BusterResizeableGridRow[] = [createMockRow(['1', '2']), createMockRow(['3'])]; + const configRows = [createMockRow(['1', '2']), createMockRow(['3'])]; expect(hasRemovedMetrics(metrics, configRows)).toBe(false); }); @@ -81,7 +78,7 @@ describe('hasRemovedMetrics', () => { '2': mockMetric2 }; - const configRows: BusterResizeableGridRow[] = [createMockRow(['1', '2', '3'])]; + const configRows = [createMockRow(['1', '2', '3'])]; expect(hasRemovedMetrics(metrics, configRows)).toBe(true); }); @@ -93,7 +90,7 @@ describe('hasRemovedMetrics', () => { '3': mockMetric3 }; - const configRows: BusterResizeableGridRow[] = [createMockRow(['1', '2'])]; + const configRows = [createMockRow(['1', '2'])]; expect(hasRemovedMetrics(metrics, configRows)).toBe(true); }); @@ -104,14 +101,14 @@ describe('hasRemovedMetrics', () => { '2': mockMetric2 }; - const configRows: BusterResizeableGridRow[] = [createMockRow(['3', '4'])]; + const configRows = [createMockRow(['3', '4'])]; expect(hasRemovedMetrics(metrics, configRows)).toBe(true); }); it('should return false when both metrics and grid rows are empty', () => { const metrics = {}; - const configRows: BusterResizeableGridRow[] = []; + const configRows: NonNullable = []; expect(hasRemovedMetrics(metrics, configRows)).toBe(false); }); diff --git a/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/helpers/normalizeMetric.test.ts b/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/helpers/normalizeMetric.test.ts index 1c461c6bd..b1412cb68 100644 --- a/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/helpers/normalizeMetric.test.ts +++ b/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/helpers/normalizeMetric.test.ts @@ -1,7 +1,6 @@ import { normalizeNewMetricsIntoGrid } from './normalizeMetric'; import { DashboardConfig } from '@/api/asset_interfaces/dashboard'; import { BusterMetric } from '@/api/asset_interfaces/metric'; -import { BusterResizeableGridRow } from '@/components/ui/grid/interfaces'; import { NUMBER_OF_COLUMNS, MAX_NUMBER_OF_ITEMS, @@ -12,7 +11,7 @@ import { createMockMetric } from '@/mocks/metric'; describe('normalizeNewMetricsIntoGrid', () => { const mockMetric = (id: string): BusterMetric => createMockMetric(id); - const createMockRow = (itemIds: string[]): BusterResizeableGridRow => ({ + const createMockRow = (itemIds: string[]): NonNullable[0] => ({ id: `row-${itemIds[0]}`, columnSizes: Array(itemIds.length).fill(NUMBER_OF_COLUMNS / itemIds.length), rowHeight: MIN_ROW_HEIGHT, diff --git a/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/helpers/normalizeMetric.ts b/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/helpers/normalizeMetric.ts index d5a5f2c93..b8f60fd2a 100644 --- a/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/helpers/normalizeMetric.ts +++ b/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/helpers/normalizeMetric.ts @@ -1,6 +1,5 @@ -import { DashboardConfig } from '@/api/asset_interfaces/dashboard'; -import { BusterMetric } from '@/api/asset_interfaces/metric'; -import { BusterResizeableGridRow } from '@/components/ui/grid/interfaces'; +import type { DashboardConfig } from '@/api/asset_interfaces/dashboard'; +import type { BusterMetric } from '@/api/asset_interfaces/metric'; import { v4 as uuidv4 } from 'uuid'; import { NUMBER_OF_COLUMNS, @@ -11,7 +10,7 @@ import { export const normalizeNewMetricsIntoGrid = ( metricsRecord: Record, grid: DashboardConfig['rows'] = [] -): BusterResizeableGridRow[] => { +): NonNullable => { const metrics = Object.values(metricsRecord); const newMetrics = getAddedMetrics(metrics, grid); const removedMetrics = getRemovedMetrics(metrics, grid); @@ -21,7 +20,7 @@ export const normalizeNewMetricsIntoGrid = ( let newGrid = grid; const createNewOverflowRows = (metrics: BusterMetric[]) => { - return metrics.reduce((acc, metric, index) => { + return metrics.reduce>((acc, metric, index) => { const rowIndex = Math.floor(index / 4); const selectedRow = acc[rowIndex]; if (!selectedRow) { @@ -45,7 +44,7 @@ export const normalizeNewMetricsIntoGrid = ( // First, remove any metrics that are no longer in the metricsRecord if (numberOfRemovedMetrics > 0) { newGrid = grid - .map((row): BusterResizeableGridRow | null => { + .map((row) => { const newItems = row.items.filter((item) => metrics.some((m) => m.id === item.id)); if (newItems.length === 0) return null; @@ -58,7 +57,7 @@ export const normalizeNewMetricsIntoGrid = ( columnSizes }; }) - .filter((row): row is BusterResizeableGridRow => row !== null); + .filter((row) => row !== null); } // Then, add new metrics diff --git a/web/src/controllers/MetricController/MetricViewResults/useMetricRunSQL/helpers.test.ts b/web/src/controllers/MetricController/MetricViewResults/useMetricRunSQL/helpers.test.ts index edac85506..d9d25d580 100644 --- a/web/src/controllers/MetricController/MetricViewResults/useMetricRunSQL/helpers.test.ts +++ b/web/src/controllers/MetricController/MetricViewResults/useMetricRunSQL/helpers.test.ts @@ -20,14 +20,6 @@ const createColumnMetaData = ( type: simple_type === 'text' ? 'text' : simple_type === 'number' ? 'float' : 'date' }); -// Mock the createDefaultChartConfig function -jest.mock('@/lib/messageAutoChartHandler', () => ({ - createDefaultChartConfig: jest.fn((props) => ({ - ...DEFAULT_CHART_CONFIG, - ...props.chart_config - })) -})); - describe('didColumnDataChange', () => { it('should return true when either input is undefined', () => { const columnData: ColumnMetaData[] = [createColumnMetaData('col1', 'text')]; @@ -71,10 +63,6 @@ describe('didColumnDataChange', () => { }); describe('simplifyChatConfigForSQLChange', () => { - beforeEach(() => { - (createDefaultChartConfig as jest.Mock).mockClear(); - }); - it('should handle empty metadata', () => { const chartConfig: Partial = { ...DEFAULT_CHART_CONFIG, diff --git a/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/DashboardContainerHeaderButtons/DashboardThreeDotMenu.tsx b/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/DashboardContainerHeaderButtons/DashboardThreeDotMenu.tsx index 052c486b2..60bee2864 100644 --- a/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/DashboardContainerHeaderButtons/DashboardThreeDotMenu.tsx +++ b/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/DashboardContainerHeaderButtons/DashboardThreeDotMenu.tsx @@ -122,12 +122,15 @@ const useCollectionSelectMenu = ({ dashboardId }: { dashboardId: string }) => { }, [collections]); const onSaveToCollection = useMemoizedFn(async (collectionIds: string[]) => { - await saveDashboardToCollection({ dashboardId, collectionIds }); + await saveDashboardToCollection({ dashboardIds: [dashboardId], collectionIds }); openInfoMessage('Dashboard saved to collections'); }); const onRemoveFromCollection = useMemoizedFn(async (collectionId: string) => { - await removeDashboardFromCollection({ dashboardId, collectionIds: [collectionId] }); + await removeDashboardFromCollection({ + dashboardIds: [dashboardId], + collectionIds: [collectionId] + }); openInfoMessage('Dashboard removed from collections'); });