From 5dd3bbaddb8d44185f4c08ab82e23f8d114e9479 Mon Sep 17 00:00:00 2001 From: Mikhail Shustov Date: Sat, 8 Feb 2020 08:26:49 +0100 Subject: [PATCH] Revert "Manual backport rendering tests (#57105)" (#57164) This reverts commit fa42edc41ccf7a4f218afe3baae59377fef132b9. --- .../integration_tests/router.test.tsx | 95 ++---------- .../application/integration_tests/utils.tsx | 6 +- src/core/public/application/test_types.ts | 17 +-- test/functional/services/browser.ts | 12 -- test/plugin_functional/config.js | 12 +- .../core_plugin_chromeless/public/plugin.tsx | 6 + .../rendering_plugin/public/plugin.tsx | 13 +- .../test_suites/core_plugins/rendering.ts | 141 +++++------------- 8 files changed, 70 insertions(+), 232 deletions(-) diff --git a/src/core/public/application/integration_tests/router.test.tsx b/src/core/public/application/integration_tests/router.test.tsx index 0c5f5a138d58f..4d83ab67810af 100644 --- a/src/core/public/application/integration_tests/router.test.tsx +++ b/src/core/public/application/integration_tests/router.test.tsx @@ -23,7 +23,7 @@ import { createMemoryHistory, History, createHashHistory } from 'history'; import { AppRouter, AppNotFound } from '../ui'; import { EitherApp, MockedMounterMap, MockedMounterTuple } from '../test_types'; -import { createRenderer, createAppMounter, createLegacyAppMounter, getUnmounter } from './utils'; +import { createRenderer, createAppMounter, createLegacyAppMounter } from './utils'; import { AppStatus } from '../types'; describe('AppContainer', () => { @@ -36,6 +36,7 @@ describe('AppContainer', () => { history.push(path); return update(); }; + const mockMountersToMounters = () => new Map([...mounters].map(([appId, { mounter }]) => [appId, mounter])); const setAppLeaveHandlerMock = () => undefined; @@ -57,8 +58,7 @@ describe('AppContainer', () => { createLegacyAppMounter('legacyApp1', jest.fn()), createAppMounter('app2', '
App 2
'), createLegacyAppMounter('baseApp:legacyApp2', jest.fn()), - createAppMounter('app3', '
Chromeless A
', '/chromeless-a/path'), - createAppMounter('app4', '
Chromeless B
', '/chromeless-b/path'), + createAppMounter('app3', '
App 3
', '/custom/path'), createAppMounter('disabledApp', '
Disabled app
'), createLegacyAppMounter('disabledLegacyApp', jest.fn()), ] as Array>); @@ -75,24 +75,23 @@ describe('AppContainer', () => { }); it('calls mount handler and returned unmount function when navigating between apps', async () => { + const dom1 = await navigate('/app/app1'); const app1 = mounters.get('app1')!; - const app2 = mounters.get('app2')!; - let dom = await navigate('/app/app1'); expect(app1.mounter.mount).toHaveBeenCalled(); - expect(dom?.html()).toMatchInlineSnapshot(` + expect(dom1?.html()).toMatchInlineSnapshot(` "
basename: /app/app1 html: App 1
" `); - const app1Unmount = await getUnmounter(app1); - dom = await navigate('/app/app2'); + const app1Unmount = await app1.mounter.mount.mock.results[0].value; + const dom2 = await navigate('/app/app2'); expect(app1Unmount).toHaveBeenCalled(); - expect(app2.mounter.mount).toHaveBeenCalled(); - expect(dom?.html()).toMatchInlineSnapshot(` + expect(mounters.get('app2')!.mounter.mount).toHaveBeenCalled(); + expect(dom2?.html()).toMatchInlineSnapshot(` "
basename: /app/app2 html:
App 2
@@ -100,82 +99,6 @@ describe('AppContainer', () => { `); }); - it('can navigate between standard application and one with custom appRoute', async () => { - const standardApp = mounters.get('app1')!; - const chromelessApp = mounters.get('app3')!; - let dom = await navigate('/app/app1'); - - expect(standardApp.mounter.mount).toHaveBeenCalled(); - expect(dom?.html()).toMatchInlineSnapshot(` - "
- basename: /app/app1 - html: App 1 -
" - `); - - const standardAppUnmount = await getUnmounter(standardApp); - dom = await navigate('/chromeless-a/path'); - - expect(standardAppUnmount).toHaveBeenCalled(); - expect(chromelessApp.mounter.mount).toHaveBeenCalled(); - expect(dom?.html()).toMatchInlineSnapshot(` - "
- basename: /chromeless-a/path - html:
Chromeless A
-
" - `); - - const chromelessAppUnmount = await getUnmounter(standardApp); - dom = await navigate('/app/app1'); - - expect(chromelessAppUnmount).toHaveBeenCalled(); - expect(standardApp.mounter.mount).toHaveBeenCalledTimes(2); - expect(dom?.html()).toMatchInlineSnapshot(` - "
- basename: /app/app1 - html: App 1 -
" - `); - }); - - it('can navigate between two applications with custom appRoutes', async () => { - const chromelessAppA = mounters.get('app3')!; - const chromelessAppB = mounters.get('app4')!; - let dom = await navigate('/chromeless-a/path'); - - expect(chromelessAppA.mounter.mount).toHaveBeenCalled(); - expect(dom?.html()).toMatchInlineSnapshot(` - "
- basename: /chromeless-a/path - html:
Chromeless A
-
" - `); - - const chromelessAppAUnmount = await getUnmounter(chromelessAppA); - dom = await navigate('/chromeless-b/path'); - - expect(chromelessAppAUnmount).toHaveBeenCalled(); - expect(chromelessAppB.mounter.mount).toHaveBeenCalled(); - expect(dom?.html()).toMatchInlineSnapshot(` - "
- basename: /chromeless-b/path - html:
Chromeless B
-
" - `); - - const chromelessAppBUnmount = await getUnmounter(chromelessAppB); - dom = await navigate('/chromeless-a/path'); - - expect(chromelessAppBUnmount).toHaveBeenCalled(); - expect(chromelessAppA.mounter.mount).toHaveBeenCalledTimes(2); - expect(dom?.html()).toMatchInlineSnapshot(` - "
- basename: /chromeless-a/path - html:
Chromeless A
-
" - `); - }); - it('should not mount when partial route path matches', async () => { mounters.set(...createAppMounter('spaces', '
Custom Space
', '/spaces/fake-login')); mounters.set(...createAppMounter('login', '
Login Page
', '/fake-login')); diff --git a/src/core/public/application/integration_tests/utils.tsx b/src/core/public/application/integration_tests/utils.tsx index 4f34438fc822a..6367d1fa12697 100644 --- a/src/core/public/application/integration_tests/utils.tsx +++ b/src/core/public/application/integration_tests/utils.tsx @@ -23,7 +23,7 @@ import { mount } from 'enzyme'; import { I18nProvider } from '@kbn/i18n/react'; import { App, LegacyApp, AppMountParameters } from '../types'; -import { EitherApp, MockedMounter, MockedMounterTuple, Mountable } from '../test_types'; +import { MockedMounter, MockedMounterTuple } from '../test_types'; type Dom = ReturnType | null; type Renderer = () => Dom | Promise; @@ -80,7 +80,3 @@ export const createLegacyAppMounter = ( unmount: jest.fn(), }, ]; - -export function getUnmounter(app: Mountable) { - return app.mounter.mount.mock.results[0].value; -} diff --git a/src/core/public/application/test_types.ts b/src/core/public/application/test_types.ts index b822597e510cb..3d992cb950eb4 100644 --- a/src/core/public/application/test_types.ts +++ b/src/core/public/application/test_types.ts @@ -26,19 +26,18 @@ export type ApplicationServiceContract = PublicMethodsOf; export type EitherApp = App | LegacyApp; /** @internal */ export type MockedUnmount = jest.Mocked; - -/** @internal */ -export interface Mountable { - mounter: MockedMounter; - unmount: MockedUnmount; -} - /** @internal */ export type MockedMounter = jest.Mocked>>; /** @internal */ -export type MockedMounterTuple = [string, Mountable]; +export type MockedMounterTuple = [ + string, + { mounter: MockedMounter; unmount: MockedUnmount } +]; /** @internal */ -export type MockedMounterMap = Map>; +export type MockedMounterMap = Map< + string, + { mounter: MockedMounter; unmount: MockedUnmount } +>; /** @internal */ export type MockLifecycle< T extends keyof ApplicationService, diff --git a/test/functional/services/browser.ts b/test/functional/services/browser.ts index ae68be3ed7987..59498bd8413a7 100644 --- a/test/functional/services/browser.ts +++ b/test/functional/services/browser.ts @@ -311,23 +311,11 @@ export async function BrowserProvider({ getService }: FtrProviderContext) { /** * Moves forwards in the browser history. * https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_Navigation.html#forward - * - * @return {Promise} */ public async goForward() { await driver.navigate().forward(); } - /** - * Navigates to a URL via the browser history. - * https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_Navigation.html#to - * - * @return {Promise} - */ - public async navigateTo(url: string) { - await driver.navigate().to(url); - } - /** * Sends a sequance of keyboard keys. For each key, this will record a pair of keyDown and keyUp actions * https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/input_exports_Actions.html#sendKeys diff --git a/test/plugin_functional/config.js b/test/plugin_functional/config.js index bed9a2cf8c847..e63054f1b6912 100644 --- a/test/plugin_functional/config.js +++ b/test/plugin_functional/config.js @@ -32,13 +32,13 @@ export default async function({ readConfigFile }) { return { testFiles: [ - // require.resolve('./test_suites/app_plugins'), - // require.resolve('./test_suites/custom_visualizations'), - // require.resolve('./test_suites/panel_actions'), - // require.resolve('./test_suites/embeddable_explorer'), + require.resolve('./test_suites/app_plugins'), + require.resolve('./test_suites/custom_visualizations'), + require.resolve('./test_suites/panel_actions'), + require.resolve('./test_suites/embeddable_explorer'), require.resolve('./test_suites/core_plugins'), - // require.resolve('./test_suites/management'), - // require.resolve('./test_suites/bfetch_explorer'), + require.resolve('./test_suites/management'), + require.resolve('./test_suites/bfetch_explorer'), ], services: { ...functionalConfig.get('services'), diff --git a/test/plugin_functional/plugins/core_plugin_chromeless/public/plugin.tsx b/test/plugin_functional/plugins/core_plugin_chromeless/public/plugin.tsx index 7ce348fa2111e..03870410fb334 100644 --- a/test/plugin_functional/plugins/core_plugin_chromeless/public/plugin.tsx +++ b/test/plugin_functional/plugins/core_plugin_chromeless/public/plugin.tsx @@ -31,6 +31,12 @@ export class CorePluginChromelessPlugin return renderApp(context, params); }, }); + + return { + getGreeting() { + return 'Hello from Plugin Chromeless!'; + }, + }; } public start() {} diff --git a/test/plugin_functional/plugins/rendering_plugin/public/plugin.tsx b/test/plugin_functional/plugins/rendering_plugin/public/plugin.tsx index a4925cdb8f8df..6e80b56953ca0 100644 --- a/test/plugin_functional/plugins/rendering_plugin/public/plugin.tsx +++ b/test/plugin_functional/plugins/rendering_plugin/public/plugin.tsx @@ -26,24 +26,13 @@ export class RenderingPlugin implements Plugin { core.application.register({ id: 'rendering', title: 'Rendering', - appRoute: '/render/core', + appRoute: '/render', async mount(context, { element }) { render(

rendering service

, element); return () => unmountComponentAtNode(element); }, }); - - core.application.register({ - id: 'custom-app-route', - title: 'Custom App Route', - appRoute: '/custom/appRoute', - async mount(context, { element }) { - render(

Custom App Route

, element); - - return () => unmountComponentAtNode(element); - }, - }); } public start() {} diff --git a/test/plugin_functional/test_suites/core_plugins/rendering.ts b/test/plugin_functional/test_suites/core_plugins/rendering.ts index d85c3d4896b79..d0025c82a7ba5 100644 --- a/test/plugin_functional/test_suites/core_plugins/rendering.ts +++ b/test/plugin_functional/test_suites/core_plugins/rendering.ts @@ -22,60 +22,43 @@ import expect from '@kbn/expect'; import '../../plugins/core_provider_plugin/types'; import { PluginFunctionalProviderContext } from '../../services'; -declare global { - interface Window { - /** - * We use this global variable to track page history changes to ensure that - * navigation is done without causing a full page reload. - */ - __RENDERING_SESSION__: string[]; - } -} - // eslint-disable-next-line import/no-default-export export default function({ getService, getPageObjects }: PluginFunctionalProviderContext) { const PageObjects = getPageObjects(['common']); - const appsMenu = getService('appsMenu'); const browser = getService('browser'); const find = getService('find'); const testSubjects = getService('testSubjects'); - const navigateTo = (path: string) => - browser.navigateTo(`${PageObjects.common.getHostPort()}${path}`); - const navigateToApp = async (title: string) => { - await appsMenu.clickLink(title); - return browser.execute(() => { - if (!('__RENDERING_SESSION__' in window)) { - window.__RENDERING_SESSION__ = []; - } + function navigate(path: string) { + return browser.get(`${PageObjects.common.getHostPort()}${path}`); + } - window.__RENDERING_SESSION__.push(window.location.pathname); - }); - }; - const getLegacyMode = () => - browser.execute(() => { + function getLegacyMode() { + return browser.execute(() => { return JSON.parse(document.querySelector('kbn-injected-metadata')!.getAttribute('data')!) .legacyMode; }); - const getUserSettings = () => - browser.execute(() => { + } + + function getUserSettings() { + return browser.execute(() => { return JSON.parse(document.querySelector('kbn-injected-metadata')!.getAttribute('data')!) .legacyMetadata.uiSettings.user; }); - const exists = (selector: string) => testSubjects.exists(selector, { timeout: 5000 }); - const findLoadingMessage = () => testSubjects.find('kbnLoadingMessage', 5000); - const getRenderingSession = () => - browser.execute(() => { - return window.__RENDERING_SESSION__; - }); + } + + async function init() { + const loading = await testSubjects.find('kbnLoadingMessage', 5000); + + return () => find.waitForElementStale(loading); + } - // eslint-disable-next-line ban/ban - describe.only('rendering service', () => { + describe('rendering service', () => { it('renders "core" application', async () => { - await navigateTo('/render/core'); + await navigate('/render/core'); - const [loadingMessage, legacyMode, userSettings] = await Promise.all([ - findLoadingMessage(), + const [loaded, legacyMode, userSettings] = await Promise.all([ + init(), getLegacyMode(), getUserSettings(), ]); @@ -83,16 +66,16 @@ export default function({ getService, getPageObjects }: PluginFunctionalProvider expect(legacyMode).to.be(false); expect(userSettings).to.not.be.empty(); - await find.waitForElementStale(loadingMessage); + await loaded(); - expect(await exists('renderingHeader')).to.be(true); + expect(await testSubjects.exists('renderingHeader')).to.be(true); }); it('renders "core" application without user settings', async () => { - await navigateTo('/render/core?includeUserSettings=false'); + await navigate('/render/core?includeUserSettings=false'); - const [loadingMessage, legacyMode, userSettings] = await Promise.all([ - findLoadingMessage(), + const [loaded, legacyMode, userSettings] = await Promise.all([ + init(), getLegacyMode(), getUserSettings(), ]); @@ -100,16 +83,16 @@ export default function({ getService, getPageObjects }: PluginFunctionalProvider expect(legacyMode).to.be(false); expect(userSettings).to.be.empty(); - await find.waitForElementStale(loadingMessage); + await loaded(); - expect(await exists('renderingHeader')).to.be(true); + expect(await testSubjects.exists('renderingHeader')).to.be(true); }); it('renders "legacy" application', async () => { - await navigateTo('/render/core_plugin_legacy'); + await navigate('/render/core_plugin_legacy'); - const [loadingMessage, legacyMode, userSettings] = await Promise.all([ - findLoadingMessage(), + const [loaded, legacyMode, userSettings] = await Promise.all([ + init(), getLegacyMode(), getUserSettings(), ]); @@ -117,17 +100,17 @@ export default function({ getService, getPageObjects }: PluginFunctionalProvider expect(legacyMode).to.be(true); expect(userSettings).to.not.be.empty(); - await find.waitForElementStale(loadingMessage); + await loaded(); - expect(await exists('coreLegacyCompatH1')).to.be(true); - expect(await exists('renderingHeader')).to.be(false); + expect(await testSubjects.exists('coreLegacyCompatH1')).to.be(true); + expect(await testSubjects.exists('renderingHeader')).to.be(false); }); it('renders "legacy" application without user settings', async () => { - await navigateTo('/render/core_plugin_legacy?includeUserSettings=false'); + await navigate('/render/core_plugin_legacy?includeUserSettings=false'); - const [loadingMessage, legacyMode, userSettings] = await Promise.all([ - findLoadingMessage(), + const [loaded, legacyMode, userSettings] = await Promise.all([ + init(), getLegacyMode(), getUserSettings(), ]); @@ -135,56 +118,10 @@ export default function({ getService, getPageObjects }: PluginFunctionalProvider expect(legacyMode).to.be(true); expect(userSettings).to.be.empty(); - await find.waitForElementStale(loadingMessage); + await loaded(); - expect(await exists('coreLegacyCompatH1')).to.be(true); - expect(await exists('renderingHeader')).to.be(false); - }); - - it('navigates between standard application and one with custom appRoute', async () => { - await navigateTo('/'); - await find.waitForElementStale(await findLoadingMessage()); - - await navigateToApp('App Status'); - expect(await exists('appStatusApp')).to.be(true); - expect(await exists('renderingHeader')).to.be(false); - - await navigateToApp('Rendering'); - expect(await exists('appStatusApp')).to.be(false); - expect(await exists('renderingHeader')).to.be(true); - - await navigateToApp('App Status'); - expect(await exists('appStatusApp')).to.be(true); - expect(await exists('renderingHeader')).to.be(false); - - expect(await getRenderingSession()).to.eql([ - '/app/app_status', - '/render/core', - '/app/app_status', - ]); - }); - - it('navigates between applications with custom appRoutes', async () => { - await navigateTo('/'); - await find.waitForElementStale(await findLoadingMessage()); - - await navigateToApp('Rendering'); - expect(await exists('renderingHeader')).to.be(true); - expect(await exists('customAppRouteHeader')).to.be(false); - - await navigateToApp('Custom App Route'); - expect(await exists('customAppRouteHeader')).to.be(true); - expect(await exists('renderingHeader')).to.be(false); - - await navigateToApp('Rendering'); - expect(await exists('renderingHeader')).to.be(true); - expect(await exists('customAppRouteHeader')).to.be(false); - - expect(await getRenderingSession()).to.eql([ - '/render/core', - '/custom/appRoute', - '/render/core', - ]); + expect(await testSubjects.exists('coreLegacyCompatH1')).to.be(true); + expect(await testSubjects.exists('renderingHeader')).to.be(false); }); }); }