TestRuleButton.test.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. LoadingPlaceholder: {},
  15. };
  16. Object.assign(props, propOverrides);
  17. const wrapper = shallow(<TestRuleResult {...props} />);
  18. return { wrapper, instance: wrapper.instance() as TestRuleResult };
  19. };
  20. describe('Render', () => {
  21. it('should render component', () => {
  22. const { wrapper } = setup();
  23. expect(wrapper).toMatchSnapshot();
  24. });
  25. });
  26. describe('Life cycle', () => {
  27. describe('component did mount', () => {
  28. it('should call testRule', () => {
  29. const { instance } = setup();
  30. instance.testRule = jest.fn();
  31. instance.componentDidMount();
  32. expect(instance.testRule).toHaveBeenCalled();
  33. });
  34. });
  35. });