fix(types): add TypeScript types to test files and FilterDefinitionOption

- Add type for setup function parameter in AdhocMetricOption.test.tsx
- Add type for setup function parameter in MetricDefinitionValue.test.tsx
- Add OptionType interface to FilterDefinitionOption.tsx

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Evan Rusackas
2025-12-20 00:32:03 -08:00
parent de9dc4fa32
commit 2b2e3bbdff
3 changed files with 29 additions and 17 deletions

View File

@@ -57,7 +57,7 @@ const defaultProps = {
index: 0,
};
function setup(overrides) {
function setup(overrides: Partial<typeof defaultProps> = {}) {
const props = {
...defaultProps,
...overrides,
@@ -66,12 +66,12 @@ function setup(overrides) {
}
test('renders an overlay trigger wrapper for the label', () => {
setup();
setup({});
expect(screen.getByText('SUM(value)')).toBeInTheDocument();
});
test('overwrites the adhocMetric in state with onLabelChange', async () => {
setup();
setup({});
userEvent.click(screen.getByText('SUM(value)'));
userEvent.click(screen.getByTestId(/AdhocMetricEditTitle#trigger/i));
const labelInput = await screen.findByTestId(/AdhocMetricEditTitle#input/i);
@@ -86,7 +86,7 @@ test('overwrites the adhocMetric in state with onLabelChange', async () => {
});
test('returns to default labels when the custom label is cleared', async () => {
setup();
setup({});
userEvent.click(screen.getByText('SUM(value)'));
userEvent.click(screen.getByTestId(/AdhocMetricEditTitle#trigger/i));
const labelInput = await screen.findByTestId(/AdhocMetricEditTitle#input/i);

View File

@@ -22,6 +22,14 @@ import columnType from './columnType';
import adhocMetricType from './adhocMetricType';
import { StyledColumnOption } from '../../optionRenderers';
interface OptionType {
saved_metric_name?: string;
column_name?: string;
label?: string;
type?: string;
[key: string]: unknown;
}
const propTypes = {
option: PropTypes.oneOfType([
columnType,
@@ -30,7 +38,7 @@ const propTypes = {
]).isRequired,
};
export default function FilterDefinitionOption({ option }) {
export default function FilterDefinitionOption({ option }: { option: OptionType }) {
if (option.saved_metric_name) {
return (
<StyledColumnOption

View File

@@ -26,17 +26,21 @@ const sumValueAdhocMetric = new AdhocMetric({
aggregate: AGGREGATES.SUM,
});
const setup = propOverrides => {
const defaultProps = {
onMetricEdit: jest.fn(),
option: sumValueAdhocMetric,
index: 1,
columns: [],
savedMetrics: [],
savedMetricsOptions: [],
datasource: {},
onMoveLabel: jest.fn(),
onDropLabel: jest.fn(),
};
const setup = (propOverrides: Partial<typeof defaultProps> = {}) => {
const props = {
onMetricEdit: jest.fn(),
option: sumValueAdhocMetric,
index: 1,
columns: [],
savedMetrics: [],
savedMetricsOptions: [],
datasource: {},
onMoveLabel: jest.fn(),
onDropLabel: jest.fn(),
...defaultProps,
...propOverrides,
};
return render(<MetricDefinitionValue {...props} />, { useDnd: true });
@@ -44,12 +48,12 @@ const setup = propOverrides => {
test('renders a MetricOption given a saved metric', () => {
setup({
option: { metric_name: 'a_saved_metric', expression: 'COUNT(*)' },
option: { metric_name: 'a_saved_metric', expression: 'COUNT(*)' } as typeof defaultProps['option'],
});
expect(screen.getByText('a_saved_metric')).toBeInTheDocument();
});
test('renders an AdhocMetricOption given an adhoc metric', () => {
setup();
setup({});
expect(screen.getByText('SUM(value)')).toBeInTheDocument();
});