From e72123aef40aaa8342644833f470e1fcfdb12293 Mon Sep 17 00:00:00 2001 From: sulemanof Date: Mon, 20 Jan 2020 15:15:01 +0300 Subject: [PATCH 1/2] Move tests in dashboard into appropriate folders --- .../get_embeddable_factories_mock.ts | 26 -------------- .../dashboard/__tests__/saved_dashboards.js | 36 ------------------- .../kibana/public/dashboard/legacy_imports.ts | 1 + .../dashboard_empty_screen.test.tsx.snap | 0 .../dashboard_empty_screen.test.tsx | 5 +-- .../np_ready/dashboard_state.test.ts | 2 +- .../test_utils}/get_app_state_mock.ts | 2 +- .../test_utils}/get_saved_dashboard_mock.ts | 4 +-- .../test_utils}/index.ts | 1 - .../url_helper.test.ts | 2 +- 10 files changed, 7 insertions(+), 72 deletions(-) delete mode 100644 src/legacy/core_plugins/kibana/public/dashboard/__tests__/get_embeddable_factories_mock.ts delete mode 100644 src/legacy/core_plugins/kibana/public/dashboard/__tests__/saved_dashboards.js rename src/legacy/core_plugins/kibana/public/dashboard/{__tests__ => np_ready}/__snapshots__/dashboard_empty_screen.test.tsx.snap (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{__tests__ => np_ready}/dashboard_empty_screen.test.tsx (96%) rename src/legacy/core_plugins/kibana/public/dashboard/{__tests__ => np_ready/test_utils}/get_app_state_mock.ts (96%) rename src/legacy/core_plugins/kibana/public/dashboard/{__tests__ => np_ready/test_utils}/get_saved_dashboard_mock.ts (90%) rename src/legacy/core_plugins/kibana/public/dashboard/{__tests__ => np_ready/test_utils}/index.ts (92%) rename src/legacy/core_plugins/kibana/public/dashboard/{__tests__ => np_ready}/url_helper.test.ts (99%) diff --git a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/get_embeddable_factories_mock.ts b/src/legacy/core_plugins/kibana/public/dashboard/__tests__/get_embeddable_factories_mock.ts deleted file mode 100644 index 357ab307c3f12..0000000000000 --- a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/get_embeddable_factories_mock.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/* global jest */ -export function getEmbeddableFactoryMock(config?: any) { - const embeddableFactoryMockDefaults = { - create: jest.fn(() => Promise.resolve({})), - }; - return Object.assign(embeddableFactoryMockDefaults, config); -} diff --git a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/saved_dashboards.js b/src/legacy/core_plugins/kibana/public/dashboard/__tests__/saved_dashboards.js deleted file mode 100644 index b387467189385..0000000000000 --- a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/saved_dashboards.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import ngMock from 'ng_mock'; -import expect from '@kbn/expect'; - -describe('SavedDashboards Service', function() { - let savedDashboardLoader; - - beforeEach(ngMock.module('kibana')); - beforeEach( - ngMock.inject(function(savedDashboards) { - savedDashboardLoader = savedDashboards; - }) - ); - - it('delete returns a native promise', function() { - expect(savedDashboardLoader.delete(['1', '2'])).to.be.a(Promise); - }); -}); diff --git a/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts b/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts index b44d1993db23a..021dbfc2e60a8 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts @@ -68,3 +68,4 @@ export { SavedObjectLoader } from 'ui/saved_objects'; export { VISUALIZE_EMBEDDABLE_TYPE } from '../../../visualizations/public/embeddable'; export { registerTimefilterWithGlobalStateFactory } from 'ui/timefilter/setup_router'; export { absoluteToParsedUrl } from 'ui/url/absolute_to_parsed_url'; +export { searchSourceMock } from 'ui/courier/search_source/mocks'; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/__snapshots__/dashboard_empty_screen.test.tsx.snap b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/__snapshots__/dashboard_empty_screen.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/dashboard/__tests__/__snapshots__/dashboard_empty_screen.test.tsx.snap rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/__snapshots__/dashboard_empty_screen.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/dashboard_empty_screen.test.tsx b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_empty_screen.test.tsx similarity index 96% rename from src/legacy/core_plugins/kibana/public/dashboard/__tests__/dashboard_empty_screen.test.tsx rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_empty_screen.test.tsx index 347502c2560ab..d5e22798b4f24 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/dashboard_empty_screen.test.tsx +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_empty_screen.test.tsx @@ -18,10 +18,7 @@ */ import React from 'react'; import { mountWithIntl } from 'test_utils/enzyme_helpers'; -import { - DashboardEmptyScreen, - DashboardEmptyScreenProps, -} from '../np_ready/dashboard_empty_screen'; +import { DashboardEmptyScreen, DashboardEmptyScreenProps } from './dashboard_empty_screen'; // @ts-ignore import { findTestSubject } from '@elastic/eui/lib/test'; import { coreMock } from '../../../../../../core/public/mocks'; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_state.test.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_state.test.ts index d9a93b2ceedc3..9ba73d076d5e3 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_state.test.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_state.test.ts @@ -19,7 +19,7 @@ import './np_core.test.mocks'; import { DashboardStateManager } from './dashboard_state_manager'; -import { getAppStateMock, getSavedDashboardMock } from '../__tests__'; +import { getAppStateMock, getSavedDashboardMock } from './test_utils'; import { AppStateClass } from '../legacy_imports'; import { DashboardAppState } from './types'; import { TimeRange, TimefilterContract, InputTimeRange } from 'src/plugins/data/public'; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/get_app_state_mock.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/test_utils/get_app_state_mock.ts similarity index 96% rename from src/legacy/core_plugins/kibana/public/dashboard/__tests__/get_app_state_mock.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/test_utils/get_app_state_mock.ts index d9dea35a8a1c0..e238a3ab7ff55 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/get_app_state_mock.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/test_utils/get_app_state_mock.ts @@ -17,7 +17,7 @@ * under the License. */ -import { AppStateClass } from '../legacy_imports'; +import { AppStateClass } from '../../legacy_imports'; /** * A poor excuse for a mock just to get some basic tests to run in jest without requiring the injector. diff --git a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/get_saved_dashboard_mock.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/test_utils/get_saved_dashboard_mock.ts similarity index 90% rename from src/legacy/core_plugins/kibana/public/dashboard/__tests__/get_saved_dashboard_mock.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/test_utils/get_saved_dashboard_mock.ts index 1c2405b5824f2..6bb9ef9a178fe 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/get_saved_dashboard_mock.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/test_utils/get_saved_dashboard_mock.ts @@ -17,8 +17,8 @@ * under the License. */ -import { searchSourceMock } from 'ui/courier/search_source/mocks'; -import { SavedObjectDashboard } from '../saved_dashboard/saved_dashboard'; +import { searchSourceMock } from '../../legacy_imports'; +import { SavedObjectDashboard } from '../../saved_dashboard/saved_dashboard'; export function getSavedDashboardMock( config?: Partial diff --git a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/index.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/test_utils/index.ts similarity index 92% rename from src/legacy/core_plugins/kibana/public/dashboard/__tests__/index.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/test_utils/index.ts index ab8dfe81163e4..04a6d417b0030 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/index.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/test_utils/index.ts @@ -19,4 +19,3 @@ export { getAppStateMock } from './get_app_state_mock'; export { getSavedDashboardMock } from './get_saved_dashboard_mock'; -export { getEmbeddableFactoryMock } from './get_embeddable_factories_mock'; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/url_helper.test.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/url_helper.test.ts similarity index 99% rename from src/legacy/core_plugins/kibana/public/dashboard/__tests__/url_helper.test.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/url_helper.test.ts index df2dbfd54c130..60ca1b39d29d6 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/url_helper.test.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/url_helper.test.ts @@ -47,7 +47,7 @@ import { addEmbeddableToDashboardUrl, getLensUrlFromDashboardAbsoluteUrl, getUrlVars, -} from '../np_ready/url_helper'; +} from './url_helper'; describe('Dashboard URL Helper', () => { beforeEach(() => { From 5bc4cc23dbdf432b6a58630d79fa75f4754bd4a7 Mon Sep 17 00:00:00 2001 From: sulemanof Date: Tue, 28 Jan 2020 11:56:03 +0300 Subject: [PATCH 2/2] Remove unused imports --- .../core_plugins/kibana/public/dashboard/legacy_imports.ts | 1 - .../kibana/public/dashboard/np_ready/dashboard_state.test.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts b/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts index 1903535e88a6a..97d165b6b5c23 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts @@ -61,4 +61,3 @@ export { SavedObjectLoader } from 'ui/saved_objects'; export { VISUALIZE_EMBEDDABLE_TYPE } from '../../../visualizations/public/embeddable'; export { registerTimefilterWithGlobalStateFactory } from 'ui/timefilter/setup_router'; export { absoluteToParsedUrl } from 'ui/url/absolute_to_parsed_url'; -export { searchSourceMock } from 'ui/courier/search_source/mocks'; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_state.test.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_state.test.ts index a67894d496f2a..60ea14dad19e1 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_state.test.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_state.test.ts @@ -20,7 +20,6 @@ import './np_core.test.mocks'; import { createBrowserHistory } from 'history'; import { DashboardStateManager } from './dashboard_state_manager'; -import { DashboardAppState } from './types'; import { getSavedDashboardMock } from './test_utils'; import { InputTimeRange, TimefilterContract, TimeRange } from 'src/plugins/data/public'; import { ViewMode } from 'src/plugins/embeddable/public';