Chore: fix some bad uses of userEvent (#82191)

* fix some bad uses of userEvent

* wrap advance call in act

* don't use act

* remove skip

* need act here (see https://kentcdodds.com/blog/fix-the-not-wrapped-in-act-warning#1-when-using-jestusefaketimers)

* remove test that isn't correct anymore

* implement same change in grafana-prometheus
This commit is contained in:
Ashley Harrison
2024-02-09 10:04:35 +00:00
committed by GitHub
parent e9dab611fe
commit 765a1f8533
17 changed files with 79 additions and 170 deletions

View File

@@ -12,12 +12,12 @@ describe('AlertLabels', () => {
render(<AlertLabels labels={labels} commonLabels={commonLabels} />);
expect(screen.getByText('+2 common labels')).toBeInTheDocument();
userEvent.click(screen.getByRole('button'));
await userEvent.click(screen.getByRole('button'));
await waitFor(() => {
expect(screen.getByText('Hide common labels')).toBeInTheDocument();
});
userEvent.click(screen.getByRole('button'));
await userEvent.click(screen.getByRole('button'));
await waitFor(() => {
expect(screen.getByText('+2 common labels')).toBeInTheDocument();
});

View File

@@ -1,63 +0,0 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { PluginType } from '@grafana/data';
import { Expression } from './Expression';
const expression =
'100 - ( avg by ( agent_hostname ) ( rate ( node_cpu_seconds_total { mode = "idle" } [ 2h ] ) ) * 100 ) > 97';
const rulesSource = {
id: 5,
uid: 'gdev-prometheus',
type: 'prometheus',
name: 'gdev-prometheus',
meta: {
id: 'prometheus',
type: PluginType.datasource,
name: 'Prometheus',
info: {
author: {
name: 'Grafana Labs',
url: 'https://grafana.com',
},
description: 'Open source time series database & alerting',
links: [
{
name: 'Learn more',
url: 'https://prometheus.io/',
},
],
logos: {
small: 'public/app/plugins/datasource/prometheus/img/prometheus_logo.svg',
large: 'public/app/plugins/datasource/prometheus/img/prometheus_logo.svg',
},
build: {},
screenshots: [],
version: '',
updated: '',
},
module: 'app/plugins/datasource/prometheus/module',
baseUrl: 'public/app/plugins/datasource/prometheus',
},
url: '/api/datasources/proxy/5',
access: 'proxy' as const,
jsonData: {
manageAlerts: true,
},
readOnly: false,
};
describe('Expression', () => {
it('Should not allow to edit the text in the editor', () => {
render(<Expression expression={expression} rulesSource={rulesSource} />);
const editor = screen.getByTestId('expression-editor');
userEvent.type(editor, 'something else');
expect(editor).toHaveTextContent(expression);
expect(editor).not.toHaveTextContent('something else');
});
});