Skip to content

Commit

Permalink
Test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomThomson committed Aug 20, 2020
1 parent 1d5b123 commit f497244
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,27 @@ export class AttributeService<
ValType extends EmbeddableInput & { attributes: SavedObjectAttributes },
RefType extends SavedObjectEmbeddableInput
> {
private embeddableFactory: EmbeddableFactory;
private embeddableFactory?: EmbeddableFactory;

constructor(
private type: string,
private savedObjectsClient: SavedObjectsClientContract,
private overlays: OverlayStart,
private i18nContext: I18nStart['Context'],
private toasts: NotificationsStart['toasts'],
getEmbeddableFactory: EmbeddableStart['getEmbeddableFactory'],
getEmbeddableFactory?: EmbeddableStart['getEmbeddableFactory'],
private customSaveMethod?: (
attributes: SavedObjectAttributes,
savedObjectId?: string
) => Promise<{ id: string }>
) {
const factory = getEmbeddableFactory(this.type);
if (!factory) {
throw new EmbeddableFactoryNotFoundError(this.type);
if (getEmbeddableFactory) {
const factory = getEmbeddableFactory(this.type);
if (!factory) {
throw new EmbeddableFactoryNotFoundError(this.type);
}
this.embeddableFactory = factory;
}
this.embeddableFactory = factory;
}

public async unwrapAttributes(input: RefType | ValType): Promise<SavedObjectAttributes> {
Expand Down Expand Up @@ -165,7 +167,7 @@ export class AttributeService<
copyOnSave: false,
lastSavedTitle: '',
getEsType: () => this.type,
getDisplayName: this.embeddableFactory.getDisplayName,
getDisplayName: this.embeddableFactory?.getDisplayName || (() => this.type),
},
props.isTitleDuplicateConfirmed,
props.onTitleDuplicate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,7 @@ const attributeServiceMockFromSavedVis = (
LensSavedObjectAttributes,
LensByValueInput,
LensByReferenceInput
>(
'lens',
core.savedObjects.client,
core.overlays,
core.i18n.Context,
core.notifications.toasts,
jest.fn()
);
>('lens', core.savedObjects.client, core.overlays, core.i18n.Context, core.notifications.toasts);
service.unwrapAttributes = jest.fn((input: LensByValueInput | LensByReferenceInput) => {
return Promise.resolve({ ...document } as LensSavedObjectAttributes);
});
Expand Down

0 comments on commit f497244

Please sign in to comment.