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

@@ -236,11 +236,10 @@ describe('PromVariableQueryEditor', () => {
await selectOptionInTest(screen.getByLabelText('Query type'), 'Metrics');
const metricInput = screen.getByLabelText('Metric selector');
await userEvent.type(metricInput, 'a').then((prom) => {
const queryType = screen.getByLabelText('Query type');
// click elsewhere to trigger the onBlur
return userEvent.click(queryType);
});
await userEvent.type(metricInput, 'a');
const queryType = screen.getByLabelText('Query type');
// click elsewhere to trigger the onBlur
await userEvent.click(queryType);
await waitFor(() =>
expect(onChange).toHaveBeenCalledWith({

View File

@@ -38,7 +38,7 @@ describe('PromQail', () => {
it('shows selected metric and asks for a prompt', async () => {
setup(defaultQuery);
clickSecurityButton();
await clickSecurityButton();
await waitFor(() => {
expect(screen.getByText('random_metric')).toBeInTheDocument();
@@ -49,7 +49,7 @@ describe('PromQail', () => {
it('displays a prompt when the user knows what they want to query', async () => {
setup(defaultQuery);
clickSecurityButton();
await clickSecurityButton();
await waitFor(() => {
expect(screen.getByText('random_metric')).toBeInTheDocument();
@@ -58,7 +58,7 @@ describe('PromQail', () => {
const aiPrompt = screen.getByTestId(queryAssistanttestIds.clickForAi);
userEvent.click(aiPrompt);
await userEvent.click(aiPrompt);
await waitFor(() => {
expect(screen.getByText('What kind of data do you want to see with your metric?')).toBeInTheDocument();
@@ -68,7 +68,7 @@ describe('PromQail', () => {
it('does not display a prompt when choosing historical', async () => {
setup(defaultQuery);
clickSecurityButton();
await clickSecurityButton();
await waitFor(() => {
expect(screen.getByText('random_metric')).toBeInTheDocument();
@@ -77,7 +77,7 @@ describe('PromQail', () => {
const historicalPrompt = screen.getByTestId(queryAssistanttestIds.clickForHistorical);
userEvent.click(historicalPrompt);
await userEvent.click(historicalPrompt);
await waitFor(() => {
expect(screen.queryByText('What kind of data do you want to see with your metric?')).toBeNull();
@@ -141,8 +141,8 @@ function setup(query: PromVisualQuery) {
return container;
}
function clickSecurityButton() {
async function clickSecurityButton() {
const securityInfoButton = screen.getByTestId(queryAssistanttestIds.securityInfoButton);
userEvent.click(securityInfoButton);
await userEvent.click(securityInfoButton);
}

View File

@@ -17,7 +17,7 @@ describe('QueryAssistantButton', () => {
const props = createProps(false, 'metric', setShowDrawer);
render(<QueryAssistantButton {...props} />);
const button = screen.getByText('Get query suggestions');
userEvent.hover(button);
await userEvent.hover(button);
await waitFor(() => {
expect(screen.getByText('Install and enable the LLM plugin')).toBeInTheDocument();
});
@@ -27,7 +27,7 @@ describe('QueryAssistantButton', () => {
const props = createProps(true, '', setShowDrawer);
render(<QueryAssistantButton {...props} />);
const button = screen.getByText('Get query suggestions');
userEvent.hover(button);
await userEvent.hover(button);
await waitFor(() => {
expect(screen.getByText('First, select a metric.')).toBeInTheDocument();
});