Chore: clean up console warning from Cloudwatch Dimensions tests (#46661)

This commit is contained in:
Kevin Yu
2022-03-17 06:59:55 -07:00
committed by GitHub
parent 7c255f190c
commit 56b750dc42

View File

@@ -1,11 +1,9 @@
import React from 'react';
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
import { fireEvent, render, screen, act, within } from '@testing-library/react';
import { setupMockedDataSource } from '../../__mocks__/CloudWatchDataSource';
import '@testing-library/jest-dom';
import { CloudWatchMetricsQuery } from '../../types';
import userEvent from '@testing-library/user-event';
import { Dimensions } from '..';
import { within } from '@testing-library/dom';
const ds = setupMockedDataSource({
variables: [],
@@ -36,7 +34,6 @@ const props = {
onChange: jest.fn(),
onRunQuery: jest.fn(),
};
afterEach(cleanup);
describe('Dimensions', () => {
describe('when rendered with two existing dimensions', () => {
@@ -97,20 +94,25 @@ describe('Dimensions', () => {
<Dimensions {...props} query={props.query} onChange={onChange} dimensionKeys={[]} />
);
userEvent.click(screen.getByLabelText('Add'));
const label = await screen.findByLabelText('Add');
userEvent.click(label);
const filterItemElement = screen.getByTestId('cloudwatch-dimensions-filter-item');
expect(filterItemElement).toBeInTheDocument();
const keyElement = container.querySelector('#cloudwatch-dimensions-filter-item-key');
expect(keyElement).toBeInTheDocument();
userEvent.type(keyElement!, 'my-key');
fireEvent.keyDown(keyElement!, { keyCode: 13 });
await act(async () => {
userEvent.type(keyElement!, 'my-key');
fireEvent.keyDown(keyElement!, { keyCode: 13 });
});
expect(onChange).not.toHaveBeenCalled();
const valueElement = container.querySelector('#cloudwatch-dimensions-filter-item-value');
expect(valueElement).toBeInTheDocument();
userEvent.type(valueElement!, 'my-value');
fireEvent.keyDown(valueElement!, { keyCode: 13 });
await act(async () => {
userEvent.type(valueElement!, 'my-value');
fireEvent.keyDown(valueElement!, { keyCode: 13 });
});
expect(onChange).not.toHaveBeenCalledWith({
...props.query,
dimensions: {