fix broken tests

This commit is contained in:
Nate Kelley 2025-05-09 10:51:26 -06:00
parent f612f967a9
commit 32a3d6f21e
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
4 changed files with 203 additions and 10 deletions

View File

@ -21,9 +21,10 @@ test('Can create a collection', async ({ page }) => {
await page.getByRole('button').filter({ hasText: /^$/ }).nth(2).click();
await page.getByRole('menuitem', { name: 'Delete collection' }).click();
await page.getByRole('button', { name: 'Submit' }).click();
await page.waitForTimeout(50);
await page.waitForTimeout(1000);
await page.waitForLoadState('networkidle');
await page.waitForLoadState('domcontentloaded');
await page.waitForLoadState('load');
expect(page.url()).toBe('http://localhost:3000/app/collections');
});

View File

@ -152,16 +152,16 @@ test('Can edit name and description of a dashboard', async ({ page }) => {
await page.waitForLoadState('networkidle');
await page.getByTestId('segmented-trigger-file').click();
await page.getByTestId('segmented-trigger-file').click();
await page.waitForTimeout(2000); // Wait up to 2 seconds for the text to appear
await expect(page.getByText('Important Metrics SWAG')).toBeVisible({ timeout: 20000 }); // Wait up to 20 seconds for visibility
await expect(page.getByRole('code').getByText('Important Metrics SWAG')).toBeVisible({
timeout: 5000
});
await expect(page.locator('.current-line').first()).toBeVisible();
await page
.getByRole('textbox', { name: 'Editor content' })
.fill(
"name: Important Metrics\ndescription: ''\nrows:\n- items:\n - id: 72e445a5-fb08-5b76-8c77-1642adf0cb72\n - id: 45848c7f-0d28-52a0-914e-f3fc1b7d4180\n - id: 117a2fc5-e3e8-5bb0-a29b-bcfa3da3adc0\n - id: b19d2606-6061-5d22-8628-78a4878310d4\n rowHeight: 320\n columnSizes:\n"
);
await page.getByRole('button', { name: 'Save' }).click();
await page.getByTestId('segmented-trigger-dashboard').click();
await page.getByRole('textbox', { name: 'New dashboard' }).click();
await page.getByRole('textbox', { name: 'New dashboard' }).fill('Important Metrics');
await page.getByRole('button', { name: 'Save' }).click();
await expect(page.getByRole('textbox', { name: 'New dashboard' })).toHaveValue(
'Important Metrics'
);
});

View File

@ -0,0 +1,112 @@
import { canSupportTrendlineRecord } from './canSupportTrendline';
import { isNumericColumnType } from '@/lib/messages';
import { DEFAULT_COLUMN_LABEL_FORMAT } from '@/api/asset_interfaces/metric';
import type { BusterChartProps, Trendline } from '@/api/asset_interfaces/metric/charts';
// Mock the isNumericColumnType function
jest.mock('@/lib/messages', () => ({
isNumericColumnType: jest.fn()
}));
const mockedIsNumericColumnType = isNumericColumnType as jest.MockedFunction<
typeof isNumericColumnType
>;
describe('canSupportTrendlineRecord', () => {
const trendlineTypes: Trendline['type'][] = [
'linear_regression',
'logarithmic_regression',
'exponential_regression',
'polynomial_regression',
'min',
'max',
'median',
'average'
];
const columnId = 'test-column';
const mockColumnLabelFormats: NonNullable<BusterChartProps['columnLabelFormats']> = {
[columnId]: {
columnType: 'number',
style: 'number'
}
};
beforeEach(() => {
jest.clearAllMocks();
});
test.each(trendlineTypes)(
'returns true when %s trendline has a numeric column type',
(trendlineType) => {
// Arrange
mockedIsNumericColumnType.mockReturnValue(true);
const trendline: Trendline = {
type: trendlineType,
columnId,
show: true,
showTrendlineLabel: true,
trendlineLabel: 'Test Label'
};
// Act
const result = canSupportTrendlineRecord[trendlineType](mockColumnLabelFormats, trendline);
// Assert
expect(result).toBe(true);
expect(mockedIsNumericColumnType).toHaveBeenCalledWith('number');
}
);
test.each(trendlineTypes)(
'returns false when %s trendline has a non-numeric column type',
(trendlineType) => {
// Arrange
mockedIsNumericColumnType.mockReturnValue(false);
const trendline: Trendline = {
type: trendlineType,
columnId,
show: true,
showTrendlineLabel: true,
trendlineLabel: 'Test Label'
};
// Act
const result = canSupportTrendlineRecord[trendlineType](mockColumnLabelFormats, trendline);
// Assert
expect(result).toBe(false);
expect(mockedIsNumericColumnType).toHaveBeenCalledWith('number');
}
);
test.each(trendlineTypes)(
'uses DEFAULT_COLUMN_LABEL_FORMAT when column format not provided for %s',
(trendlineType) => {
// Arrange
mockedIsNumericColumnType.mockReturnValue(true);
const trendline: Trendline = {
type: trendlineType,
columnId: 'non-existent',
show: true,
showTrendlineLabel: true,
trendlineLabel: 'Test Label'
};
// Act
const result = canSupportTrendlineRecord[trendlineType](mockColumnLabelFormats, trendline);
// Assert
expect(result).toBe(true);
expect(mockedIsNumericColumnType).toHaveBeenCalledWith(
DEFAULT_COLUMN_LABEL_FORMAT.columnType
);
}
);
test('confirms all trendline types are tested', () => {
// This test ensures we've covered all trendline types in our tests
const allTrendlineTypes = Object.keys(canSupportTrendlineRecord) as Trendline['type'][];
expect(allTrendlineTypes.sort()).toEqual(trendlineTypes.sort());
});
});

