|
|
|
@ -1,4 +1,4 @@ |
|
|
|
|
import { shallow } from 'enzyme'; |
|
|
|
|
import { render } from '@testing-library/react'; |
|
|
|
|
import React from 'react'; |
|
|
|
|
|
|
|
|
|
import { DashboardModel, PanelModel } from '../dashboard/state'; |
|
|
|
@ -16,35 +16,20 @@ jest.mock('@grafana/runtime', () => { |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const setup = (propOverrides?: object) => { |
|
|
|
|
const props: Props = { |
|
|
|
|
panel: new PanelModel({ id: 1 }), |
|
|
|
|
dashboard: new DashboardModel({ panels: [{ id: 1 }] }), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Object.assign(props, propOverrides); |
|
|
|
|
|
|
|
|
|
const wrapper = shallow(<TestRuleResult {...props} />); |
|
|
|
|
|
|
|
|
|
return { wrapper, instance: wrapper.instance() as TestRuleResult }; |
|
|
|
|
const props: Props = { |
|
|
|
|
panel: new PanelModel({ id: 1 }), |
|
|
|
|
dashboard: new DashboardModel({ panels: [{ id: 1 }] }), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
describe('Render', () => { |
|
|
|
|
it('should render component', () => { |
|
|
|
|
const { wrapper } = setup(); |
|
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot(); |
|
|
|
|
describe('TestRuleResult', () => { |
|
|
|
|
it('should render without error', () => { |
|
|
|
|
expect(() => render(<TestRuleResult {...props} />)).not.toThrow(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('Life cycle', () => { |
|
|
|
|
describe('component did mount', () => { |
|
|
|
|
it('should call testRule', () => { |
|
|
|
|
const { instance } = setup(); |
|
|
|
|
instance.testRule = jest.fn(); |
|
|
|
|
instance.componentDidMount(); |
|
|
|
|
it('should call testRule when mounting', () => { |
|
|
|
|
jest.spyOn(TestRuleResult.prototype, 'testRule'); |
|
|
|
|
render(<TestRuleResult {...props} />); |
|
|
|
|
|
|
|
|
|
expect(instance.testRule).toHaveBeenCalled(); |
|
|
|
|
}); |
|
|
|
|
expect(TestRuleResult.prototype.testRule).toHaveBeenCalled(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|