some basic selector tests

This commit is contained in:
Peter Holmberg
2018-09-03 16:58:11 +02:00
parent 638370e310
commit f4594c8320
3 changed files with 49 additions and 1 deletions

View File

@@ -2,6 +2,10 @@ import React from 'react';
import { shallow } from 'enzyme';
import AlertRuleItem, { Props } from './AlertRuleItem';
jest.mock('react-redux', () => ({
connect: params => params,
}));
const setup = (propOverrides?: object) => {
const props: Props = {
rule: {
@@ -17,6 +21,7 @@ const setup = (propOverrides?: object) => {
url: 'https://something.something.darkside',
},
search: '',
togglePauseAlertRule: jest.fn(),
};
Object.assign(props, propOverrides);

View File

@@ -0,0 +1,43 @@
import { getSearchQuery, getAlertRuleItems } from './selectors';
import { AlertRulesState } from '../../../types';
const defaultState: AlertRulesState = {
items: [],
searchQuery: '',
};
const getState = (overrides?: object) => Object.assign(defaultState, overrides);
describe('Get search query', () => {
it('should get search query', () => {
const state = getState({ searchQuery: 'dashboard' });
const result = getSearchQuery(state);
expect(result).toEqual(state.searchQuery);
});
});
describe('Get alert rule items', () => {
it('should get alert rule items', () => {
const state = getState({
items: [
{
id: 1,
dashboardId: 1,
panelId: 1,
name: '',
state: '',
stateText: '',
stateIcon: '',
stateClass: '',
stateAge: '',
url: '',
},
],
});
const result = getAlertRuleItems(state);
expect(result.length).toEqual(0);
});
});

View File

@@ -32,8 +32,8 @@ export interface AlertRule {
stateIcon: string;
stateClass: string;
stateAge: string;
info?: string;
url: string;
info?: string;
executionError?: string;
evalData?: { noData: boolean };
}