forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Discover] Extend EBT context with a list of activated context-aware …
…profiles (elastic#192908) - Closes elastic#186109 ## Summary This PR extends EBT context with `dscProfiles` - a list of active context-aware profiles. <img width="981" alt="Screenshot 2024-09-16 at 17 30 47" src="https://github.com/user-attachments/assets/64d49abc-3ee0-4d5a-8283-cdca5d78f963"> ## Testing Enable "Usage collection" global setting. Navigate to Discover and observe `kibana-browser` requests in Network tab. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <[email protected]> (cherry picked from commit c28af87)
- Loading branch information
Showing
11 changed files
with
361 additions
and
12 deletions.
There are no files selected for viewing
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
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
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
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
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
95 changes: 95 additions & 0 deletions
95
src/plugins/discover/public/services/discover_ebt_context_manager.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,95 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { BehaviorSubject } from 'rxjs'; | ||
import { coreMock } from '@kbn/core/public/mocks'; | ||
import { DiscoverEBTContextManager } from './discover_ebt_context_manager'; | ||
|
||
const coreSetupMock = coreMock.createSetup(); | ||
|
||
describe('DiscoverEBTContextManager', () => { | ||
let discoverEBTContextManager: DiscoverEBTContextManager; | ||
|
||
beforeEach(() => { | ||
discoverEBTContextManager = new DiscoverEBTContextManager(); | ||
}); | ||
|
||
describe('register', () => { | ||
it('should register the context provider', () => { | ||
discoverEBTContextManager.initialize({ core: coreSetupMock }); | ||
|
||
expect(coreSetupMock.analytics.registerContextProvider).toHaveBeenCalledWith({ | ||
name: 'discover_context', | ||
context$: expect.any(BehaviorSubject), | ||
schema: { | ||
discoverProfiles: { | ||
type: 'array', | ||
items: { | ||
type: 'keyword', | ||
_meta: { | ||
description: 'List of active Discover context awareness profiles', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('updateProfilesWith', () => { | ||
it('should update the profiles with the provided props', () => { | ||
const dscProfiles = ['profile1', 'profile2']; | ||
const dscProfiles2 = ['profile21', 'profile22']; | ||
discoverEBTContextManager.initialize({ core: coreSetupMock }); | ||
discoverEBTContextManager.enable(); | ||
|
||
discoverEBTContextManager.updateProfilesContextWith(dscProfiles); | ||
expect(discoverEBTContextManager.getProfilesContext()).toBe(dscProfiles); | ||
|
||
discoverEBTContextManager.updateProfilesContextWith(dscProfiles2); | ||
expect(discoverEBTContextManager.getProfilesContext()).toBe(dscProfiles2); | ||
}); | ||
|
||
it('should not update the profiles if profile list did not change', () => { | ||
const dscProfiles = ['profile1', 'profile2']; | ||
const dscProfiles2 = ['profile1', 'profile2']; | ||
discoverEBTContextManager.initialize({ core: coreSetupMock }); | ||
discoverEBTContextManager.enable(); | ||
|
||
discoverEBTContextManager.updateProfilesContextWith(dscProfiles); | ||
expect(discoverEBTContextManager.getProfilesContext()).toBe(dscProfiles); | ||
|
||
discoverEBTContextManager.updateProfilesContextWith(dscProfiles2); | ||
expect(discoverEBTContextManager.getProfilesContext()).toBe(dscProfiles); | ||
}); | ||
|
||
it('should not update the profiles if not enabled yet', () => { | ||
const dscProfiles = ['profile1', 'profile2']; | ||
discoverEBTContextManager.initialize({ core: coreSetupMock }); | ||
|
||
discoverEBTContextManager.updateProfilesContextWith(dscProfiles); | ||
expect(discoverEBTContextManager.getProfilesContext()).toEqual([]); | ||
}); | ||
|
||
it('should not update the profiles after resetting unless enabled again', () => { | ||
const dscProfiles = ['profile1', 'profile2']; | ||
discoverEBTContextManager.initialize({ core: coreSetupMock }); | ||
discoverEBTContextManager.enable(); | ||
discoverEBTContextManager.updateProfilesContextWith(dscProfiles); | ||
expect(discoverEBTContextManager.getProfilesContext()).toBe(dscProfiles); | ||
discoverEBTContextManager.disableAndReset(); | ||
expect(discoverEBTContextManager.getProfilesContext()).toEqual([]); | ||
discoverEBTContextManager.updateProfilesContextWith(dscProfiles); | ||
expect(discoverEBTContextManager.getProfilesContext()).toEqual([]); | ||
discoverEBTContextManager.enable(); | ||
discoverEBTContextManager.updateProfilesContextWith(dscProfiles); | ||
expect(discoverEBTContextManager.getProfilesContext()).toBe(dscProfiles); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.