Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mount ui/new_platform applications in same div structure as Core #63930

Merged
merged 3 commits into from
May 10, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
joshdover marked this conversation as resolved.
Show resolved Hide resolved

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