mirror of https://github.com/buster-so/buster.git
update tests
This commit is contained in:
parent
3d0a403ea9
commit
8de76b8d58
|
@ -1,12 +1,9 @@
|
||||||
import { hasUnmappedMetrics, hasRemovedMetrics } from './hasMappedMetrics';
|
import { hasUnmappedMetrics, hasRemovedMetrics } from './hasMappedMetrics';
|
||||||
import { DashboardConfig } from '@/api/asset_interfaces/dashboard';
|
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 { createMockMetric } from '@/mocks/metric';
|
||||||
import { NUMBER_OF_COLUMNS } from '@/components/ui/grid/helpers';
|
import { NUMBER_OF_COLUMNS } from '@/components/ui/grid/helpers';
|
||||||
|
|
||||||
const createMockRow = (itemIds: string[]): BusterResizeableGridRow => ({
|
const createMockRow = (itemIds: string[]): NonNullable<DashboardConfig['rows']>[0] => ({
|
||||||
id: `row-${itemIds[0]}`,
|
id: `row-${itemIds[0]}`,
|
||||||
columnSizes: Array(itemIds.length).fill(NUMBER_OF_COLUMNS / itemIds.length),
|
columnSizes: Array(itemIds.length).fill(NUMBER_OF_COLUMNS / itemIds.length),
|
||||||
items: itemIds.map((id) => ({ id }))
|
items: itemIds.map((id) => ({ id }))
|
||||||
|
@ -70,7 +67,7 @@ describe('hasRemovedMetrics', () => {
|
||||||
'3': mockMetric3
|
'3': mockMetric3
|
||||||
};
|
};
|
||||||
|
|
||||||
const configRows: BusterResizeableGridRow[] = [createMockRow(['1', '2']), createMockRow(['3'])];
|
const configRows = [createMockRow(['1', '2']), createMockRow(['3'])];
|
||||||
|
|
||||||
expect(hasRemovedMetrics(metrics, configRows)).toBe(false);
|
expect(hasRemovedMetrics(metrics, configRows)).toBe(false);
|
||||||
});
|
});
|
||||||
|
@ -81,7 +78,7 @@ describe('hasRemovedMetrics', () => {
|
||||||
'2': mockMetric2
|
'2': mockMetric2
|
||||||
};
|
};
|
||||||
|
|
||||||
const configRows: BusterResizeableGridRow[] = [createMockRow(['1', '2', '3'])];
|
const configRows = [createMockRow(['1', '2', '3'])];
|
||||||
|
|
||||||
expect(hasRemovedMetrics(metrics, configRows)).toBe(true);
|
expect(hasRemovedMetrics(metrics, configRows)).toBe(true);
|
||||||
});
|
});
|
||||||
|
@ -93,7 +90,7 @@ describe('hasRemovedMetrics', () => {
|
||||||
'3': mockMetric3
|
'3': mockMetric3
|
||||||
};
|
};
|
||||||
|
|
||||||
const configRows: BusterResizeableGridRow[] = [createMockRow(['1', '2'])];
|
const configRows = [createMockRow(['1', '2'])];
|
||||||
|
|
||||||
expect(hasRemovedMetrics(metrics, configRows)).toBe(true);
|
expect(hasRemovedMetrics(metrics, configRows)).toBe(true);
|
||||||
});
|
});
|
||||||
|
@ -104,14 +101,14 @@ describe('hasRemovedMetrics', () => {
|
||||||
'2': mockMetric2
|
'2': mockMetric2
|
||||||
};
|
};
|
||||||
|
|
||||||
const configRows: BusterResizeableGridRow[] = [createMockRow(['3', '4'])];
|
const configRows = [createMockRow(['3', '4'])];
|
||||||
|
|
||||||
expect(hasRemovedMetrics(metrics, configRows)).toBe(true);
|
expect(hasRemovedMetrics(metrics, configRows)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false when both metrics and grid rows are empty', () => {
|
it('should return false when both metrics and grid rows are empty', () => {
|
||||||
const metrics = {};
|
const metrics = {};
|
||||||
const configRows: BusterResizeableGridRow[] = [];
|
const configRows: NonNullable<DashboardConfig['rows']> = [];
|
||||||
|
|
||||||
expect(hasRemovedMetrics(metrics, configRows)).toBe(false);
|
expect(hasRemovedMetrics(metrics, configRows)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { normalizeNewMetricsIntoGrid } from './normalizeMetric';
|
import { normalizeNewMetricsIntoGrid } from './normalizeMetric';
|
||||||
import { DashboardConfig } from '@/api/asset_interfaces/dashboard';
|
import { DashboardConfig } from '@/api/asset_interfaces/dashboard';
|
||||||
import { BusterMetric } from '@/api/asset_interfaces/metric';
|
import { BusterMetric } from '@/api/asset_interfaces/metric';
|
||||||
import { BusterResizeableGridRow } from '@/components/ui/grid/interfaces';
|
|
||||||
import {
|
import {
|
||||||
NUMBER_OF_COLUMNS,
|
NUMBER_OF_COLUMNS,
|
||||||
MAX_NUMBER_OF_ITEMS,
|
MAX_NUMBER_OF_ITEMS,
|
||||||
|
@ -12,7 +11,7 @@ import { createMockMetric } from '@/mocks/metric';
|
||||||
describe('normalizeNewMetricsIntoGrid', () => {
|
describe('normalizeNewMetricsIntoGrid', () => {
|
||||||
const mockMetric = (id: string): BusterMetric => createMockMetric(id);
|
const mockMetric = (id: string): BusterMetric => createMockMetric(id);
|
||||||
|
|
||||||
const createMockRow = (itemIds: string[]): BusterResizeableGridRow => ({
|
const createMockRow = (itemIds: string[]): NonNullable<DashboardConfig['rows']>[0] => ({
|
||||||
id: `row-${itemIds[0]}`,
|
id: `row-${itemIds[0]}`,
|
||||||
columnSizes: Array(itemIds.length).fill(NUMBER_OF_COLUMNS / itemIds.length),
|
columnSizes: Array(itemIds.length).fill(NUMBER_OF_COLUMNS / itemIds.length),
|
||||||
rowHeight: MIN_ROW_HEIGHT,
|
rowHeight: MIN_ROW_HEIGHT,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { DashboardConfig } from '@/api/asset_interfaces/dashboard';
|
import type { DashboardConfig } from '@/api/asset_interfaces/dashboard';
|
||||||
import { BusterMetric } from '@/api/asset_interfaces/metric';
|
import type { BusterMetric } from '@/api/asset_interfaces/metric';
|
||||||
import { BusterResizeableGridRow } from '@/components/ui/grid/interfaces';
|
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import {
|
import {
|
||||||
NUMBER_OF_COLUMNS,
|
NUMBER_OF_COLUMNS,
|
||||||
|
@ -11,7 +10,7 @@ import {
|
||||||
export const normalizeNewMetricsIntoGrid = (
|
export const normalizeNewMetricsIntoGrid = (
|
||||||
metricsRecord: Record<string, BusterMetric>,
|
metricsRecord: Record<string, BusterMetric>,
|
||||||
grid: DashboardConfig['rows'] = []
|
grid: DashboardConfig['rows'] = []
|
||||||
): BusterResizeableGridRow[] => {
|
): NonNullable<DashboardConfig['rows']> => {
|
||||||
const metrics = Object.values(metricsRecord);
|
const metrics = Object.values(metricsRecord);
|
||||||
const newMetrics = getAddedMetrics(metrics, grid);
|
const newMetrics = getAddedMetrics(metrics, grid);
|
||||||
const removedMetrics = getRemovedMetrics(metrics, grid);
|
const removedMetrics = getRemovedMetrics(metrics, grid);
|
||||||
|
@ -21,7 +20,7 @@ export const normalizeNewMetricsIntoGrid = (
|
||||||
let newGrid = grid;
|
let newGrid = grid;
|
||||||
|
|
||||||
const createNewOverflowRows = (metrics: BusterMetric[]) => {
|
const createNewOverflowRows = (metrics: BusterMetric[]) => {
|
||||||
return metrics.reduce<BusterResizeableGridRow[]>((acc, metric, index) => {
|
return metrics.reduce<NonNullable<DashboardConfig['rows']>>((acc, metric, index) => {
|
||||||
const rowIndex = Math.floor(index / 4);
|
const rowIndex = Math.floor(index / 4);
|
||||||
const selectedRow = acc[rowIndex];
|
const selectedRow = acc[rowIndex];
|
||||||
if (!selectedRow) {
|
if (!selectedRow) {
|
||||||
|
@ -45,7 +44,7 @@ export const normalizeNewMetricsIntoGrid = (
|
||||||
// First, remove any metrics that are no longer in the metricsRecord
|
// First, remove any metrics that are no longer in the metricsRecord
|
||||||
if (numberOfRemovedMetrics > 0) {
|
if (numberOfRemovedMetrics > 0) {
|
||||||
newGrid = grid
|
newGrid = grid
|
||||||
.map((row): BusterResizeableGridRow | null => {
|
.map((row) => {
|
||||||
const newItems = row.items.filter((item) => metrics.some((m) => m.id === item.id));
|
const newItems = row.items.filter((item) => metrics.some((m) => m.id === item.id));
|
||||||
if (newItems.length === 0) return null;
|
if (newItems.length === 0) return null;
|
||||||
|
|
||||||
|
@ -58,7 +57,7 @@ export const normalizeNewMetricsIntoGrid = (
|
||||||
columnSizes
|
columnSizes
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.filter((row): row is BusterResizeableGridRow => row !== null);
|
.filter((row) => row !== null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then, add new metrics
|
// Then, add new metrics
|
||||||
|
|
|
@ -20,14 +20,6 @@ const createColumnMetaData = (
|
||||||
type: simple_type === 'text' ? 'text' : simple_type === 'number' ? 'float' : 'date'
|
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', () => {
|
describe('didColumnDataChange', () => {
|
||||||
it('should return true when either input is undefined', () => {
|
it('should return true when either input is undefined', () => {
|
||||||
const columnData: ColumnMetaData[] = [createColumnMetaData('col1', 'text')];
|
const columnData: ColumnMetaData[] = [createColumnMetaData('col1', 'text')];
|
||||||
|
@ -71,10 +63,6 @@ describe('didColumnDataChange', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('simplifyChatConfigForSQLChange', () => {
|
describe('simplifyChatConfigForSQLChange', () => {
|
||||||
beforeEach(() => {
|
|
||||||
(createDefaultChartConfig as jest.Mock).mockClear();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle empty metadata', () => {
|
it('should handle empty metadata', () => {
|
||||||
const chartConfig: Partial<IBusterMetricChartConfig> = {
|
const chartConfig: Partial<IBusterMetricChartConfig> = {
|
||||||
...DEFAULT_CHART_CONFIG,
|
...DEFAULT_CHART_CONFIG,
|
||||||
|
|
|
@ -122,12 +122,15 @@ const useCollectionSelectMenu = ({ dashboardId }: { dashboardId: string }) => {
|
||||||
}, [collections]);
|
}, [collections]);
|
||||||
|
|
||||||
const onSaveToCollection = useMemoizedFn(async (collectionIds: string[]) => {
|
const onSaveToCollection = useMemoizedFn(async (collectionIds: string[]) => {
|
||||||
await saveDashboardToCollection({ dashboardId, collectionIds });
|
await saveDashboardToCollection({ dashboardIds: [dashboardId], collectionIds });
|
||||||
openInfoMessage('Dashboard saved to collections');
|
openInfoMessage('Dashboard saved to collections');
|
||||||
});
|
});
|
||||||
|
|
||||||
const onRemoveFromCollection = useMemoizedFn(async (collectionId: string) => {
|
const onRemoveFromCollection = useMemoizedFn(async (collectionId: string) => {
|
||||||
await removeDashboardFromCollection({ dashboardId, collectionIds: [collectionId] });
|
await removeDashboardFromCollection({
|
||||||
|
dashboardIds: [dashboardId],
|
||||||
|
collectionIds: [collectionId]
|
||||||
|
});
|
||||||
openInfoMessage('Dashboard removed from collections');
|
openInfoMessage('Dashboard removed from collections');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue