Skip to content

Commit

Permalink
Mount ui/new_platform applications in same div structure as Core (#63930
Browse files Browse the repository at this point in the history
)
  • Loading branch information
joshdover authored May 10, 2020
1 parent ef1800b commit 1c554d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/legacy/ui/public/new_platform/new_platform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jest.mock('history');
import { setRootControllerMock, historyMock } from './new_platform.test.mocks';
import { legacyAppRegister, __reset__, __setup__, __start__ } from './new_platform';
import { coreMock } from '../../../../core/public/mocks';
import { AppMount } from '../../../../core/public';

describe('ui/new_platform', () => {
describe('legacyAppRegister', () => {
Expand All @@ -33,7 +34,7 @@ describe('ui/new_platform', () => {

const registerApp = () => {
const unmountMock = jest.fn();
const mountMock = jest.fn(() => unmountMock);
const mountMock = jest.fn<ReturnType<AppMount>, Parameters<AppMount>>(() => unmountMock);
legacyAppRegister({
id: 'test',
title: 'Test',
Expand Down Expand Up @@ -62,13 +63,25 @@ describe('ui/new_platform', () => {

controller(scopeMock, elementMock);
expect(mountMock).toHaveBeenCalledWith({
element: elementMock[0],
element: expect.any(HTMLElement),
appBasePath: '/test/base/path/app/test',
onAppLeave: expect.any(Function),
history: historyMock,
});
});

test('app is mounted in new div inside containing element', () => {
const { mountMock } = registerApp();
const controller = setRootControllerMock.mock.calls[0][1];
const scopeMock = { $on: jest.fn() };
const elementMock = [document.createElement('div')];

controller(scopeMock, elementMock);

const { element } = mountMock.mock.calls[0][0];
expect(element.parentElement).toEqual(elementMock[0]);
});

test('controller calls deprecated context app.mount when invoked', () => {
const unmountMock = jest.fn();
// Two arguments changes how this is called.
Expand All @@ -84,7 +97,7 @@ describe('ui/new_platform', () => {

controller(scopeMock, elementMock);
expect(mountMock).toHaveBeenCalledWith(expect.any(Object), {
element: elementMock[0],
element: expect.any(HTMLElement),
appBasePath: '/test/base/path/app/test',
onAppLeave: expect.any(Function),
history: historyMock,
Expand Down
3 changes: 2 additions & 1 deletion src/legacy/ui/public/new_platform/new_platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ export const legacyAppRegister = (app: App<any>) => {
legacyAppRegistered = true;

require('ui/chrome').setRootController(app.id, ($scope: IScope, $element: JQLite) => {
const element = $element[0];
const element = document.createElement('div');
$element[0].appendChild(element);

// Root controller cannot return a Promise so use an internal async function and call it immediately
(async () => {
Expand Down

0 comments on commit 1c554d9

Please sign in to comment.