mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix being redirected to list view when clicking Save rule button (#75510)
* Fix: dont allow 'Save rule' button and let 'Save rule and exit' in case of new rule * Fix tests
This commit is contained in:
parent
e4c1a7a141
commit
1456b26075
@ -152,7 +152,7 @@ describe('RuleEditor cloud', () => {
|
|||||||
await user.type(getLabelInput(ui.inputs.labelValue(0).get()), 'warn{enter}');
|
await user.type(getLabelInput(ui.inputs.labelValue(0).get()), 'warn{enter}');
|
||||||
|
|
||||||
// save and check what was sent to backend
|
// save and check what was sent to backend
|
||||||
await user.click(ui.buttons.save.get());
|
await user.click(ui.buttons.saveAndExit.get());
|
||||||
await waitFor(() => expect(mocks.api.setRulerRuleGroup).toHaveBeenCalled());
|
await waitFor(() => expect(mocks.api.setRulerRuleGroup).toHaveBeenCalled());
|
||||||
expect(mocks.api.setRulerRuleGroup).toHaveBeenCalledWith(
|
expect(mocks.api.setRulerRuleGroup).toHaveBeenCalledWith(
|
||||||
{ dataSourceName: 'Prom', apiVersion: 'config' },
|
{ dataSourceName: 'Prom', apiVersion: 'config' },
|
||||||
|
@ -145,7 +145,7 @@ describe('RuleEditor grafana managed rules', () => {
|
|||||||
//8 segons
|
//8 segons
|
||||||
|
|
||||||
// save and check what was sent to backend
|
// save and check what was sent to backend
|
||||||
await userEvent.click(ui.buttons.save.get());
|
await userEvent.click(ui.buttons.saveAndExit.get());
|
||||||
// 9seg
|
// 9seg
|
||||||
await waitFor(() => expect(mocks.api.setRulerRuleGroup).toHaveBeenCalled());
|
await waitFor(() => expect(mocks.api.setRulerRuleGroup).toHaveBeenCalled());
|
||||||
// 9seg
|
// 9seg
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { waitFor, screen, within, waitForElementToBeRemoved } from '@testing-library/react';
|
import { screen, waitFor, waitForElementToBeRemoved, within } from '@testing-library/react';
|
||||||
import userEvent, { PointerEventsCheckLevel } from '@testing-library/user-event';
|
import userEvent, { PointerEventsCheckLevel } from '@testing-library/user-event';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { renderRuleEditor, ui } from 'test/helpers/alertingRuleEditor';
|
import { renderRuleEditor, ui } from 'test/helpers/alertingRuleEditor';
|
||||||
@ -151,7 +151,7 @@ describe('RuleEditor recording rules', () => {
|
|||||||
await userEvent.type(getLabelInput(ui.inputs.labelValue(1).get()), 'the a-team{enter}');
|
await userEvent.type(getLabelInput(ui.inputs.labelValue(1).get()), 'the a-team{enter}');
|
||||||
|
|
||||||
// try to save, find out that recording rule name is invalid
|
// try to save, find out that recording rule name is invalid
|
||||||
await userEvent.click(ui.buttons.save.get());
|
await userEvent.click(ui.buttons.saveAndExit.get());
|
||||||
await waitFor(() =>
|
await waitFor(() =>
|
||||||
expect(
|
expect(
|
||||||
byText(
|
byText(
|
||||||
@ -166,7 +166,7 @@ describe('RuleEditor recording rules', () => {
|
|||||||
await userEvent.type(await ui.inputs.name.find(), 'my:great:new:recording:rule');
|
await userEvent.type(await ui.inputs.name.find(), 'my:great:new:recording:rule');
|
||||||
|
|
||||||
// save and check what was sent to backend
|
// save and check what was sent to backend
|
||||||
await userEvent.click(ui.buttons.save.get());
|
await userEvent.click(ui.buttons.saveAndExit.get());
|
||||||
await waitFor(() => expect(mocks.api.setRulerRuleGroup).toHaveBeenCalled());
|
await waitFor(() => expect(mocks.api.setRulerRuleGroup).toHaveBeenCalled());
|
||||||
expect(mocks.api.setRulerRuleGroup).toHaveBeenCalledWith(
|
expect(mocks.api.setRulerRuleGroup).toHaveBeenCalledWith(
|
||||||
{ dataSourceName: 'Prom', apiVersion: 'legacy' },
|
{ dataSourceName: 'Prom', apiVersion: 'legacy' },
|
||||||
|
@ -166,6 +166,7 @@ export const AlertRuleForm = ({ existing, prefill }: Props) => {
|
|||||||
|
|
||||||
const actionButtons = (
|
const actionButtons = (
|
||||||
<HorizontalGroup height="auto" justify="flex-end">
|
<HorizontalGroup height="auto" justify="flex-end">
|
||||||
|
{existing && (
|
||||||
<Button
|
<Button
|
||||||
variant="primary"
|
variant="primary"
|
||||||
type="button"
|
type="button"
|
||||||
@ -176,6 +177,7 @@ export const AlertRuleForm = ({ existing, prefill }: Props) => {
|
|||||||
{submitState.loading && <Spinner className={styles.buttonSpinner} inline={true} />}
|
{submitState.loading && <Spinner className={styles.buttonSpinner} inline={true} />}
|
||||||
Save rule
|
Save rule
|
||||||
</Button>
|
</Button>
|
||||||
|
)}
|
||||||
<Button
|
<Button
|
||||||
variant="primary"
|
variant="primary"
|
||||||
type="button"
|
type="button"
|
||||||
|
@ -25,6 +25,7 @@ export const ui = {
|
|||||||
expr: byTestId('expr'),
|
expr: byTestId('expr'),
|
||||||
},
|
},
|
||||||
buttons: {
|
buttons: {
|
||||||
|
saveAndExit: byRole('button', { name: 'Save rule and exit' }),
|
||||||
save: byRole('button', { name: 'Save rule' }),
|
save: byRole('button', { name: 'Save rule' }),
|
||||||
addAnnotation: byRole('button', { name: /Add info/ }),
|
addAnnotation: byRole('button', { name: /Add info/ }),
|
||||||
addLabel: byRole('button', { name: /Add label/ }),
|
addLabel: byRole('button', { name: /Add label/ }),
|
||||||
|
Loading…
Reference in New Issue
Block a user