Skip to content

Commit

Permalink
R Austin / J Brown review: Add test coverage for selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Brent Kimmel committed May 14, 2020
1 parent 080e112 commit 7e03a25
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
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 });
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ const nodeAssets = {
const getDisplayName: (schemaName: string) => string = function nameInSchemaToDisplayName(
schemaName: string
) {

const displayNameRecord: Record<string, string> = {
application: i18n.translate('xpack.endpoint.resolver.applicationEventTypeDisplayName', {
defaultMessage: 'Application',
Expand Down

0 comments on commit 7e03a25

Please sign in to comment.