View File

@ -0,0 +1,80 @@
import {
simplifyColumnType,
isNumericColumnType,
isNumericColumnStyle,
isDateColumnType,
NUMBER_TYPES,
TEXT_TYPES,
DATE_TYPES
} from './messages';
import type { SimplifiedColumnType } from '@/api/asset_interfaces/metric/';
import type { ColumnLabelFormat } from '@/api/asset_interfaces/metric/charts';
describe('simplifyColumnType', () => {
test('should return "number" for numeric types', () => {
NUMBER_TYPES.forEach((type) => {
expect(simplifyColumnType(type)).toBe('number');
});
expect(simplifyColumnType('number')).toBe('number');
});
test('should return "text" for text types', () => {
TEXT_TYPES.forEach((type) => {
expect(simplifyColumnType(type)).toBe('text');
});
expect(simplifyColumnType('text')).toBe('text');
});
test('should return "date" for date types', () => {
DATE_TYPES.forEach((type) => {
expect(simplifyColumnType(type)).toBe('date');
});
expect(simplifyColumnType('date')).toBe('date');
});
test('should return "text" for unknown types', () => {
expect(simplifyColumnType('unknown')).toBe('text');
expect(simplifyColumnType('boolean')).toBe('text');
expect(simplifyColumnType('')).toBe('text');
});
});
describe('isNumericColumnType', () => {
test('should return true for "number" type', () => {
expect(isNumericColumnType('number')).toBe(true);
});
test('should return false for non-number types', () => {
expect(isNumericColumnType('text')).toBe(false);
expect(isNumericColumnType('date')).toBe(false);
});
});
describe('isNumericColumnStyle', () => {
test('should return true for numeric styles', () => {
expect(isNumericColumnStyle('number')).toBe(true);
expect(isNumericColumnStyle('percent')).toBe(true);
expect(isNumericColumnStyle('currency')).toBe(true);
});
test('should return false for non-numeric styles', () => {
expect(isNumericColumnStyle('string')).toBe(false);
expect(isNumericColumnStyle('date')).toBe(false);
expect(isNumericColumnStyle(undefined)).toBe(false);
});
});
describe('isDateColumnType', () => {
test('should return true for "date" type', () => {
expect(isDateColumnType('date')).toBe(true);
});
test('should return false for non-date types', () => {
expect(isDateColumnType('number')).toBe(false);
expect(isDateColumnType('text')).toBe(false);
});
test('should return false for undefined', () => {
expect(isDateColumnType(undefined)).toBe(false);
});
});