* initial draft * move components to their own files * create services folder and move tags package * add assignment service * fix some types * prepare assign tag route * move server-side tag client under the `services` folder * add security check, move a lot of stuff. * design improvements * display tags in flyout * improve button and add notification on save * add action on tag rows * fix types * fix mock import paths * add lens to the list of assignable types * update generated doc * add base functional tests * move api to internal * add api/security test suites * add / use get_assignable_types API * fix feature control tests * fix assignable types propagation * rename actions folder to bulk_actions * extract actions to their own module * add common / server unit tests * add client-side assign tests * add some tests and tsdoc * typo * add getActions test * revert width change * fix typo in API * various minor improvements * typo * tsdoc on flyout page object * close flyout when leaving the page * fix bug when redirecting to SO management with a tag having whitespaces in its name * check for dupes in toAdd and toRemove * add lazy load to assign modal opener * add lazy load to edit/create modals * check if at least one assign or unassign tag id is specified * grammar * add explicit type existence check
111 lines
4.2 KiB
TypeScript
111 lines
4.2 KiB
TypeScript
/*
|
|
* 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 moment from 'moment';
|
|
import { PublicMethodsOf } from '@kbn/utility-types';
|
|
import { coreMock } from '../../../../src/core/public/mocks';
|
|
import { managementPluginMock } from '../../../../src/plugins/management/public/mocks';
|
|
import { savedObjectTaggingOssPluginMock } from '../../../../src/plugins/saved_objects_tagging_oss/public/mocks';
|
|
import { SavedObjectTaggingPlugin } from './plugin';
|
|
import { SavedObjectsTaggingClientConfigRawType } from './config';
|
|
import { TagsCache } from './services';
|
|
import { tagsCacheMock } from './services/tags/tags_cache.mock';
|
|
|
|
jest.mock('./services/tags/tags_cache');
|
|
const MockedTagsCache = (TagsCache as unknown) as jest.Mock<PublicMethodsOf<TagsCache>>;
|
|
|
|
describe('SavedObjectTaggingPlugin', () => {
|
|
let plugin: SavedObjectTaggingPlugin;
|
|
let managementPluginSetup: ReturnType<typeof managementPluginMock.createSetupContract>;
|
|
let savedObjectsTaggingOssPluginSetup: ReturnType<
|
|
typeof savedObjectTaggingOssPluginMock.createSetup
|
|
>;
|
|
|
|
beforeEach(() => {
|
|
const rawConfig: SavedObjectsTaggingClientConfigRawType = {
|
|
cache_refresh_interval: moment.duration('15', 'minute').toString(),
|
|
};
|
|
const initializerContext = coreMock.createPluginInitializerContext(rawConfig);
|
|
|
|
plugin = new SavedObjectTaggingPlugin(initializerContext);
|
|
});
|
|
|
|
describe('#setup', () => {
|
|
beforeEach(() => {
|
|
managementPluginSetup = managementPluginMock.createSetupContract();
|
|
savedObjectsTaggingOssPluginSetup = savedObjectTaggingOssPluginMock.createSetup();
|
|
|
|
plugin.setup(coreMock.createSetup(), {
|
|
management: managementPluginSetup,
|
|
savedObjectsTaggingOss: savedObjectsTaggingOssPluginSetup,
|
|
});
|
|
});
|
|
|
|
it('register the `tags` app to the `kibana` management section', () => {
|
|
expect(managementPluginSetup.sections.section.kibana.registerApp).toHaveBeenCalledTimes(1);
|
|
expect(managementPluginSetup.sections.section.kibana.registerApp).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
id: 'tags',
|
|
title: 'Tags',
|
|
mount: expect.any(Function),
|
|
})
|
|
);
|
|
});
|
|
it('register its API app to the `savedObjectsTaggingOss` plugin', () => {
|
|
expect(savedObjectsTaggingOssPluginSetup.registerTaggingApi).toHaveBeenCalledTimes(1);
|
|
expect(savedObjectsTaggingOssPluginSetup.registerTaggingApi).toHaveBeenCalledWith(
|
|
expect.any(Promise)
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('#start', () => {
|
|
beforeEach(() => {
|
|
managementPluginSetup = managementPluginMock.createSetupContract();
|
|
savedObjectsTaggingOssPluginSetup = savedObjectTaggingOssPluginMock.createSetup();
|
|
MockedTagsCache.mockImplementation(() => tagsCacheMock.create());
|
|
|
|
plugin.setup(coreMock.createSetup(), {
|
|
management: managementPluginSetup,
|
|
savedObjectsTaggingOss: savedObjectsTaggingOssPluginSetup,
|
|
});
|
|
});
|
|
|
|
it('creates its cache with correct parameters', () => {
|
|
plugin.start(coreMock.createStart());
|
|
|
|
expect(MockedTagsCache).toHaveBeenCalledTimes(1);
|
|
expect(MockedTagsCache).toHaveBeenCalledWith({
|
|
refreshHandler: expect.any(Function),
|
|
refreshInterval: expect.any(Object),
|
|
});
|
|
|
|
const refreshIntervalParam = MockedTagsCache.mock.calls[0][0].refreshInterval;
|
|
|
|
expect(moment.isDuration(refreshIntervalParam)).toBe(true);
|
|
expect(refreshIntervalParam.toString()).toBe('PT15M');
|
|
});
|
|
|
|
it('initializes its cache if not on an anonymous page', async () => {
|
|
const coreStart = coreMock.createStart();
|
|
coreStart.http.anonymousPaths.isAnonymous.mockReturnValue(false);
|
|
|
|
plugin.start(coreStart);
|
|
|
|
expect(MockedTagsCache.mock.instances[0].initialize).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('does not initialize its cache if on an anonymous page', async () => {
|
|
const coreStart = coreMock.createStart();
|
|
coreStart.http.anonymousPaths.isAnonymous.mockReturnValue(true);
|
|
|
|
plugin.start(coreStart);
|
|
|
|
expect(MockedTagsCache.mock.instances[0].initialize).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|