From 5de1b21abf4fcae87f2b8a23b7f3e23b7ef73638 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Fri, 5 Jun 2020 08:26:30 -0500 Subject: [PATCH] fix jest test mock --- .../common/index_patterns/fields/field.test.ts | 6 +----- .../data/common/index_patterns/fields/field.ts | 13 ++++--------- .../common/index_patterns/fields/field_list.ts | 8 ++++---- src/plugins/data/common/index_patterns/index.ts | 1 + .../index_patterns/_fields_fetcher.ts | 3 ++- .../index_patterns/ensure_default_index_pattern.ts | 14 -------------- .../index_patterns/index_pattern.test.ts | 4 ++-- .../index_patterns/index_patterns/index_pattern.ts | 14 ++------------ 8 files changed, 16 insertions(+), 47 deletions(-) diff --git a/src/plugins/data/common/index_patterns/fields/field.test.ts b/src/plugins/data/common/index_patterns/fields/field.test.ts index 92e1f254229a3..328c85a4e06a9 100644 --- a/src/plugins/data/common/index_patterns/fields/field.test.ts +++ b/src/plugins/data/common/index_patterns/fields/field.test.ts @@ -18,9 +18,7 @@ */ import { Field } from './field'; -import { IndexPattern } from '../index_patterns'; -// import { notificationServiceMock } from '../../../../../core/public/mocks'; -// import { FieldFormatsStart } from '../../field_formats'; +import { IndexPattern } from '..'; import { FieldFormatMethods } from '../types'; import { KBN_FIELD_TYPES } from '../../../common'; @@ -37,7 +35,6 @@ describe('Field', function () { { fieldFormats: {} as FieldFormatMethods, onNotification: () => {}, - // toastNotifications: notificationServiceMock.createStartContract().toasts, } ); } @@ -219,7 +216,6 @@ describe('Field', function () { const field = new Field({ fieldFormatMap: { name: {} } } as IndexPattern, fieldValues, false, { fieldFormats: {} as FieldFormatMethods, onNotification: () => {}, - // toastNotifications: notificationServiceMock.createStartContract().toasts, }); expect(flatten(field)).toMatchSnapshot(); }); diff --git a/src/plugins/data/common/index_patterns/fields/field.ts b/src/plugins/data/common/index_patterns/fields/field.ts index 0a9a83da0fc84..c6e9e567c814f 100644 --- a/src/plugins/data/common/index_patterns/fields/field.ts +++ b/src/plugins/data/common/index_patterns/fields/field.ts @@ -18,10 +18,9 @@ */ import { i18n } from '@kbn/i18n'; -// import { ToastsStart } from 'kibana/public'; // @ts-ignore import { ObjDefine } from './obj_define'; -import { IIndexPattern } from '../../types'; +import { IndexPattern } from '../index_patterns'; import { IFieldType, getKbnFieldType, @@ -55,21 +54,17 @@ export class Field implements IFieldType { scripted?: boolean; subType?: IFieldSubType; displayName?: string; - indexPattern?: IIndexPattern; + indexPattern?: IndexPattern; readFromDocValues?: boolean; format: any; $$spec: FieldSpec; conflictDescriptions?: Record; constructor( - indexPattern: IIndexPattern, + indexPattern: IndexPattern, spec: FieldSpec | Field, shortDotsEnable: boolean, - { - fieldFormats, - onNotification, - }: // toastNotifications - FieldDependencies + { fieldFormats, onNotification }: FieldDependencies ) { // unwrap old instances of Field if (spec instanceof Field) spec = spec.$$spec; diff --git a/src/plugins/data/common/index_patterns/fields/field_list.ts b/src/plugins/data/common/index_patterns/fields/field_list.ts index 5627ec72ac9fd..e8f712d3220c2 100644 --- a/src/plugins/data/common/index_patterns/fields/field_list.ts +++ b/src/plugins/data/common/index_patterns/fields/field_list.ts @@ -18,7 +18,7 @@ */ import { findIndex } from 'lodash'; -import { IIndexPattern } from '../../types'; +import { IndexPattern } from '../index_patterns'; import { IFieldType } from '../../../common'; import { Field, FieldSpec } from './field'; import { FieldFormatMethods, OnNotification } from '../types'; @@ -39,7 +39,7 @@ export interface IIndexPatternFieldList extends Array { } export type CreateIndexPatternFieldList = ( - indexPattern: IIndexPattern, + indexPattern: IndexPattern, specs?: FieldSpec[], shortDotsEnable?: boolean ) => IIndexPatternFieldList; @@ -51,7 +51,7 @@ export const getIndexPatternFieldListCreator = ({ class FieldList extends Array implements IIndexPatternFieldList { private byName: FieldMap = new Map(); private groups: Map = new Map(); - private indexPattern: IIndexPattern; + private indexPattern: IndexPattern; private shortDotsEnable: boolean; private setByName = (field: Field) => this.byName.set(field.name, field); private setByGroup = (field: Field) => { @@ -62,7 +62,7 @@ export const getIndexPatternFieldListCreator = ({ }; private removeByGroup = (field: IFieldType) => this.groups.get(field.type)!.delete(field.name); - constructor(indexPattern: IIndexPattern, specs: FieldSpec[] = [], shortDotsEnable = false) { + constructor(indexPattern: IndexPattern, specs: FieldSpec[] = [], shortDotsEnable = false) { super(); this.indexPattern = indexPattern; this.shortDotsEnable = shortDotsEnable; diff --git a/src/plugins/data/common/index_patterns/index.ts b/src/plugins/data/common/index_patterns/index.ts index d26587efccc0f..4f46f4737ab0f 100644 --- a/src/plugins/data/common/index_patterns/index.ts +++ b/src/plugins/data/common/index_patterns/index.ts @@ -19,3 +19,4 @@ export * from './fields'; export * from './types'; +export * from './index_patterns'; diff --git a/src/plugins/data/common/index_patterns/index_patterns/_fields_fetcher.ts b/src/plugins/data/common/index_patterns/index_patterns/_fields_fetcher.ts index 727c4d445688d..d9850086339c0 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/_fields_fetcher.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/_fields_fetcher.ts @@ -17,7 +17,8 @@ * under the License. */ -import { GetFieldsOptions, IIndexPatternsApiClient, IndexPattern } from '.'; +import { IndexPattern } from './index_pattern'; +import { GetFieldsOptions, IIndexPatternsApiClient } from './index_patterns_api_client'; /** @internal */ export const createFieldsFetcher = ( diff --git a/src/plugins/data/common/index_patterns/index_patterns/ensure_default_index_pattern.ts b/src/plugins/data/common/index_patterns/index_patterns/ensure_default_index_pattern.ts index 4d248b00bc4d1..702812a6f31de 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/ensure_default_index_pattern.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/ensure_default_index_pattern.ts @@ -18,32 +18,18 @@ */ import { contains } from 'lodash'; -// import React from 'react'; -// import { History } from 'history'; -// import { i18n } from '@kbn/i18n'; -// import { EuiCallOut } from '@elastic/eui'; import { CoreStart } from 'kibana/public'; -// import { toMountPoint } from '../../../../kibana_react/public'; import { IndexPatternsContract } from './index_patterns'; -// export type EnsureDefaultIndexPattern = (history: History) => Promise | undefined; - export type EnsureDefaultIndexPattern = () => Promise | undefined; export const createEnsureDefaultIndexPattern = ( core: CoreStart, onRedirectNoIndexPattern: (core: CoreStart) => void ) => { - // let bannerId: string; - // let timeoutId: NodeJS.Timeout | undefined; - /** * Checks whether a default index pattern is set and exists and defines * one otherwise. - * - * If there are no index patterns, redirect to management page and show - * banner. In this case the promise returned from this function will never - * resolve to wait for the URL change to happen. */ return async function ensureDefaultIndexPattern(this: IndexPatternsContract) { const patterns = await this.getIds(); diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts index eb7ba53286614..0471d9087191b 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts @@ -31,8 +31,8 @@ import { Field } from '../fields'; import { FieldFormatMethods } from '../types'; -jest.mock('../../../../kibana_utils/public', () => { - const originalModule = jest.requireActual('../../../../kibana_utils/public'); +jest.mock('../../../../kibana_utils/common', () => { + const originalModule = jest.requireActual('../../../../kibana_utils/common'); return { ...originalModule, diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts index cf313a4e86d19..aa50541fe6678 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts @@ -523,22 +523,10 @@ export class IndexPattern implements IIndexPattern { // const { toasts } = getNotifications(); if (err instanceof IndexPatternMissingIndices) { - // toasts.addDanger((err as any).message); this.onNotification({ title: (err as any).message, color: 'danger' }); return []; } - /* - toasts.addError(err, { - title: i18n.translate('data.indexPatterns.fetchFieldErrorTitle', { - defaultMessage: 'Error fetching fields for index pattern {title} (ID: {id})', - values: { - id: this.id, - title: this.title, - }, - }), - }); - */ this.onNotification({ title: i18n.translate('data.indexPatterns.fetchFieldErrorTitle', { defaultMessage: 'Error fetching fields for index pattern {title} (ID: {id})', @@ -547,6 +535,8 @@ export class IndexPattern implements IIndexPattern { title: this.title, }, }), + // todo + // message: err, color: 'danger', }); // was addError });