|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | + |
| 7 | +import { cloneDeep } from 'lodash/fp'; |
| 8 | +import { mockGlobalState } from '../../mock'; |
| 9 | +import { SourcererScopeName } from './model'; |
| 10 | +import { getSourcererScopeSelector } from './selectors'; |
| 11 | + |
| 12 | +describe('Sourcerer selectors', () => { |
| 13 | + describe('getSourcererScopeSelector', () => { |
| 14 | + it('Should exclude elastic cloud alias when selected patterns include "logs-*" as an alias', () => { |
| 15 | + const mapStateToProps = getSourcererScopeSelector(); |
| 16 | + expect( |
| 17 | + mapStateToProps(mockGlobalState, SourcererScopeName.default).selectedPatterns |
| 18 | + ).toEqual([ |
| 19 | + 'apm-*-transaction*', |
| 20 | + 'auditbeat-*', |
| 21 | + 'endgame-*', |
| 22 | + 'filebeat-*', |
| 23 | + 'logs-*', |
| 24 | + 'packetbeat-*', |
| 25 | + 'winlogbeat-*', |
| 26 | + '-*elastic-cloud-logs-*', |
| 27 | + ]); |
| 28 | + }); |
| 29 | + |
| 30 | + it('Should NOT exclude elastic cloud alias when selected patterns does NOT include "logs-*" as an alias', () => { |
| 31 | + const mapStateToProps = getSourcererScopeSelector(); |
| 32 | + const myMockGlobalState = cloneDeep(mockGlobalState); |
| 33 | + myMockGlobalState.sourcerer.sourcererScopes.default.selectedPatterns = myMockGlobalState.sourcerer.sourcererScopes.default.selectedPatterns.filter( |
| 34 | + (index) => !index.includes('logs-*') |
| 35 | + ); |
| 36 | + expect( |
| 37 | + mapStateToProps(myMockGlobalState, SourcererScopeName.default).selectedPatterns |
| 38 | + ).toEqual([ |
| 39 | + 'apm-*-transaction*', |
| 40 | + 'auditbeat-*', |
| 41 | + 'endgame-*', |
| 42 | + 'filebeat-*', |
| 43 | + 'packetbeat-*', |
| 44 | + 'winlogbeat-*', |
| 45 | + ]); |
| 46 | + }); |
| 47 | + |
| 48 | + it('Should NOT exclude elastic cloud alias when selected patterns include "logs-endpoint.event-*" as an alias', () => { |
| 49 | + const mapStateToProps = getSourcererScopeSelector(); |
| 50 | + const myMockGlobalState = cloneDeep(mockGlobalState); |
| 51 | + myMockGlobalState.sourcerer.sourcererScopes.default.selectedPatterns = [ |
| 52 | + ...myMockGlobalState.sourcerer.sourcererScopes.default.selectedPatterns.filter( |
| 53 | + (index) => !index.includes('logs-*') |
| 54 | + ), |
| 55 | + 'logs-endpoint.event-*', |
| 56 | + ]; |
| 57 | + expect( |
| 58 | + mapStateToProps(myMockGlobalState, SourcererScopeName.default).selectedPatterns |
| 59 | + ).toEqual([ |
| 60 | + 'apm-*-transaction*', |
| 61 | + 'auditbeat-*', |
| 62 | + 'endgame-*', |
| 63 | + 'filebeat-*', |
| 64 | + 'packetbeat-*', |
| 65 | + 'winlogbeat-*', |
| 66 | + 'logs-endpoint.event-*', |
| 67 | + ]); |
| 68 | + }); |
| 69 | + }); |
| 70 | +}); |
0 commit comments