From 9d0199d3d8d5432bb4550db6df26e1821285f4c9 Mon Sep 17 00:00:00 2001 From: Eli Perelman Date: Wed, 4 Dec 2019 18:54:27 -0600 Subject: [PATCH] Move extraneous application integration tests to unit tests --- .../application/application_service.test.ts | 54 ++++++++ .../application_service.test.tsx | 116 ------------------ 2 files changed, 54 insertions(+), 116 deletions(-) delete mode 100644 src/core/public/application/integration_tests/application_service.test.tsx diff --git a/src/core/public/application/application_service.test.ts b/src/core/public/application/application_service.test.ts index 5373e44f6f74f95..d064b17ace14230 100644 --- a/src/core/public/application/application_service.test.ts +++ b/src/core/public/application/application_service.test.ts @@ -18,6 +18,8 @@ */ import { createElement } from 'react'; +import { Subject } from 'rxjs'; +import { bufferCount, skip, takeUntil } from 'rxjs/operators'; import { shallow } from 'enzyme'; import { injectedMetadataServiceMock } from '../injected_metadata/injected_metadata_service.mock'; @@ -383,5 +385,57 @@ describe('#start()', () => { navigateToApp('myTestApp'); expect(setupDeps.redirectTo).toHaveBeenCalledWith('/test/app/myTestApp'); }); + + it('updates currentApp$ after mounting', async () => { + service.setup(setupDeps); + + const { currentAppId$, navigateToApp } = await service.start(startDeps); + const stop$ = new Subject(); + const promise = currentAppId$.pipe(skip(1), bufferCount(4), takeUntil(stop$)).toPromise(); + + await navigateToApp('alpha'); + await navigateToApp('beta'); + await navigateToApp('gamma'); + await navigateToApp('delta'); + stop$.next(); + + const appIds = await promise; + + expect(appIds).toMatchInlineSnapshot(` + Array [ + "alpha", + "beta", + "gamma", + "delta", + ] + `); + }); + + it('sets window.location.href when navigating to legacy apps', async () => { + setupDeps.http = httpServiceMock.createSetupContract({ basePath: '/test' }); + setupDeps.injectedMetadata.getLegacyMode.mockReturnValue(true); + setupDeps.redirectTo = jest.fn(); + service.setup(setupDeps); + + const { navigateToApp } = await service.start(startDeps); + + await navigateToApp('alpha'); + expect(setupDeps.redirectTo).toHaveBeenCalledWith('/test/app/alpha'); + }); + + it('handles legacy apps with subapps', async () => { + setupDeps.http = httpServiceMock.createSetupContract({ basePath: '/test' }); + setupDeps.injectedMetadata.getLegacyMode.mockReturnValue(true); + setupDeps.redirectTo = jest.fn(); + + const { registerLegacyApp } = service.setup(setupDeps); + + registerLegacyApp({ id: 'baseApp:legacyApp1' } as any); + + const { navigateToApp } = await service.start(startDeps); + + await navigateToApp('baseApp:legacyApp1'); + expect(setupDeps.redirectTo).toHaveBeenCalledWith('/test/app/baseApp'); + }); }); }); diff --git a/src/core/public/application/integration_tests/application_service.test.tsx b/src/core/public/application/integration_tests/application_service.test.tsx deleted file mode 100644 index f01eb15fd48ab33..000000000000000 --- a/src/core/public/application/integration_tests/application_service.test.tsx +++ /dev/null @@ -1,116 +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 { Subject } from 'rxjs'; -import { bufferCount, skip, takeUntil } from 'rxjs/operators'; - -import { injectedMetadataServiceMock } from '../../injected_metadata/injected_metadata_service.mock'; -import { contextServiceMock } from '../../context/context_service.mock'; -import { httpServiceMock } from '../../http/http_service.mock'; -import { MockLifecycle } from '../test_types'; -import { ApplicationService } from '../application_service'; -import { createRenderer } from './utils'; - -describe('#start()', () => { - let setupDeps: MockLifecycle<'setup'>; - let startDeps: MockLifecycle<'start'>; - let service: ApplicationService; - - beforeEach(() => { - setupDeps = { - http: httpServiceMock.createSetupContract(), - context: contextServiceMock.createSetupContract(), - injectedMetadata: injectedMetadataServiceMock.createSetupContract(), - }; - setupDeps.http.post.mockImplementation(async path => { - if (path.startsWith('/api/core/capabilities')) { - return { - navLinks: { - alpha: true, - beta: false, - gamma: true, - delta: false, - }, - }; - } - }); - setupDeps.injectedMetadata.getLegacyMode.mockReturnValue(false); - startDeps = { http: setupDeps.http, injectedMetadata: setupDeps.injectedMetadata }; - service = new ApplicationService(); - }); - - describe('navigateToApp', () => { - it('updates currentApp$ after mounting', async () => { - service.setup(setupDeps); - - const application = await service.start(startDeps); - const stop$ = new Subject(); - const promise = application.currentAppId$ - .pipe(skip(1), bufferCount(4), takeUntil(stop$)) - .toPromise(); - const render = createRenderer(application.getComponent(), application.navigateToApp); - - await render('alpha'); - await render('beta'); - await render('gamma'); - await render('delta'); - stop$.next(); - - const appIds = await promise; - - expect(appIds).toMatchInlineSnapshot(` - Array [ - "alpha", - "beta", - "gamma", - "delta", - ] - `); - }); - - it('sets window.location.href when navigating to legacy apps', async () => { - setupDeps.http = httpServiceMock.createSetupContract({ basePath: '/test' }); - setupDeps.injectedMetadata.getLegacyMode.mockReturnValue(true); - setupDeps.redirectTo = jest.fn(); - service.setup(setupDeps); - - const application = await service.start(startDeps); - const render = createRenderer(application.getComponent(), application.navigateToApp); - - await render('alpha'); - expect(setupDeps.redirectTo).toHaveBeenCalledWith('/test/app/alpha'); - }); - - it('handles legacy apps with subapps', async () => { - setupDeps.http = httpServiceMock.createSetupContract({ basePath: '/test' }); - setupDeps.injectedMetadata.getLegacyMode.mockReturnValue(true); - setupDeps.redirectTo = jest.fn(); - - const { registerLegacyApp } = service.setup(setupDeps); - - registerLegacyApp({ id: 'baseApp:legacyApp1' } as any); - - const application = await service.start(startDeps); - const render = createRenderer(application.getComponent(), application.navigateToApp); - - await render('baseApp:legacyApp1'); - expect(setupDeps.redirectTo).toHaveBeenCalledWith('/test/app/baseApp'); - }); - }); -});