mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Upgrade @testing-library/user-event to v14 (#47898)
* Update dependency @testing-library/user-event to v14
* everything is async...
* everything is async pt.2
* Fix cascader tests
* hack the yarn.lock file to remove the old version of @testing-library/dom
* some more fixes!
* MOAR FIXES
* more fixes
* remove a bunch of places where we're wrapping in act()
* down to 7 failing tests...
* Fix arrow tests
* Fix rest of NavBarItem tests
* Fix last tests
* Use {Enter} instead of {enter}
* Revert "Use {Enter} instead of {enter}"
This reverts commit e72453bb52.
* remove some unused act imports
* Fix LibraryPanelsSearch tests
* more stable test
* More consistent test...
Co-authored-by: Renovate Bot <bot@renovateapp.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import * as runtime from '@grafana/runtime';
|
||||
import { render, screen, waitFor, waitForElementToBeRemoved } from '@testing-library/react';
|
||||
import { act, render, screen, waitFor } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
import { VariablesUnknownTable, VariablesUnknownTableProps } from './VariablesUnknownTable';
|
||||
@@ -36,25 +36,17 @@ describe('VariablesUnknownTable', () => {
|
||||
});
|
||||
|
||||
describe('when expanding the section', () => {
|
||||
it('then it should show loading spinner', async () => {
|
||||
await getTestContext();
|
||||
|
||||
userEvent.click(screen.getByRole('heading', { name: /renamed or missing variables/i }));
|
||||
await waitFor(() => expect(screen.getByText('Loading...')).toBeInTheDocument());
|
||||
});
|
||||
|
||||
it('then it should call getUnknownsNetwork', async () => {
|
||||
const { getUnknownsNetworkSpy } = await getTestContext();
|
||||
|
||||
userEvent.click(screen.getByRole('heading', { name: /renamed or missing variables/i }));
|
||||
await userEvent.click(screen.getByRole('heading', { name: /renamed or missing variables/i }));
|
||||
await waitFor(() => expect(getUnknownsNetworkSpy).toHaveBeenCalledTimes(1));
|
||||
});
|
||||
|
||||
it('then it should report the interaction', async () => {
|
||||
const { reportInteractionSpy } = await getTestContext();
|
||||
|
||||
userEvent.click(screen.getByRole('heading', { name: /renamed or missing variables/i }));
|
||||
await waitFor(() => expect(screen.getByText('Loading...')).toBeInTheDocument());
|
||||
await userEvent.click(screen.getByRole('heading', { name: /renamed or missing variables/i }));
|
||||
|
||||
expect(reportInteractionSpy).toHaveBeenCalledTimes(1);
|
||||
expect(reportInteractionSpy).toHaveBeenCalledWith('Unknown variables section expanded');
|
||||
@@ -64,14 +56,14 @@ describe('VariablesUnknownTable', () => {
|
||||
it('then it should not call getUnknownsNetwork', async () => {
|
||||
const { getUnknownsNetworkSpy } = await getTestContext();
|
||||
|
||||
userEvent.click(screen.getByRole('heading', { name: /renamed or missing variables/i }));
|
||||
await userEvent.click(screen.getByRole('heading', { name: /renamed or missing variables/i }));
|
||||
await waitFor(() => expect(screen.getByRole('button')).toHaveAttribute('aria-expanded', 'true'));
|
||||
expect(getUnknownsNetworkSpy).toHaveBeenCalledTimes(1);
|
||||
|
||||
userEvent.click(screen.getByRole('heading', { name: /renamed or missing variables/i }));
|
||||
await userEvent.click(screen.getByRole('heading', { name: /renamed or missing variables/i }));
|
||||
await waitFor(() => expect(screen.getByRole('button')).toHaveAttribute('aria-expanded', 'false'));
|
||||
|
||||
userEvent.click(screen.getByRole('heading', { name: /renamed or missing variables/i }));
|
||||
await userEvent.click(screen.getByRole('heading', { name: /renamed or missing variables/i }));
|
||||
await waitFor(() => expect(screen.getByRole('button')).toHaveAttribute('aria-expanded', 'true'));
|
||||
|
||||
expect(getUnknownsNetworkSpy).toHaveBeenCalledTimes(1);
|
||||
@@ -82,8 +74,7 @@ describe('VariablesUnknownTable', () => {
|
||||
it('then it should render the correct message', async () => {
|
||||
await getTestContext();
|
||||
|
||||
userEvent.click(screen.getByRole('heading', { name: /renamed or missing variables/i }));
|
||||
await waitForElementToBeRemoved(() => screen.getByText('Loading...'));
|
||||
await userEvent.click(screen.getByRole('heading', { name: /renamed or missing variables/i }));
|
||||
|
||||
expect(screen.getByText('No renamed or missing variables found.')).toBeInTheDocument();
|
||||
});
|
||||
@@ -95,8 +86,7 @@ describe('VariablesUnknownTable', () => {
|
||||
const usages = [{ variable, nodes: [], edges: [], showGraph: false }];
|
||||
const { reportInteractionSpy } = await getTestContext({}, usages);
|
||||
|
||||
userEvent.click(screen.getByRole('heading', { name: /renamed or missing variables/i }));
|
||||
await waitForElementToBeRemoved(() => screen.getByText('Loading...'));
|
||||
await userEvent.click(screen.getByRole('heading', { name: /renamed or missing variables/i }));
|
||||
|
||||
expect(screen.queryByText('No renamed or missing variables found.')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('Renamed Variable')).toBeInTheDocument();
|
||||
@@ -117,16 +107,22 @@ describe('VariablesUnknownTable', () => {
|
||||
it('then it should report slow expansion', async () => {
|
||||
const variable = customBuilder().withId('Renamed Variable').withName('Renamed Variable').build();
|
||||
const usages = [{ variable, nodes: [], edges: [], showGraph: false }];
|
||||
const { reportInteractionSpy } = await getTestContext({}, usages);
|
||||
const { reportInteractionSpy, rerender } = await getTestContext({}, usages);
|
||||
const dateNowStart = 1000;
|
||||
const dateNowStop = 2000;
|
||||
Date.now = jest.fn().mockReturnValueOnce(dateNowStart).mockReturnValue(dateNowStop);
|
||||
|
||||
userEvent.click(screen.getByRole('heading', { name: /renamed or missing variables/i }));
|
||||
await waitForElementToBeRemoved(() => screen.getByText('Loading...'));
|
||||
await userEvent.click(screen.getByRole('heading', { name: /renamed or missing variables/i }));
|
||||
const props: VariablesUnknownTableProps = {
|
||||
variables: [],
|
||||
dashboard: null,
|
||||
};
|
||||
await act(async () => {
|
||||
rerender(<VariablesUnknownTable {...props} />);
|
||||
});
|
||||
|
||||
// make sure we report the interaction for slow expansion
|
||||
expect(reportInteractionSpy).toHaveBeenCalledTimes(2);
|
||||
await waitFor(() => expect(reportInteractionSpy).toHaveBeenCalledTimes(2));
|
||||
expect(reportInteractionSpy.mock.calls[0][0]).toEqual('Unknown variables section expanded');
|
||||
expect(reportInteractionSpy.mock.calls[1][0]).toEqual('Slow unknown variables expansion');
|
||||
expect(reportInteractionSpy.mock.calls[1][1]).toEqual({ elapsed: 1000 });
|
||||
|
||||
Reference in New Issue
Block a user