From 9b8a5333cb8cf3bcf41ec39c9f07d9270febad3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=A4ggmark?= Date: Wed, 9 Jan 2019 11:39:56 +0100 Subject: [PATCH] Added tests for TestRuleButton --- .../features/alerting/TestRuleButton.test.tsx | 44 +++++++++++++++++++ .../TestRuleButton.test.tsx.snap | 15 +++++++ 2 files changed, 59 insertions(+) create mode 100644 public/app/features/alerting/TestRuleButton.test.tsx create mode 100644 public/app/features/alerting/__snapshots__/TestRuleButton.test.tsx.snap diff --git a/public/app/features/alerting/TestRuleButton.test.tsx b/public/app/features/alerting/TestRuleButton.test.tsx new file mode 100644 index 00000000000..ae3b570cf43 --- /dev/null +++ b/public/app/features/alerting/TestRuleButton.test.tsx @@ -0,0 +1,44 @@ +import React from 'react'; +import { shallow } from 'enzyme'; +import { DashboardModel } from '../dashboard/dashboard_model'; +import { Props, TestRuleButton } from './TestRuleButton'; + +jest.mock('app/core/services/backend_srv', () => ({ + getBackendSrv: () => ({ + post: jest.fn(), + }), +})); + +const setup = (propOverrides?: object) => { + const props: Props = { + panelId: 1, + dashboard: new DashboardModel({ panels: [{ id: 1 }] }), + LoadingPlaceholder: {}, + }; + + Object.assign(props, propOverrides); + + const wrapper = shallow(); + + return { wrapper, instance: wrapper.instance() as TestRuleButton }; +}; + +describe('Render', () => { + it('should render component', () => { + const { wrapper } = setup(); + + expect(wrapper).toMatchSnapshot(); + }); +}); + +describe('Life cycle', () => { + describe('component did mount', () => { + it('should call testRule', () => { + const { instance } = setup(); + instance.testRule = jest.fn(); + instance.componentDidMount(); + + expect(instance.testRule).toHaveBeenCalled(); + }); + }); +}); diff --git a/public/app/features/alerting/__snapshots__/TestRuleButton.test.tsx.snap b/public/app/features/alerting/__snapshots__/TestRuleButton.test.tsx.snap new file mode 100644 index 00000000000..0e1c95d7233 --- /dev/null +++ b/public/app/features/alerting/__snapshots__/TestRuleButton.test.tsx.snap @@ -0,0 +1,15 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Render should render component 1`] = ` + + + +`;