Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Apr 29, 2020
1 parent 484f9f9 commit 8fb0107
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
22 changes: 13 additions & 9 deletions src/core/public/application/application_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,23 +711,27 @@ describe('#start()', () => {
it('preserves trailing slash when path contains a hash', async () => {
const { register } = service.setup(setupDeps);

register(Symbol(), createApp({ id: 'app2', appRoute: '/custom/path' }));
register(Symbol(), createApp({ id: 'app2', appRoute: '/custom/app-path' }));

const { navigateToApp } = await service.start(startDeps);
await navigateToApp('myTestApp', { path: '#/' });
expect(MockHistory.push).toHaveBeenCalledWith('/app/myTestApp#/', undefined);
await navigateToApp('app2', { path: '#/' });
expect(MockHistory.push).toHaveBeenCalledWith('/custom/app-path#/', undefined);
MockHistory.push.mockClear();

await navigateToApp('app2', { path: '#/foo/bar/' });
expect(MockHistory.push).toHaveBeenCalledWith('/custom/app-path#/foo/bar/', undefined);
MockHistory.push.mockClear();

await navigateToApp('myTestApp', { path: '#/foo/bar/' });
expect(MockHistory.push).toHaveBeenCalledWith('/app/myTestApp#/foo/bar/', undefined);
await navigateToApp('app2', { path: '/path#/' });
expect(MockHistory.push).toHaveBeenCalledWith('/custom/app-path/path#/', undefined);
MockHistory.push.mockClear();

await navigateToApp('myTestApp', { path: '/path#/' });
expect(MockHistory.push).toHaveBeenCalledWith('/app/myTestApp/path#/', undefined);
await navigateToApp('app2', { path: '/path#/hash/' });
expect(MockHistory.push).toHaveBeenCalledWith('/custom/app-path/path#/hash/', undefined);
MockHistory.push.mockClear();

await navigateToApp('myTestApp', { path: '/path#/hash/' });
expect(MockHistory.push).toHaveBeenCalledWith('/app/myTestApp/path#/hash/', undefined);
await navigateToApp('app2', { path: '/path/' });
expect(MockHistory.push).toHaveBeenCalledWith('/custom/app-path/path', undefined);
MockHistory.push.mockClear();
});

Expand Down
20 changes: 19 additions & 1 deletion src/core/public/application/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { removeSlashes } from './utils';
import { removeSlashes, appendAppPath } from './utils';

describe('removeSlashes', () => {
it('only removes duplicates by default', () => {
Expand Down Expand Up @@ -51,3 +51,21 @@ describe('removeSlashes', () => {
).toEqual('some/url/to');
});
});

describe('appendAppPath', () => {
it('appends the appBasePath with given path', () => {
expect(appendAppPath('/app/my-app', '/some-path')).toEqual('/app/my-app/some-path');
expect(appendAppPath('/app/my-app/', 'some-path')).toEqual('/app/my-app/some-path');
expect(appendAppPath('/app/my-app', 'some-path')).toEqual('/app/my-app/some-path');
expect(appendAppPath('/app/my-app', '')).toEqual('/app/my-app');
});

it('preserves the trailing slash only if included in the hash', () => {
expect(appendAppPath('/app/my-app', '/some-path/')).toEqual('/app/my-app/some-path');
expect(appendAppPath('/app/my-app', '/some-path#/')).toEqual('/app/my-app/some-path#/');
expect(appendAppPath('/app/my-app', '/some-path#/hash/')).toEqual(
'/app/my-app/some-path#/hash/'
);
expect(appendAppPath('/app/my-app', '/some-path#/hash')).toEqual('/app/my-app/some-path#/hash');
});
});

0 comments on commit 8fb0107

Please sign in to comment.