Skip to content

Commit

Permalink
preprend basePath in getUrlForApp (#57316)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Feb 12, 2020
1 parent 6eaeca8 commit 49bec6e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/core/public/application/application_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let service: ApplicationService;

describe('#setup()', () => {
beforeEach(() => {
const http = httpServiceMock.createSetupContract({ basePath: '/test' });
const http = httpServiceMock.createSetupContract({ basePath: '/base-path' });
setupDeps = {
http,
context: contextServiceMock.createSetupContract(),
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('#setup()', () => {
const { register } = service.setup(setupDeps);

expect(() =>
register(Symbol(), createApp({ id: 'app2', appRoute: '/test/app2' }))
register(Symbol(), createApp({ id: 'app2', appRoute: '/base-path/app2' }))
).toThrowErrorMatchingInlineSnapshot(
`"Cannot register an application route that includes HTTP base path"`
);
Expand Down Expand Up @@ -430,7 +430,7 @@ describe('#start()', () => {
beforeEach(() => {
MockHistory.push.mockReset();

const http = httpServiceMock.createSetupContract({ basePath: '/test' });
const http = httpServiceMock.createSetupContract({ basePath: '/base-path' });
setupDeps = {
http,
context: contextServiceMock.createSetupContract(),
Expand Down Expand Up @@ -561,7 +561,7 @@ describe('#start()', () => {

const { getUrlForApp } = await service.start(startDeps);

expect(getUrlForApp('app1')).toBe('/app/app1');
expect(getUrlForApp('app1')).toBe('/base-path/app/app1');
});

it('creates URL for registered appId', async () => {
Expand All @@ -573,20 +573,20 @@ describe('#start()', () => {

const { getUrlForApp } = await service.start(startDeps);

expect(getUrlForApp('app1')).toBe('/app/app1');
expect(getUrlForApp('legacyApp1')).toBe('/app/legacyApp1');
expect(getUrlForApp('app2')).toBe('/custom/path');
expect(getUrlForApp('app1')).toBe('/base-path/app/app1');
expect(getUrlForApp('legacyApp1')).toBe('/base-path/app/legacyApp1');
expect(getUrlForApp('app2')).toBe('/base-path/custom/path');
});

it('creates URLs with path parameter', async () => {
service.setup(setupDeps);

const { getUrlForApp } = await service.start(startDeps);

expect(getUrlForApp('app1', { path: 'deep/link' })).toBe('/app/app1/deep/link');
expect(getUrlForApp('app1', { path: '/deep//link/' })).toBe('/app/app1/deep/link');
expect(getUrlForApp('app1', { path: '//deep/link//' })).toBe('/app/app1/deep/link');
expect(getUrlForApp('app1', { path: 'deep/link///' })).toBe('/app/app1/deep/link');
expect(getUrlForApp('app1', { path: 'deep/link' })).toBe('/base-path/app/app1/deep/link');
expect(getUrlForApp('app1', { path: '/deep//link/' })).toBe('/base-path/app/app1/deep/link');
expect(getUrlForApp('app1', { path: '//deep/link//' })).toBe('/base-path/app/app1/deep/link');
expect(getUrlForApp('app1', { path: 'deep/link///' })).toBe('/base-path/app/app1/deep/link');
});
});

Expand Down Expand Up @@ -659,7 +659,7 @@ describe('#start()', () => {
const { navigateToApp } = await service.start(startDeps);

await navigateToApp('myTestApp');
expect(setupDeps.redirectTo).toHaveBeenCalledWith('/test/app/myTestApp');
expect(setupDeps.redirectTo).toHaveBeenCalledWith('/base-path/app/myTestApp');
});

it('updates currentApp$ after mounting', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/application/application_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class ApplicationService {
),
registerMountContext: this.mountContext.registerContext,
getUrlForApp: (appId, { path }: { path?: string } = {}) =>
getAppUrl(availableMounters, appId, path),
http.basePath.prepend(getAppUrl(availableMounters, appId, path)),
navigateToApp: async (appId, { path, state }: { path?: string; state?: any } = {}) => {
if (await this.shouldNavigate(overlays)) {
this.appLeaveHandlers.delete(this.currentAppId$.value!);
Expand Down

0 comments on commit 49bec6e

Please sign in to comment.