-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
R Austin / J Brown review: Add test coverage for selectors
- Loading branch information
Brent Kimmel
committed
May 14, 2020
1 parent
080e112
commit 7e03a25
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
x-pack/plugins/endpoint/public/embeddables/resolver/store/data/selectors.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { Store, createStore } from 'redux'; | ||
import { DataAction } from './action'; | ||
import { dataReducer } from './reducer'; | ||
import { DataState, RelatedEventDataEntry, RelatedEventDataEntryWithStats } from '../../types'; | ||
import { ResolverEvent } from '../../../../../common/types'; | ||
import { relatedEventStats, relatedEvents } from './selectors'; | ||
|
||
describe('resolver data selectors', () => { | ||
const store: Store<DataState, DataAction> = createStore(dataReducer, undefined); | ||
describe('when related event data is reduced into state with no results', () => { | ||
const relatedEventInfoBeforeAction = new Map(relatedEvents(store.getState()) || []); | ||
beforeEach(() => { | ||
const payload: Map<ResolverEvent, RelatedEventDataEntry> = new Map(); | ||
const action: DataAction = { type: 'serverReturnedRelatedEventData', payload }; | ||
store.dispatch(action); | ||
}); | ||
it('should have the same related info as before the action', () => { | ||
const relatedInfoAfterAction = relatedEvents(store.getState()); | ||
expect(relatedInfoAfterAction).toEqual(relatedEventInfoBeforeAction); | ||
}); | ||
}); | ||
describe('when related event data is reduced into state with 2 dns results', () => { | ||
const mockBaseEvent = {} as ResolverEvent; | ||
beforeEach(() => { | ||
function dnsRelatedEventEntry() { | ||
const fakeEvent = {} as ResolverEvent; | ||
return { relatedEvent: fakeEvent, relatedEventType: 'dns' }; | ||
} | ||
const payload: Map<ResolverEvent, RelatedEventDataEntry> = new Map([ | ||
[ | ||
mockBaseEvent, | ||
{ | ||
relatedEvents: [dnsRelatedEventEntry(), dnsRelatedEventEntry()], | ||
}, | ||
], | ||
]); | ||
const action: DataAction = { type: 'serverReturnedRelatedEventData', payload }; | ||
store.dispatch(action); | ||
}); | ||
it('should compile stats reflecting a count of 2 for dns', () => { | ||
const actualStats = relatedEventStats(store.getState()); | ||
const statsForFakeEvent = actualStats.get(mockBaseEvent)! as RelatedEventDataEntryWithStats; | ||
expect(statsForFakeEvent.stats).toEqual({ dns: 2 }); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters