From 58c58536c137268019a5ab39b2bbaaaba21f9df8 Mon Sep 17 00:00:00 2001 From: Oleksii Kurinnyi Date: Thu, 31 Aug 2023 15:09:33 +0300 Subject: [PATCH] fixup! chore: code cleanup --- .../src/preload/__tests__/index.spec.ts | 6 +++--- .../src/preload/__tests__/main.spec.ts | 21 ++++++------------- .../dashboard-frontend/src/preload/index.ts | 4 ++-- .../dashboard-frontend/src/preload/main.ts | 2 +- 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/packages/dashboard-frontend/src/preload/__tests__/index.spec.ts b/packages/dashboard-frontend/src/preload/__tests__/index.spec.ts index 502d87352..5d2951752 100644 --- a/packages/dashboard-frontend/src/preload/__tests__/index.spec.ts +++ b/packages/dashboard-frontend/src/preload/__tests__/index.spec.ts @@ -10,12 +10,12 @@ * Red Hat, Inc. - initial API and implementation */ -const mockMain = jest.fn(); +const mockRedirectToDashboard = jest.fn(); jest.mock('../main.ts', () => ({ - main: mockMain, + redirectToDashboard: mockRedirectToDashboard, })); it('should call main()', () => { require('../index.ts'); - expect(mockMain).toHaveBeenCalled(); + expect(mockRedirectToDashboard).toHaveBeenCalled(); }); diff --git a/packages/dashboard-frontend/src/preload/__tests__/main.spec.ts b/packages/dashboard-frontend/src/preload/__tests__/main.spec.ts index b84afe934..edc974979 100644 --- a/packages/dashboard-frontend/src/preload/__tests__/main.spec.ts +++ b/packages/dashboard-frontend/src/preload/__tests__/main.spec.ts @@ -12,7 +12,7 @@ import { REMOTES_ATTR } from '../../services/helpers/factoryFlow/buildFactoryParams'; import SessionStorageService, { SessionStorageKey } from '../../services/session-storage'; -import { main, buildFactoryLoaderPath, storePathIfNeeded } from '../main'; +import { redirectToDashboard, buildFactoryLoaderPath, storePathIfNeeded } from '../main'; describe('test buildFactoryLoaderPath()', () => { describe('SSHLocation', () => { @@ -158,7 +158,7 @@ describe('test storePathnameIfNeeded()', () => { }); }); -describe('test main()', () => { +describe('test redirectToDashboard()', () => { const origin = 'https://che-host'; let spyWindowLocation: jest.SpyInstance; @@ -166,20 +166,11 @@ describe('test main()', () => { spyWindowLocation.mockRestore(); }); - describe('known pathname', () => { - it('should not redirect', () => { - spyWindowLocation = createWindowLocationSpy(origin + '/dashboard/#/workspaces'); - - main(); - expect(spyWindowLocation).not.toHaveBeenCalled(); - }); - }); - describe('wrong pathname', () => { it('should redirect to home', () => { spyWindowLocation = createWindowLocationSpy(origin + '/test'); - main(); + redirectToDashboard(); expect(spyWindowLocation).toHaveBeenCalledWith(origin + '/dashboard/'); }); }); @@ -190,7 +181,7 @@ describe('test main()', () => { const query = 'new'; spyWindowLocation = createWindowLocationSpy(origin + '#' + repoUrl + '&' + query); - main(); + redirectToDashboard(); expect(spyWindowLocation).toHaveBeenCalledWith( origin + '/dashboard/f?policies.create=perclick&url=' + encodeURIComponent(repoUrl), ); @@ -201,7 +192,7 @@ describe('test main()', () => { const query = 'devfilePath=my-devfile.yaml'; spyWindowLocation = createWindowLocationSpy(origin + '#' + repoUrl + '&' + query); - main(); + redirectToDashboard(); expect(spyWindowLocation).toHaveBeenCalledWith( origin + '/dashboard/f?override.devfileFilename=my-devfile.yaml&url=' + @@ -215,7 +206,7 @@ describe('test main()', () => { const remoteUrl = '{https://origin-url,https://upstream-url}'; spyWindowLocation = createWindowLocationSpy(origin + '?' + REMOTES_ATTR + '=' + remoteUrl); - main(); + redirectToDashboard(); expect(spyWindowLocation).toHaveBeenCalledWith( origin + '/dashboard/f?remotes=' + encodeURIComponent(remoteUrl), ); diff --git a/packages/dashboard-frontend/src/preload/index.ts b/packages/dashboard-frontend/src/preload/index.ts index 371833b60..527a62a0c 100644 --- a/packages/dashboard-frontend/src/preload/index.ts +++ b/packages/dashboard-frontend/src/preload/index.ts @@ -10,8 +10,8 @@ * Red Hat, Inc. - initial API and implementation */ -import { main } from './main'; +import { redirectToDashboard } from './main'; (function (): void { - main(); + redirectToDashboard(); })(); diff --git a/packages/dashboard-frontend/src/preload/main.ts b/packages/dashboard-frontend/src/preload/main.ts index 192034d97..e7b28abc7 100644 --- a/packages/dashboard-frontend/src/preload/main.ts +++ b/packages/dashboard-frontend/src/preload/main.ts @@ -18,7 +18,7 @@ import { import { sanitizeLocation } from '../services/helpers/location'; import SessionStorageService, { SessionStorageKey } from '../services/session-storage'; -export function main(): void { +export function redirectToDashboard(): void { if (window.location.pathname.startsWith('/dashboard/')) { // known location, do nothing return;