Skip to content

Commit

Permalink
adapt SavedObjectsManagement to use the registry
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Mar 6, 2020
1 parent b504359 commit 579c3ca
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 175 deletions.
2 changes: 1 addition & 1 deletion src/core/server/saved_objects/management/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export { SavedObjectsManagement, SavedObjectsManagementDefinition } from './management';
export { SavedObjectsManagement } from './management';
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const createManagementMock = () => {
const mocked: jest.Mocked<Management> = {
isImportAndExportable: jest.fn().mockReturnValue(true),
getDefaultSearchField: jest.fn(),
getImportableAndExportableTypes: jest.fn(),
getIcon: jest.fn(),
getTitle: jest.fn(),
getEditUrl: jest.fn(),
Expand Down
268 changes: 148 additions & 120 deletions src/core/server/saved_objects/management/management.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,157 +18,185 @@
*/

import { SavedObjectsManagement } from './management';
import { SavedObjectsType } from '../types';
import { SavedObjectTypeRegistry } from '../saved_objects_type_registry';

describe('isImportAndExportable()', () => {
it('returns false for unknown types', () => {
const management = new SavedObjectsManagement();
const result = management.isImportAndExportable('bar');
expect(result).toBe(false);
});
describe('SavedObjectsManagement', () => {
let registry: SavedObjectTypeRegistry;
let management: SavedObjectsManagement;

it('returns true for explicitly importable and exportable type', () => {
const management = new SavedObjectsManagement({
foo: {
isImportableAndExportable: true,
},
const registerType = (type: Partial<SavedObjectsType>) =>
registry.registerType({
name: 'unknown',
hidden: false,
namespaceAgnostic: false,
mappings: { properties: {} },
migrations: {},
...type,
});
const result = management.isImportAndExportable('foo');
expect(result).toBe(true);

beforeEach(() => {
registry = new SavedObjectTypeRegistry();
management = new SavedObjectsManagement(registry);
});

it('returns false for explicitly importable and exportable type', () => {
const management = new SavedObjectsManagement({
foo: {
isImportableAndExportable: false,
},
describe('isImportAndExportable()', () => {
it('returns false for unknown types', () => {
const result = management.isImportAndExportable('bar');
expect(result).toBe(false);
});
const result = management.isImportAndExportable('foo');
expect(result).toBe(false);
});
});

describe('getDefaultSearchField()', () => {
it('returns empty for unknown types', () => {
const management = new SavedObjectsManagement();
const result = management.getDefaultSearchField('bar');
expect(result).toEqual(undefined);
});
it('returns true for explicitly importable and exportable type', () => {
registerType({
name: 'foo',
management: {
importableAndExportable: true,
},
});

it('returns explicit value', () => {
const management = new SavedObjectsManagement({
foo: {
defaultSearchField: 'value',
},
const result = management.isImportAndExportable('foo');
expect(result).toBe(true);
});
const result = management.getDefaultSearchField('foo');
expect(result).toEqual('value');
});
});

describe('getIcon', () => {
it('returns empty for unknown types', () => {
const management = new SavedObjectsManagement();
const result = management.getIcon('bar');
expect(result).toEqual(undefined);
});
it('returns false for explicitly importable and exportable type', () => {
registerType({
name: 'foo',
management: {
importableAndExportable: false,
},
});

it('returns explicit value', () => {
const management = new SavedObjectsManagement({
foo: {
icon: 'value',
},
const result = management.isImportAndExportable('foo');
expect(result).toBe(false);
});
const result = management.getIcon('foo');
expect(result).toEqual('value');
});
});

describe('getTitle', () => {
it('returns empty for unknown type', () => {
const management = new SavedObjectsManagement();
const result = management.getTitle({
id: '1',
type: 'foo',
attributes: {},
references: [],
describe('getDefaultSearchField()', () => {
it('returns empty for unknown types', () => {
const result = management.getDefaultSearchField('bar');
expect(result).toEqual(undefined);
});
expect(result).toEqual(undefined);
});

it('returns explicit value', () => {
const management = new SavedObjectsManagement({
foo: {
getTitle() {
return 'called';
it('returns explicit value', () => {
registerType({
name: 'foo',
management: {
defaultSearchField: 'value',
},
},
});
const result = management.getTitle({
id: '1',
type: 'foo',
attributes: {},
references: [],
});

const result = management.getDefaultSearchField('foo');
expect(result).toEqual('value');
});
expect(result).toEqual('called');
});
});

describe('getEditUrl()', () => {
it('returns empty for unknown type', () => {
const management = new SavedObjectsManagement();
const result = management.getEditUrl({
id: '1',
type: 'foo',
attributes: {},
references: [],
describe('getIcon()', () => {
it('returns empty for unknown types', () => {
const result = management.getIcon('bar');
expect(result).toEqual(undefined);
});
expect(result).toEqual(undefined);
});

it('returns explicit value', () => {
const management = new SavedObjectsManagement({
foo: {
getEditUrl() {
return 'called';
it('returns explicit value', () => {
registerType({
name: 'foo',
management: {
icon: 'value',
},
},
});
const result = management.getEditUrl({
id: '1',
type: 'foo',
attributes: {},
references: [],
});
const result = management.getIcon('foo');
expect(result).toEqual('value');
});
expect(result).toEqual('called');
});
});

describe('getInAppUrl()', () => {
it('returns empty array for unknown type', () => {
const management = new SavedObjectsManagement();
const result = management.getInAppUrl({
id: '1',
type: 'foo',
attributes: {},
references: [],
describe('getTitle()', () => {
it('returns empty for unknown type', () => {
const result = management.getTitle({
id: '1',
type: 'foo',
attributes: {},
references: [],
});
expect(result).toEqual(undefined);
});

it('returns explicit value', () => {
registerType({
name: 'foo',
management: {
getTitle() {
return 'called';
},
},
});
const result = management.getTitle({
id: '1',
type: 'foo',
attributes: {},
references: [],
});
expect(result).toEqual('called');
});
expect(result).toEqual(undefined);
});

it('returns explicit value', () => {
const management = new SavedObjectsManagement({
foo: {
getInAppUrl() {
return { path: 'called', uiCapabilitiesPath: 'my.path' };
describe('getEditUrl()', () => {
it('returns empty for unknown type', () => {
const result = management.getEditUrl({
id: '1',
type: 'foo',
attributes: {},
references: [],
});
expect(result).toEqual(undefined);
});

it('returns explicit value', () => {
registerType({
name: 'foo',
management: {
getEditUrl() {
return 'called';
},
},
},
});

const result = management.getEditUrl({
id: '1',
type: 'foo',
attributes: {},
references: [],
});
expect(result).toEqual('called');
});
});

describe('getInAppUrl()', () => {
it('returns empty array for unknown type', () => {
const result = management.getInAppUrl({
id: '1',
type: 'foo',
attributes: {},
references: [],
});
expect(result).toEqual(undefined);
});
const result = management.getInAppUrl({
id: '1',
type: 'foo',
attributes: {},
references: [],

it('returns explicit value', () => {
registerType({
name: 'foo',
management: {
getInAppUrl() {
return { path: 'called', uiCapabilitiesPath: 'my.path' };
},
},
});

const result = management.getInAppUrl({
id: '1',
type: 'foo',
attributes: {},
references: [],
});
expect(result).toEqual({ path: 'called', uiCapabilitiesPath: 'my.path' });
});
expect(result).toEqual({ path: 'called', uiCapabilitiesPath: 'my.path' });
});
});
Loading

0 comments on commit 579c3ca

Please sign in to comment.