From 5ac5a08e9e9b21ac711bcb2095fa9d10afb80119 Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Tue, 4 Sep 2018 09:53:24 +0200 Subject: [PATCH] Fixed a bug in the test and added test for filter alert rules --- .../features/alerting/state/selectors.test.ts | 75 ++++++++++++++++--- 1 file changed, 63 insertions(+), 12 deletions(-) diff --git a/public/app/features/alerting/state/selectors.test.ts b/public/app/features/alerting/state/selectors.test.ts index 2d6d48caa2d..e853b146c03 100644 --- a/public/app/features/alerting/state/selectors.test.ts +++ b/public/app/features/alerting/state/selectors.test.ts @@ -1,16 +1,8 @@ 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 state = { searchQuery: 'dashboard' }; const result = getSearchQuery(state); expect(result).toEqual(state.searchQuery); @@ -19,7 +11,7 @@ describe('Get search query', () => { describe('Get alert rule items', () => { it('should get alert rule items', () => { - const state = getState({ + const state = { items: [ { id: 1, @@ -34,10 +26,69 @@ describe('Get alert rule items', () => { url: '', }, ], - }); + searchQuery: '', + }; const result = getAlertRuleItems(state); + expect(result.length).toEqual(1); + }); - expect(result.length).toEqual(0); + it('should filter rule items based on search query', () => { + const state = { + items: [ + { + id: 1, + dashboardId: 1, + panelId: 1, + name: 'dashboard', + state: '', + stateText: '', + stateIcon: '', + stateClass: '', + stateAge: '', + url: '', + }, + { + id: 2, + dashboardId: 3, + panelId: 1, + name: 'dashboard2', + state: '', + stateText: '', + stateIcon: '', + stateClass: '', + stateAge: '', + url: '', + }, + { + id: 3, + dashboardId: 5, + panelId: 1, + name: 'hello', + state: '', + stateText: '', + stateIcon: '', + stateClass: '', + stateAge: '', + url: '', + }, + { + id: 4, + dashboardId: 7, + panelId: 1, + name: 'test', + state: '', + stateText: 'dashboard', + stateIcon: '', + stateClass: '', + stateAge: '', + url: '', + }, + ], + searchQuery: 'dashboard', + }; + + const result = getAlertRuleItems(state); + expect(result.length).toEqual(3); }); });