2022-08-19 09:00:53 -05:00
|
|
|
import { render } from '@testing-library/react';
|
2019-01-09 04:39:56 -06:00
|
|
|
import React from 'react';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2022-12-20 08:04:14 -06:00
|
|
|
import { PanelModel } from '../dashboard/state';
|
|
|
|
import { createDashboardModelFixture, createPanelJSONFixture } from '../dashboard/state/__fixtures__/dashboardFixtures';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2023-02-10 03:23:40 -06:00
|
|
|
import { TestRuleResult } from './TestRuleResult';
|
|
|
|
|
|
|
|
const backendSrv = {
|
|
|
|
post: jest.fn(),
|
|
|
|
};
|
2019-01-09 04:39:56 -06:00
|
|
|
|
2020-01-21 03:08:07 -06:00
|
|
|
jest.mock('@grafana/runtime', () => {
|
|
|
|
const original = jest.requireActual('@grafana/runtime');
|
|
|
|
|
|
|
|
return {
|
|
|
|
...original,
|
2023-02-10 03:23:40 -06:00
|
|
|
getBackendSrv: () => backendSrv,
|
2020-01-21 03:08:07 -06:00
|
|
|
};
|
|
|
|
});
|
2019-01-09 04:39:56 -06:00
|
|
|
|
2023-02-10 03:23:40 -06:00
|
|
|
const props: React.ComponentProps<typeof TestRuleResult> = {
|
2022-08-19 09:00:53 -05:00
|
|
|
panel: new PanelModel({ id: 1 }),
|
2022-12-20 08:04:14 -06:00
|
|
|
dashboard: createDashboardModelFixture({
|
|
|
|
panels: [createPanelJSONFixture({ id: 1 })],
|
|
|
|
}),
|
2019-01-09 04:39:56 -06:00
|
|
|
};
|
|
|
|
|
2022-08-19 09:00:53 -05:00
|
|
|
describe('TestRuleResult', () => {
|
|
|
|
it('should render without error', () => {
|
|
|
|
expect(() => render(<TestRuleResult {...props} />)).not.toThrow();
|
2019-01-09 04:39:56 -06:00
|
|
|
});
|
|
|
|
|
2022-08-19 09:00:53 -05:00
|
|
|
it('should call testRule when mounting', () => {
|
2023-02-10 03:23:40 -06:00
|
|
|
jest.spyOn(backendSrv, 'post');
|
2022-08-19 09:00:53 -05:00
|
|
|
render(<TestRuleResult {...props} />);
|
2019-01-09 04:39:56 -06:00
|
|
|
|
2023-02-10 03:23:40 -06:00
|
|
|
expect(backendSrv.post).toHaveBeenCalledWith(
|
|
|
|
'/api/alerts/test',
|
|
|
|
expect.objectContaining({
|
|
|
|
panelId: 1,
|
|
|
|
})
|
|
|
|
);
|
2019-01-09 04:39:56 -06:00
|
|
|
});
|
|
|
|
});
|