mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Use jest/expect-expect
rule to check for assertions (#93112)
This commit is contained in:
parent
029b5bc2d0
commit
b91b9a1e38
@ -12,6 +12,7 @@
|
|||||||
"extends": ["plugin:testing-library/react"],
|
"extends": ["plugin:testing-library/react"],
|
||||||
"rules": {
|
"rules": {
|
||||||
"testing-library/prefer-user-event": "error",
|
"testing-library/prefer-user-event": "error",
|
||||||
|
"jest/expect-expect": ["error", { "assertFunctionNames": ["expect*", "reducerTester"] }],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -158,7 +158,7 @@ const defaultConfigWithBothTimeIntervalsField: AlertManagerCortexConfig = {
|
|||||||
template_files: {},
|
template_files: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const expectedToHaveRedirectedToRoutesRoute = async () =>
|
const expectToHaveRedirectedToRoutesRoute = async () =>
|
||||||
expect(await screen.findByText(indexPageText)).toBeInTheDocument();
|
expect(await screen.findByText(indexPageText)).toBeInTheDocument();
|
||||||
|
|
||||||
const fillOutForm = async ({
|
const fillOutForm = async ({
|
||||||
@ -226,7 +226,7 @@ describe('Mute timings', () => {
|
|||||||
|
|
||||||
await saveMuteTiming();
|
await saveMuteTiming();
|
||||||
|
|
||||||
await expectedToHaveRedirectedToRoutesRoute();
|
await expectToHaveRedirectedToRoutesRoute();
|
||||||
|
|
||||||
const requests = await capture;
|
const requests = await capture;
|
||||||
const alertmanagerUpdate = await getAlertmanagerConfigUpdate(requests);
|
const alertmanagerUpdate = await getAlertmanagerConfigUpdate(requests);
|
||||||
@ -252,7 +252,7 @@ describe('Mute timings', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await saveMuteTiming();
|
await saveMuteTiming();
|
||||||
await expectedToHaveRedirectedToRoutesRoute();
|
await expectToHaveRedirectedToRoutesRoute();
|
||||||
|
|
||||||
const requests = await capture;
|
const requests = await capture;
|
||||||
const alertmanagerUpdate = await getAlertmanagerConfigUpdate(requests);
|
const alertmanagerUpdate = await getAlertmanagerConfigUpdate(requests);
|
||||||
@ -278,7 +278,7 @@ describe('Mute timings', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await saveMuteTiming();
|
await saveMuteTiming();
|
||||||
await expectedToHaveRedirectedToRoutesRoute();
|
await expectToHaveRedirectedToRoutesRoute();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prepopulates the form when editing a mute timing', async () => {
|
it('prepopulates the form when editing a mute timing', async () => {
|
||||||
@ -310,7 +310,7 @@ describe('Mute timings', () => {
|
|||||||
await fillOutForm(formValues);
|
await fillOutForm(formValues);
|
||||||
|
|
||||||
await saveMuteTiming();
|
await saveMuteTiming();
|
||||||
await expectedToHaveRedirectedToRoutesRoute();
|
await expectToHaveRedirectedToRoutesRoute();
|
||||||
|
|
||||||
const requests = await capture;
|
const requests = await capture;
|
||||||
const alertmanagerUpdate = await getAlertmanagerConfigUpdate(requests);
|
const alertmanagerUpdate = await getAlertmanagerConfigUpdate(requests);
|
||||||
@ -345,7 +345,7 @@ describe('Mute timings', () => {
|
|||||||
await fillOutForm({ name: 'Lunch breaks' });
|
await fillOutForm({ name: 'Lunch breaks' });
|
||||||
await saveMuteTiming();
|
await saveMuteTiming();
|
||||||
|
|
||||||
await expectedToHaveRedirectedToRoutesRoute();
|
await expectToHaveRedirectedToRoutesRoute();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows error when mute timing does not exist', async () => {
|
it('shows error when mute timing does not exist', async () => {
|
||||||
@ -367,7 +367,7 @@ describe('Mute timings', () => {
|
|||||||
await fillOutForm({ name: 'a new mute timing' });
|
await fillOutForm({ name: 'a new mute timing' });
|
||||||
|
|
||||||
await saveMuteTiming();
|
await saveMuteTiming();
|
||||||
await expectedToHaveRedirectedToRoutesRoute();
|
await expectToHaveRedirectedToRoutesRoute();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows error when mute timing does not exist', async () => {
|
it('shows error when mute timing does not exist', async () => {
|
||||||
@ -384,7 +384,7 @@ describe('Mute timings', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await saveMuteTiming();
|
await saveMuteTiming();
|
||||||
await expectedToHaveRedirectedToRoutesRoute();
|
await expectToHaveRedirectedToRoutesRoute();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('loads view form for provisioned interval', async () => {
|
it('loads view form for provisioned interval', async () => {
|
||||||
|
@ -19,7 +19,7 @@ import NewReceiverView from './components/receivers/NewReceiverView';
|
|||||||
|
|
||||||
const server = setupMswServer();
|
const server = setupMswServer();
|
||||||
|
|
||||||
const assertSaveWasSuccessful = async () => {
|
const expectSaveWasSuccessful = async () => {
|
||||||
// TODO: Have a better way to assert that the contact point was saved. This is instead asserting on some
|
// TODO: Have a better way to assert that the contact point was saved. This is instead asserting on some
|
||||||
// text that's present on the list page, as there's a lot of overlap in text between the form and the list page
|
// text that's present on the list page, as there's a lot of overlap in text between the form and the list page
|
||||||
return waitFor(() => expect(screen.getByText(/search by name or type/i)).toBeInTheDocument(), { timeout: 2000 });
|
return waitFor(() => expect(screen.getByText(/search by name or type/i)).toBeInTheDocument(), { timeout: 2000 });
|
||||||
@ -77,7 +77,7 @@ it('can save a contact point with a select dropdown', async () => {
|
|||||||
|
|
||||||
await saveContactPoint();
|
await saveContactPoint();
|
||||||
|
|
||||||
await assertSaveWasSuccessful();
|
await expectSaveWasSuccessful();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can save existing Telegram contact point', async () => {
|
it('can save existing Telegram contact point', async () => {
|
||||||
@ -89,5 +89,5 @@ it('can save existing Telegram contact point', async () => {
|
|||||||
// trigger this error if it regresses
|
// trigger this error if it regresses
|
||||||
await saveContactPoint();
|
await saveContactPoint();
|
||||||
|
|
||||||
await assertSaveWasSuccessful();
|
await expectSaveWasSuccessful();
|
||||||
});
|
});
|
||||||
|
@ -118,7 +118,8 @@ describe('RuleEditor grafana managed rules', () => {
|
|||||||
await clickSelectOption(groupInput, grafanaRulerGroup.name);
|
await clickSelectOption(groupInput, grafanaRulerGroup.name);
|
||||||
await userEvent.type(ui.inputs.annotationValue(1).get(), 'some description');
|
await userEvent.type(ui.inputs.annotationValue(1).get(), 'some description');
|
||||||
|
|
||||||
// save and check what was sent to backend
|
|
||||||
await userEvent.click(ui.buttons.saveAndExit.get());
|
await userEvent.click(ui.buttons.saveAndExit.get());
|
||||||
|
|
||||||
|
expect(await screen.findByRole('status')).toHaveTextContent('Rule added successfully');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -207,10 +207,6 @@ describe('AlertRule abilities', () => {
|
|||||||
|
|
||||||
expect(result.current).toMatchSnapshot();
|
expect(result.current).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not allow certain actions for provisioned rules', () => {});
|
|
||||||
|
|
||||||
it('should not allow certain actions for federated rules', () => {});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function createAlertmanagerWrapper(alertmanagerSourceName: string) {
|
function createAlertmanagerWrapper(alertmanagerSourceName: string) {
|
||||||
|
@ -3,6 +3,7 @@ import { render } from 'test/test-utils';
|
|||||||
import { byRole, byTestId, byText } from 'testing-library-selector';
|
import { byRole, byTestId, byText } from 'testing-library-selector';
|
||||||
|
|
||||||
import { selectors } from '@grafana/e2e-selectors';
|
import { selectors } from '@grafana/e2e-selectors';
|
||||||
|
import { AppNotificationList } from 'app/core/components/AppNotifications/AppNotificationList';
|
||||||
import RuleEditor from 'app/features/alerting/unified/RuleEditor';
|
import RuleEditor from 'app/features/alerting/unified/RuleEditor';
|
||||||
|
|
||||||
export const ui = {
|
export const ui = {
|
||||||
@ -36,10 +37,13 @@ export const ui = {
|
|||||||
|
|
||||||
export function renderRuleEditor(identifier?: string, recording = false) {
|
export function renderRuleEditor(identifier?: string, recording = false) {
|
||||||
return render(
|
return render(
|
||||||
|
<>
|
||||||
|
<AppNotificationList />
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path={'/alerting/new/:type'} element={<RuleEditor />} />
|
<Route path={'/alerting/new/:type'} element={<RuleEditor />} />
|
||||||
<Route path={'/alerting/:id/edit'} element={<RuleEditor />} />
|
<Route path={'/alerting/:id/edit'} element={<RuleEditor />} />
|
||||||
</Routes>,
|
</Routes>
|
||||||
|
</>,
|
||||||
{
|
{
|
||||||
historyOptions: {
|
historyOptions: {
|
||||||
initialEntries: [
|
initialEntries: [
|
||||||
|
Loading…
Reference in New Issue
Block a user