mirror of
https://github.com/grafana/grafana.git
synced 2024-11-24 09:50:29 -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"],
|
||||
"rules": {
|
||||
"testing-library/prefer-user-event": "error",
|
||||
"jest/expect-expect": ["error", { "assertFunctionNames": ["expect*", "reducerTester"] }],
|
||||
},
|
||||
},
|
||||
],
|
||||
|
@ -158,7 +158,7 @@ const defaultConfigWithBothTimeIntervalsField: AlertManagerCortexConfig = {
|
||||
template_files: {},
|
||||
};
|
||||
|
||||
const expectedToHaveRedirectedToRoutesRoute = async () =>
|
||||
const expectToHaveRedirectedToRoutesRoute = async () =>
|
||||
expect(await screen.findByText(indexPageText)).toBeInTheDocument();
|
||||
|
||||
const fillOutForm = async ({
|
||||
@ -226,7 +226,7 @@ describe('Mute timings', () => {
|
||||
|
||||
await saveMuteTiming();
|
||||
|
||||
await expectedToHaveRedirectedToRoutesRoute();
|
||||
await expectToHaveRedirectedToRoutesRoute();
|
||||
|
||||
const requests = await capture;
|
||||
const alertmanagerUpdate = await getAlertmanagerConfigUpdate(requests);
|
||||
@ -252,7 +252,7 @@ describe('Mute timings', () => {
|
||||
});
|
||||
|
||||
await saveMuteTiming();
|
||||
await expectedToHaveRedirectedToRoutesRoute();
|
||||
await expectToHaveRedirectedToRoutesRoute();
|
||||
|
||||
const requests = await capture;
|
||||
const alertmanagerUpdate = await getAlertmanagerConfigUpdate(requests);
|
||||
@ -278,7 +278,7 @@ describe('Mute timings', () => {
|
||||
});
|
||||
|
||||
await saveMuteTiming();
|
||||
await expectedToHaveRedirectedToRoutesRoute();
|
||||
await expectToHaveRedirectedToRoutesRoute();
|
||||
});
|
||||
|
||||
it('prepopulates the form when editing a mute timing', async () => {
|
||||
@ -310,7 +310,7 @@ describe('Mute timings', () => {
|
||||
await fillOutForm(formValues);
|
||||
|
||||
await saveMuteTiming();
|
||||
await expectedToHaveRedirectedToRoutesRoute();
|
||||
await expectToHaveRedirectedToRoutesRoute();
|
||||
|
||||
const requests = await capture;
|
||||
const alertmanagerUpdate = await getAlertmanagerConfigUpdate(requests);
|
||||
@ -345,7 +345,7 @@ describe('Mute timings', () => {
|
||||
await fillOutForm({ name: 'Lunch breaks' });
|
||||
await saveMuteTiming();
|
||||
|
||||
await expectedToHaveRedirectedToRoutesRoute();
|
||||
await expectToHaveRedirectedToRoutesRoute();
|
||||
});
|
||||
|
||||
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 saveMuteTiming();
|
||||
await expectedToHaveRedirectedToRoutesRoute();
|
||||
await expectToHaveRedirectedToRoutesRoute();
|
||||
});
|
||||
|
||||
it('shows error when mute timing does not exist', async () => {
|
||||
@ -384,7 +384,7 @@ describe('Mute timings', () => {
|
||||
});
|
||||
|
||||
await saveMuteTiming();
|
||||
await expectedToHaveRedirectedToRoutesRoute();
|
||||
await expectToHaveRedirectedToRoutesRoute();
|
||||
});
|
||||
|
||||
it('loads view form for provisioned interval', async () => {
|
||||
|
@ -19,7 +19,7 @@ import NewReceiverView from './components/receivers/NewReceiverView';
|
||||
|
||||
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
|
||||
// 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 });
|
||||
@ -77,7 +77,7 @@ it('can save a contact point with a select dropdown', async () => {
|
||||
|
||||
await saveContactPoint();
|
||||
|
||||
await assertSaveWasSuccessful();
|
||||
await expectSaveWasSuccessful();
|
||||
});
|
||||
|
||||
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
|
||||
await saveContactPoint();
|
||||
|
||||
await assertSaveWasSuccessful();
|
||||
await expectSaveWasSuccessful();
|
||||
});
|
||||
|
@ -118,7 +118,8 @@ describe('RuleEditor grafana managed rules', () => {
|
||||
await clickSelectOption(groupInput, grafanaRulerGroup.name);
|
||||
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());
|
||||
|
||||
expect(await screen.findByRole('status')).toHaveTextContent('Rule added successfully');
|
||||
});
|
||||
});
|
||||
|
@ -207,10 +207,6 @@ describe('AlertRule abilities', () => {
|
||||
|
||||
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) {
|
||||
|
@ -3,6 +3,7 @@ import { render } from 'test/test-utils';
|
||||
import { byRole, byTestId, byText } from 'testing-library-selector';
|
||||
|
||||
import { selectors } from '@grafana/e2e-selectors';
|
||||
import { AppNotificationList } from 'app/core/components/AppNotifications/AppNotificationList';
|
||||
import RuleEditor from 'app/features/alerting/unified/RuleEditor';
|
||||
|
||||
export const ui = {
|
||||
@ -36,10 +37,13 @@ export const ui = {
|
||||
|
||||
export function renderRuleEditor(identifier?: string, recording = false) {
|
||||
return render(
|
||||
<>
|
||||
<AppNotificationList />
|
||||
<Routes>
|
||||
<Route path={'/alerting/new/:type'} element={<RuleEditor />} />
|
||||
<Route path={'/alerting/:id/edit'} element={<RuleEditor />} />
|
||||
</Routes>,
|
||||
</Routes>
|
||||
</>,
|
||||
{
|
||||
historyOptions: {
|
||||
initialEntries: [
|
||||
|
Loading…
Reference in New Issue
Block a user