mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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({
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user