Skip to content

Commit

Permalink
Fix chrome:application integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eliperelman committed Dec 29, 2019
1 parent ebde655 commit f9279fe
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 40 deletions.
26 changes: 15 additions & 11 deletions src/core/public/application/application_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,27 @@ const createInternalSetupContractMock = (): jest.Mocked<InternalApplicationSetup
registerMountContext: jest.fn(),
});

const createStartContractMock = (legacyMode = false): jest.Mocked<ApplicationStart> => ({
const createStartContractMock = (): jest.Mocked<ApplicationStart> => ({
capabilities: capabilitiesServiceMock.createStartContract().capabilities,
navigateToApp: jest.fn(),
getUrlForApp: jest.fn(),
registerMountContext: jest.fn(),
});

const createInternalStartContractMock = (): jest.Mocked<InternalApplicationStart> => ({
availableApps: new Map(),
availableLegacyApps: new Map(),
capabilities: capabilitiesServiceMock.createStartContract().capabilities,
navigateToApp: jest.fn(),
getUrlForApp: jest.fn(),
registerMountContext: jest.fn(),
currentAppId$: new Subject<string | undefined>(),
getComponent: jest.fn(),
});
const createInternalStartContractMock = (): jest.Mocked<InternalApplicationStart> => {
const currentAppId$ = new Subject<string | undefined>();

return {
availableApps: new Map(),
availableLegacyApps: new Map(),
capabilities: capabilitiesServiceMock.createStartContract().capabilities,
currentAppId$: currentAppId$.asObservable(),
getComponent: jest.fn(),
getUrlForApp: jest.fn(),
navigateToApp: jest.fn().mockImplementation(appId => currentAppId$.next(appId)),
registerMountContext: jest.fn(),
};
};

const createMock = (): jest.Mocked<ApplicationServiceContract> => ({
setup: jest.fn().mockReturnValue(createInternalSetupContractMock()),
Expand Down
21 changes: 8 additions & 13 deletions src/core/public/application/application_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ describe('#setup()', () => {
).toThrowErrorMatchingInlineSnapshot(
`"An application is already registered with the appRoute \\"/app/app1\\""`
);
expect(() => registerLegacyApp({ id: 'app1' } as any)).toThrowErrorMatchingInlineSnapshot(
`"An application is already registered with the appRoute \\"/app/app1\\""`
);
expect(() => registerLegacyApp({ id: 'app1' } as any)).not.toThrow();

register(Symbol(), { id: 'app-next', mount, appRoute: '/app/app3' } as any);

Expand All @@ -88,9 +86,7 @@ describe('#setup()', () => {
).toThrowErrorMatchingInlineSnapshot(
`"An application is already registered with the appRoute \\"/app/app3\\""`
);
expect(() => registerLegacyApp({ id: 'app3' } as any)).toThrowErrorMatchingInlineSnapshot(
`"An application is already registered with the appRoute \\"/app/app3\\""`
);
expect(() => registerLegacyApp({ id: 'app3' } as any)).not.toThrow();
});

it('throws an error if an App starts with the HTTP base path', () => {
Expand Down Expand Up @@ -133,11 +129,7 @@ describe('#setup()', () => {
).toThrowErrorMatchingInlineSnapshot(
`"An application is already registered with the appRoute \\"/app/app1\\""`
);
expect(() =>
registerLegacyApp({ id: 'app1:other' } as any)
).toThrowErrorMatchingInlineSnapshot(
`"An application is already registered with the appRoute \\"/app/app1\\""`
);
expect(() => registerLegacyApp({ id: 'app1:other' } as any)).not.toThrow();
});
});

Expand Down Expand Up @@ -202,14 +194,17 @@ describe('#start()', () => {
`);
});

it('passes metadata to capabilities', async () => {
it('passes appIds to capabilities', async () => {
const { register } = service.setup(setupDeps);

register(Symbol(), { id: 'app1', mount } as any);
register(Symbol(), { id: 'app2', mount } as any);
register(Symbol(), { id: 'app3', mount } as any);
await service.start(startDeps);

expect(MockCapabilitiesService.start).toHaveBeenCalledWith({
injectedMetadata: startDeps.injectedMetadata,
appIds: ['app1', 'app2', 'app3'],
http: setupDeps.http,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ interface StartDeps {
http: HttpStart;
}

export { Capabilities };

/** @internal */
export interface CapabilitiesStart {
capabilities: RecursiveReadonly<Capabilities>;
Expand Down
3 changes: 2 additions & 1 deletion src/core/public/application/capabilities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
* under the License.
*/

export { Capabilities, CapabilitiesService } from './capabilities_service';
export { Capabilities } from '../../../types/capabilities';
export { CapabilitiesService } from './capabilities_service';
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,25 @@ describe('#start()', () => {
let service: ApplicationService;

beforeEach(() => {
const http = httpServiceMock.createSetupContract();
setupDeps = {
http,
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, injectedMetadata: setupDeps.injectedMetadata };
startDeps = { http: setupDeps.http, injectedMetadata: setupDeps.injectedMetadata };
service = new ApplicationService();
});

Expand All @@ -51,22 +62,24 @@ describe('#start()', () => {
const application = await service.start(startDeps);
const stop$ = new Subject();
const promise = application.currentAppId$
.pipe(skip(1), bufferCount(3), takeUntil(stop$))
.pipe(skip(1), bufferCount(4), takeUntil(stop$))
.toPromise();
const render = createRenderer(application.getComponent(), application.navigateToApp);

await render('myTestApp');
await render('myOtherApp');
await render('myLastApp');
await render('alpha');
await render('beta');
await render('gamma');
await render('delta');
stop$.next();

const appIds = await promise;

expect(appIds).toMatchInlineSnapshot(`
Array [
"myTestApp",
"myOtherApp",
"myLastApp",
"alpha",
"beta",
"gamma",
"delta",
]
`);
});
Expand All @@ -80,8 +93,8 @@ describe('#start()', () => {
const application = await service.start(startDeps);
const render = createRenderer(application.getComponent(), application.navigateToApp);

await render('legacyApp1');
expect(setupDeps.redirectTo).toHaveBeenCalledWith('/test/app/legacyApp1');
await render('alpha');
expect(setupDeps.redirectTo).toHaveBeenCalledWith('/test/app/alpha');
});

it('handles legacy apps with subapps', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/chrome/chrome_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class ChromeService {
)
);
this.isVisible$ = combineLatest(this.appHidden$, this.toggleHidden$).pipe(
map(([appHidden, chromeHidden]) => !(appHidden || chromeHidden)),
map(([appHidden, toggleHidden]) => !(appHidden || toggleHidden)),
takeUntil(this.stop$)
);
}
Expand Down

0 comments on commit f9279fe

Please sign in to comment.