diff --git a/src/core/public/legacy_platform/__snapshots__/legacy_platform_service.test.ts.snap b/src/core/public/legacy_platform/__snapshots__/legacy_platform_service.test.ts.snap
index e012b43d5977a..8d318e8e57673 100644
--- a/src/core/public/legacy_platform/__snapshots__/legacy_platform_service.test.ts.snap
+++ b/src/core/public/legacy_platform/__snapshots__/legacy_platform_service.test.ts.snap
@@ -1,5 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`#start() load order useLegacyTestHarness = false loads ui/modules before ui/chrome, and both before legacy files 1`] = `
+Array [
+ "ui/metadata",
+ "ui/notify/fatal_error",
+ "ui/notify/toasts",
+ "ui/chrome/api/loading_count",
+ "ui/chrome/api/base_path",
+ "ui/chrome/api/ui_settings",
+ "ui/chrome",
+ "legacy files",
+]
+`;
+
+exports[`#start() load order useLegacyTestHarness = true loads ui/modules before ui/test_harness, and both before legacy files 1`] = `
+Array [
+ "ui/metadata",
+ "ui/notify/fatal_error",
+ "ui/notify/toasts",
+ "ui/chrome/api/loading_count",
+ "ui/chrome/api/base_path",
+ "ui/chrome/api/ui_settings",
+ "ui/test_harness",
+ "legacy files",
+]
+`;
+
exports[`#stop() destroys the angular scope and empties the targetDomElement if angular is bootstraped to targetDomElement 1`] = `
{
};
});
+const mockUiSettingsInit = jest.fn();
+jest.mock('ui/chrome/api/ui_settings', () => {
+ mockLoadOrder.push('ui/chrome/api/ui_settings');
+ return {
+ __newPlatformInit__: mockUiSettingsInit,
+ };
+});
+
import { LegacyPlatformService } from './legacy_platform_service';
const fatalErrorsStartContract = {} as any;
@@ -85,7 +93,7 @@ const notificationsStartContract = {
toasts: {},
} as any;
-const injectedMetadataStartContract = {
+const injectedMetadataStartContract: any = {
getBasePath: jest.fn(),
getLegacyMetadata: jest.fn(),
};
@@ -101,6 +109,8 @@ const basePathStartContract = {
removeFromPath: jest.fn(),
};
+const uiSettingsStartContract: any = {};
+
const defaultParams = {
targetDomElement: document.createElement('div'),
requireLegacyFiles: jest.fn(() => {
@@ -114,6 +124,7 @@ const defaultStartDeps = {
notifications: notificationsStartContract,
loadingCount: loadingCountStartContract,
basePath: basePathStartContract,
+ uiSettings: uiSettingsStartContract,
};
afterEach(() => {
@@ -224,15 +235,7 @@ describe('#start()', () => {
legacyPlatform.start(defaultStartDeps);
- expect(mockLoadOrder).toEqual([
- 'ui/metadata',
- 'ui/notify/fatal_error',
- 'ui/notify/toasts',
- 'ui/chrome/api/loading_count',
- 'ui/chrome/api/base_path',
- 'ui/chrome',
- 'legacy files',
- ]);
+ expect(mockLoadOrder).toMatchSnapshot();
});
});
@@ -247,15 +250,7 @@ describe('#start()', () => {
legacyPlatform.start(defaultStartDeps);
- expect(mockLoadOrder).toEqual([
- 'ui/metadata',
- 'ui/notify/fatal_error',
- 'ui/notify/toasts',
- 'ui/chrome/api/loading_count',
- 'ui/chrome/api/base_path',
- 'ui/test_harness',
- 'legacy files',
- ]);
+ expect(mockLoadOrder).toMatchSnapshot();
});
});
});
diff --git a/src/core/public/ui_settings/__snapshots__/ui_settings_service.test.ts.snap b/src/core/public/ui_settings/__snapshots__/ui_settings_service.test.ts.snap
new file mode 100644
index 0000000000000..e30ef2fa1b14d
--- /dev/null
+++ b/src/core/public/ui_settings/__snapshots__/ui_settings_service.test.ts.snap
@@ -0,0 +1,52 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`#start contstructs UiSettingsClient and UiSettingsApi: UiSettingsApi args 1`] = `
+[MockFunction MockUiSettingsApi] {
+ "calls": Array [
+ Array [
+ Object {
+ "basePathStartContract": true,
+ },
+ "kibanaVersion",
+ ],
+ ],
+}
+`;
+
+exports[`#start contstructs UiSettingsClient and UiSettingsApi: UiSettingsClient args 1`] = `
+[MockFunction MockUiSettingsClient] {
+ "calls": Array [
+ Array [
+ Object {
+ "api": mockConstructor {
+ "getLoadingCount$": [MockFunction] {
+ "calls": Array [
+ Array [],
+ ],
+ },
+ "stop": [MockFunction],
+ },
+ "defaults": Object {
+ "legacyInjectedUiSettingDefaults": true,
+ },
+ "initialSettings": Object {
+ "legacyInjectedUiSettingUserValues": true,
+ },
+ "onUpdateError": [Function],
+ },
+ ],
+ ],
+}
+`;
+
+exports[`#start passes the uiSettings loading count to the loading count api: loadingCount.add calls 1`] = `
+[MockFunction] {
+ "calls": Array [
+ Array [
+ Object {
+ "loadingCountObservable": true,
+ },
+ ],
+ ],
+}
+`;
diff --git a/src/core/public/ui_settings/ui_settings_service.test.ts b/src/core/public/ui_settings/ui_settings_service.test.ts
new file mode 100644
index 0000000000000..d47dbf4f80189
--- /dev/null
+++ b/src/core/public/ui_settings/ui_settings_service.test.ts
@@ -0,0 +1,113 @@
+/*
+ * 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.
+ */
+
+// Mock the UiSettingsApi class
+import { UiSettingsApi } from './ui_settings_api';
+const MockUiSettingsApi = jest
+ .fn(function(this: any) {
+ this.stop = jest.fn();
+ this.getLoadingCount$ = jest.fn().mockReturnValue({
+ loadingCountObservable: true,
+ });
+ })
+ .mockName('MockUiSettingsApi');
+jest.mock('./ui_settings_api', () => ({
+ UiSettingsApi: MockUiSettingsApi,
+}));
+
+// Mock the UiSettingsClient class
+import { UiSettingsClient } from './ui_settings_client';
+const MockUiSettingsClient = jest
+ .fn(function(this: any) {
+ this.stop = jest.fn();
+ })
+ .mockName('MockUiSettingsClient');
+jest.mock('./ui_settings_client', () => ({
+ UiSettingsClient: MockUiSettingsClient,
+}));
+
+// Load the service
+import { UiSettingsService } from './ui_settings_service';
+
+const loadingCountStartContract = {
+ loadingCountStartContract: true,
+ add: jest.fn(),
+};
+
+const defaultDeps: any = {
+ notifications: {
+ notificationsStartContract: true,
+ },
+ loadingCount: loadingCountStartContract,
+ injectedMetadata: {
+ injectedMetadataStartContract: true,
+ getKibanaVersion: jest.fn().mockReturnValue('kibanaVersion'),
+ getLegacyMetadata: jest.fn().mockReturnValue({
+ uiSettings: {
+ defaults: { legacyInjectedUiSettingDefaults: true },
+ user: { legacyInjectedUiSettingUserValues: true },
+ },
+ }),
+ },
+ basePath: {
+ basePathStartContract: true,
+ },
+};
+
+afterEach(() => {
+ jest.clearAllMocks();
+});
+
+describe('#start', () => {
+ it('returns an instance of UiSettingsClient', () => {
+ const start = new UiSettingsService().start(defaultDeps);
+ expect(start).toBeInstanceOf(MockUiSettingsClient);
+ });
+
+ it('contstructs UiSettingsClient and UiSettingsApi', () => {
+ new UiSettingsService().start(defaultDeps);
+
+ expect(MockUiSettingsApi).toMatchSnapshot('UiSettingsApi args');
+ expect(MockUiSettingsClient).toMatchSnapshot('UiSettingsClient args');
+ });
+
+ it('passes the uiSettings loading count to the loading count api', () => {
+ new UiSettingsService().start(defaultDeps);
+
+ expect(loadingCountStartContract.add).toMatchSnapshot('loadingCount.add calls');
+ });
+});
+
+describe('#stop', () => {
+ it('runs fine if service never started', () => {
+ const service = new UiSettingsService();
+ expect(() => service.stop()).not.toThrowError();
+ });
+
+ it('stops the uiSettingsClient and uiSettingsApi', () => {
+ const service = new UiSettingsService();
+ const client = service.start(defaultDeps);
+ const [[{ api }]] = MockUiSettingsClient.mock.calls;
+ jest.spyOn(client, 'stop');
+ jest.spyOn(api, 'stop');
+ service.stop();
+ expect(api.stop).toHaveBeenCalledTimes(1);
+ expect(client.stop).toHaveBeenCalledTimes(1);
+ });
+});