2018-01-01 08:39:26 -06:00
|
|
|
import React from 'react';
|
|
|
|
import moment from 'moment';
|
2018-01-01 11:54:23 -06:00
|
|
|
import { AlertRuleList } from './AlertRuleList';
|
2018-01-03 13:11:07 -06:00
|
|
|
import { RootStore } from 'app/stores/RootStore/RootStore';
|
2018-01-01 08:39:26 -06:00
|
|
|
import { backendSrv, createNavTree } from 'test/mocks/common';
|
2018-01-01 11:54:23 -06:00
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import toJson from 'enzyme-to-json';
|
2018-01-01 08:39:26 -06:00
|
|
|
|
|
|
|
describe('AlertRuleList', () => {
|
|
|
|
let page, store;
|
|
|
|
|
2018-01-01 11:54:23 -06:00
|
|
|
beforeAll(() => {
|
2018-01-01 08:39:26 -06:00
|
|
|
backendSrv.get.mockReturnValue(
|
|
|
|
Promise.resolve([
|
|
|
|
{
|
|
|
|
id: 11,
|
|
|
|
dashboardId: 58,
|
|
|
|
panelId: 3,
|
|
|
|
name: 'Panel Title alert',
|
|
|
|
state: 'ok',
|
|
|
|
newStateDate: moment()
|
|
|
|
.subtract(5, 'minutes')
|
|
|
|
.format(),
|
|
|
|
evalData: {},
|
|
|
|
executionError: '',
|
2018-02-05 02:42:41 -06:00
|
|
|
url: 'd/ufkcofof/my-goal',
|
2018-01-30 16:31:02 -06:00
|
|
|
canEdit: true,
|
2018-01-01 08:39:26 -06:00
|
|
|
},
|
|
|
|
])
|
|
|
|
);
|
|
|
|
|
|
|
|
store = RootStore.create(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
backendSrv: backendSrv,
|
|
|
|
navTree: createNavTree('alerting', 'alert-list'),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2018-01-03 13:11:07 -06:00
|
|
|
page = mount(<AlertRuleList {...store} />);
|
2018-01-01 08:39:26 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should call api to get rules', () => {
|
|
|
|
expect(backendSrv.get.mock.calls[0][0]).toEqual('/api/alerts');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render 1 rule', () => {
|
2018-01-01 11:54:23 -06:00
|
|
|
page.update();
|
2018-08-26 10:14:40 -05:00
|
|
|
const ruleNode = page.find('.alert-rule-item');
|
2018-01-01 11:54:23 -06:00
|
|
|
expect(toJson(ruleNode)).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('toggle state should change pause rule if not paused', async () => {
|
|
|
|
backendSrv.post.mockReturnValue(
|
|
|
|
Promise.resolve({
|
|
|
|
state: 'paused',
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
page.find('.fa-pause').simulate('click');
|
|
|
|
|
|
|
|
// wait for api call to resolve
|
|
|
|
await Promise.resolve();
|
|
|
|
page.update();
|
|
|
|
|
|
|
|
expect(store.alertList.rules[0].state).toBe('paused');
|
|
|
|
expect(page.find('.fa-play')).toHaveLength(1);
|
2018-01-01 08:39:26 -06:00
|
|
|
});
|
|
|
|
});
|