TestRuleResult.test.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { shallow } from 'enzyme';
  2. import React from 'react';
  3. import { DashboardModel, PanelModel } from '../dashboard/state';
  4. import { TestRuleResult, Props } from './TestRuleResult';
  5. jest.mock('@grafana/runtime', () => {
  6. const original = jest.requireActual('@grafana/runtime');
  7. return {
  8. ...original,
  9. getBackendSrv: () => ({
  10. post: jest.fn(),
  11. }),
  12. };
  13. });
  14. const setup = (propOverrides?: object) => {
  15. const props: Props = {
  16. panel: new PanelModel({ id: 1 }),
  17. dashboard: new DashboardModel({ panels: [{ id: 1 }] }),
  18. };
  19. Object.assign(props, propOverrides);
  20. const wrapper = shallow(<TestRuleResult {...props} />);
  21. return { wrapper, instance: wrapper.instance() as TestRuleResult };
  22. };
  23. describe('Render', () => {
  24. it('should render component', () => {
  25. const { wrapper } = setup();
  26. expect(wrapper).toMatchSnapshot();
  27. });
  28. });
  29. describe('Life cycle', () => {
  30. describe('component did mount', () => {
  31. it('should call testRule', () => {
  32. const { instance } = setup();
  33. instance.testRule = jest.fn();
  34. instance.componentDidMount();
  35. expect(instance.testRule).toHaveBeenCalled();
  36. });
  37. });
  38. });