Skip to content

Commit

Permalink
Fix feedback and add test
Browse files Browse the repository at this point in the history
Signed-off-by: David Kwon <dakwon@redhat.com>
  • Loading branch information
dkwon17 committed Jun 16, 2022
1 parent 4a4d43c commit 06cc24e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ export class IssueComponent extends React.PureComponent<Props> {
};
};

let ideLoader;
let workspaceDetails;
let ideLoader: React.ReactNode;
let workspaceDetails: React.ReactNode;

if (workspaceRoutes) {
ideLoader = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* Red Hat, Inc. - initial API and implementation
*/

import { buildFactoryLoaderPath } from '../';
import SessionStorageService, { SessionStorageKey } from '../../services/session-storage';
import { buildFactoryLoaderPath, storePathIfNeeded } from '../';

describe('Location test', () => {
test('new policy', () => {
Expand Down Expand Up @@ -49,3 +50,22 @@ describe('Location test', () => {
);
});
});

describe('storePathnameIfNeeded test', () => {
let mockUpdate: jest.Mock;

beforeAll(() => {
mockUpdate = jest.fn();
SessionStorageService.update = mockUpdate;
});

test('empty path', () => {
storePathIfNeeded('/');
expect(mockUpdate).toBeCalledTimes(0);
});

test('regular path', () => {
storePathIfNeeded('/test');
expect(mockUpdate).toBeCalledWith(SessionStorageKey.ORIGINAL_LOCATION_PATH, '/test');
});
});
13 changes: 7 additions & 6 deletions packages/dashboard-frontend/src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ import SessionStorageService, { SessionStorageKey } from '../services/session-st
return;
}

if (window.location.pathname !== '/') {
SessionStorageService.update(
SessionStorageKey.ORIGINAL_LOCATION_PATH,
window.location.pathname,
);
}
storePathIfNeeded(window.location.pathname);

const hash = window.location.hash.replace(/(\/?)#(\/?)/, '#');
if (hash.startsWith('#http')) {
Expand All @@ -37,6 +32,12 @@ import SessionStorageService, { SessionStorageKey } from '../services/session-st
}
})();

export function storePathIfNeeded(path: string) {
if (path !== '/') {
SessionStorageService.update(SessionStorageKey.ORIGINAL_LOCATION_PATH, path);
}
}

export function buildFactoryLoaderPath(url: string): string {
const fullUrl = new window.URL(url);
const editor = extractUrlParam(fullUrl, 'che-editor');
Expand Down
4 changes: 2 additions & 2 deletions packages/dashboard-frontend/src/services/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ export default class Bootstrap {
return;
}

if (workspace.isRunning) {
window.location.href = workspace.ideUrl!;
if (workspace.isRunning && workspace.ideUrl) {
window.location.href = workspace.ideUrl;
return;
}

Expand Down

0 comments on commit 06cc24e

Please sign in to comment.