Skip to content

Commit

Permalink
Fixing typescript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Maja Grubic committed Oct 1, 2020
1 parent 4911fad commit 9c965b5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/plugins/visualizations/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const createInstance = async () => {
embeddable: embeddablePluginMock.createStartContract(),
dashboard: dashboardPluginMock.createStartContract(),
getAttributeService: jest.fn(),
savedObjectsClient: coreMock.createStart().savedObjects.client,
});

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { IBasePath } from '../../../../../../src/core/public';
import { AttributeService } from '../../../../../../src/plugins/dashboard/public';
import { Ast } from '@kbn/interpreter/common';
import { LensAttributeService } from '../../lens_attribute_service';
import { OnSaveProps } from '../../../../../../src/plugins/saved_objects/public/save_modal';

jest.mock('../../../../../../src/plugins/inspector/public/', () => ({
isAvailable: false,
Expand All @@ -45,21 +46,38 @@ const savedVis: Document = {
title: 'My title',
visualizationType: '',
};
const defaultSaveMethod = (
type: string,
testAttributes: LensSavedObjectAttributes,
savedObjectId?: string
): Promise<{ id: string }> => {
return new Promise(() => {
return { id: '123' };
});
};
const defaultUnwrapMethod = (savedObjectId: string): Promise<LensSavedObjectAttributes> => {
return new Promise(() => {
return { ...savedVis };
});
};
const defaultCheckForDuplicateTitle = (props: OnSaveProps): Promise<true> => {
return new Promise(() => {
return true;
});
};
const options = {
saveMethod: defaultSaveMethod,
unwrapMethod: defaultUnwrapMethod,
checkForDuplicateTitle: defaultCheckForDuplicateTitle,
};

const attributeServiceMockFromSavedVis = (document: Document): LensAttributeService => {
const core = coreMock.createStart();
const service = new AttributeService<
LensSavedObjectAttributes,
LensByValueInput,
LensByReferenceInput
>(
'lens',
jest.fn(),
core.savedObjects.client,
core.overlays,
core.i18n.Context,
core.notifications.toasts
);
>('lens', jest.fn(), core.i18n.Context, core.notifications.toasts, options);
service.unwrapAttributes = jest.fn((input: LensByValueInput | LensByReferenceInput) => {
return Promise.resolve({ ...document } as LensSavedObjectAttributes);
});
Expand Down
5 changes: 2 additions & 3 deletions x-pack/plugins/lens/public/lens_attribute_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
LensByReferenceInput,
} from './editor_frame_service/embeddable/embeddable';
import { SavedObjectIndexStore, DOC_TYPE } from './persistence';
import { SavedObjectAttributes } from '../../../../src/core/target/types/saved_objects';
import { checkForDuplicateTitle, OnSaveProps } from '../../../../src/plugins/saved_objects/public';

export type LensAttributeService = AttributeService<
Expand Down Expand Up @@ -44,8 +43,8 @@ export function getLensAttributeService(
});
return { id: savedDoc.savedObjectId };
},
unwrapMethod: async (savedObjectId: string) => {
const savedObject = await core.savedObjects.client.get<SavedObjectAttributes>(
unwrapMethod: async (savedObjectId: string): Promise<LensSavedObjectAttributes> => {
const savedObject = await core.savedObjects.client.get<LensSavedObjectAttributes>(
DOC_TYPE,
savedObjectId
);
Expand Down

0 comments on commit 9c965b5

Please sign in to comment.