Chore: clean up console warning from SQL Group By tests (#46733)

This commit is contained in:
Kevin Yu 2022-03-21 12:20:48 -07:00 committed by GitHub
parent 499445a5f9
commit 7480ba0226
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 14 deletions

View File

@ -1,5 +1,6 @@
import React from 'react'; import React from 'react';
import { act, render, screen, waitFor } from '@testing-library/react'; import { render, screen, waitFor } from '@testing-library/react';
import selectEvent from 'react-select-event';
import { CloudWatchMetricsQuery, MetricEditorMode, MetricQueryType, SQLExpression } from '../../types'; import { CloudWatchMetricsQuery, MetricEditorMode, MetricQueryType, SQLExpression } from '../../types';
import { setupMockedDataSource } from '../../__mocks__/CloudWatchDataSource'; import { setupMockedDataSource } from '../../__mocks__/CloudWatchDataSource';
import { createArray, createGroupBy } from '../../__mocks__/sqlUtils'; import { createArray, createGroupBy } from '../../__mocks__/sqlUtils';
@ -32,30 +33,57 @@ describe('Cloudwatch SQLGroupBy', () => {
}); });
render(<SQLGroupBy {...baseProps} query={query} />); render(<SQLGroupBy {...baseProps} query={query} />);
act(async () => { await waitFor(() => {
await waitFor(() => expect(screen.queryByText('InstanceId')).not.toBeInTheDocument();
expect(datasource.getDimensionKeys).toHaveBeenCalledWith(query.namespace, query.region, {}, undefined) expect(screen.queryByText('InstanceType')).not.toBeInTheDocument();
);
}); });
}); });
it('should load dimension keys with a dimension filter in case a group bys exist', async () => { it('should load dimension keys with a dimension filter in case a group bys exist', async () => {
const query = makeSQLQuery({ const query = makeSQLQuery({
groupBy: createArray([createGroupBy('InstanceId'), createGroupBy('InstanceType')]), groupBy: createArray([createGroupBy('InstanceId'), createGroupBy('InstanceType')]),
}); });
render(<SQLGroupBy {...baseProps} query={query} />); render(<SQLGroupBy {...baseProps} query={query} />);
act(async () => { await waitFor(() => {
expect(screen.getByText('InstanceId')).toBeInTheDocument(); expect(screen.getByText('InstanceId')).toBeInTheDocument();
expect(screen.getByText('InstanceType')).toBeInTheDocument(); expect(screen.getByText('InstanceType')).toBeInTheDocument();
});
});
await waitFor(() => it('should allow adding a new dimension filter', async () => {
expect(datasource.getDimensionKeys).toHaveBeenCalledWith( const query = makeSQLQuery({
query.namespace, groupBy: undefined,
query.region, });
{ InstanceId: null, InstanceType: null }, render(<SQLGroupBy {...baseProps} query={query} />);
undefined
) expect(screen.queryByText('Choose')).not.toBeInTheDocument();
); expect(screen.queryByText('Template Variables')).not.toBeInTheDocument();
const addButton = screen.getByRole('button', { name: 'Add' });
expect(addButton).toBeInTheDocument();
addButton.click();
expect(await screen.findByText('Choose')).toBeInTheDocument();
selectEvent.openMenu(screen.getByLabelText(/Group by/));
expect(await screen.findByText('Template Variables')).toBeInTheDocument();
});
it('should allow removing a dimension filter', async () => {
const query = makeSQLQuery({
groupBy: createArray([createGroupBy('InstanceId')]),
});
render(<SQLGroupBy {...baseProps} query={query} />);
expect(screen.getByText('InstanceId')).toBeInTheDocument();
const removeButton = screen.getByRole('button', { name: 'remove' });
expect(removeButton).toBeInTheDocument();
removeButton.click();
await waitFor(() => {
expect(screen.queryByText('InstanceId')).not.toBeInTheDocument();
}); });
}); });
}); });

View File

@ -91,6 +91,7 @@ const GroupByItem: React.FC<GroupByItemProps> = (props) => {
return ( return (
<InputGroup> <InputGroup>
<Select <Select
aria-label={`Group by ${fieldName ?? 'filter key'}`}
width="auto" width="auto"
value={fieldName ? toOption(fieldName) : null} value={fieldName ? toOption(fieldName) : null}
options={options} options={options}