TestRuleResult.test.tsx 1.0 KB

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