-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! fixup! fixup! fixup! feat: implement an ability to start works…
…paces in Safe Mode
- Loading branch information
Showing
6 changed files
with
209 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...Progress/StartingSteps/StartWorkspace/__tests__/__snapshots__/prepareRestart.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ProgressStepTitle snapshot - non-active step 1`] = ` | ||
Object { | ||
"search": "tab=Progress", | ||
} | ||
`; |
92 changes: 92 additions & 0 deletions
92
...omponents/WorkspaceProgress/StartingSteps/StartWorkspace/__tests__/prepareRestart.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (c) 2018-2023 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
|
||
import { | ||
applyStartWorkspace, | ||
applyRestartDefaultLocation, | ||
applyRestartInDebugModeLocation, | ||
applyRestartInSafeModeLocation, | ||
resetRestartInSafeModeLocation, | ||
} from '../prepareRestart'; | ||
import { Location } from 'history'; | ||
import { DevWorkspaceBuilder } from '../../../../../store/__mocks__/devWorkspaceBuilder'; | ||
import { constructWorkspace } from '../../../../../services/workspace-adapter'; | ||
|
||
describe('Prepare workspace start', () => { | ||
const startCallback = jest.fn(); | ||
|
||
beforeEach(() => { | ||
startCallback.mockResolvedValueOnce(Promise.resolve()); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('apply Safe Mode location', () => { | ||
const location = { search: '?tab=Progress' } as Location<unknown>; | ||
|
||
applyRestartInDebugModeLocation(location); | ||
|
||
expect(location).toEqual({ search: 'tab=Progress&debugWorkspaceStart=true' }); | ||
}); | ||
|
||
test('apply Safe Mode location', () => { | ||
const location = { search: '?tab=Progress' } as Location<unknown>; | ||
|
||
applyRestartInSafeModeLocation(location); | ||
|
||
expect(location).toEqual({ search: 'tab=Progress&useDefaultDevfile=true' }); | ||
}); | ||
|
||
test('apply default location', () => { | ||
const location = { search: '?debugWorkspaceStart=true&tab=Logs' } as Location<unknown>; | ||
|
||
applyRestartDefaultLocation(location); | ||
|
||
expect(location).toEqual({ search: 'tab=Logs' }); | ||
}); | ||
|
||
test('reset Safe Mode location', () => { | ||
const location = { search: '?tab=Logs&useDefaultDevfile=true' } as Location<unknown>; | ||
|
||
let hasChanged = resetRestartInSafeModeLocation(location); | ||
|
||
expect(hasChanged).toBeTruthy(); | ||
expect(location).toEqual({ search: 'tab=Logs' }); | ||
|
||
hasChanged = resetRestartInSafeModeLocation(location); | ||
|
||
expect(hasChanged).toBeFalsy(); | ||
expect(location).toEqual({ search: 'tab=Logs' }); | ||
}); | ||
|
||
test('apply start workspace', async () => { | ||
const workspace = constructWorkspace(new DevWorkspaceBuilder().build()); | ||
const location = { search: '' } as Location<unknown>; | ||
|
||
await applyStartWorkspace(startCallback, workspace, location); | ||
|
||
expect(startCallback).toBeCalledWith(workspace, undefined); | ||
}); | ||
|
||
test('apply start workspace in Debug Mode', async () => { | ||
const workspace = constructWorkspace(new DevWorkspaceBuilder().build()); | ||
const location = { search: '?debugWorkspaceStart=true' } as Location<unknown>; | ||
|
||
await applyStartWorkspace(startCallback, workspace, location); | ||
|
||
expect(startCallback).toBeCalledWith(workspace, { | ||
'debug-workspace-start': true, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...-frontend/src/components/WorkspaceProgress/StartingSteps/StartWorkspace/prepareRestart.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2018-2023 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
|
||
import { Location } from 'history'; | ||
import { | ||
DEBUG_WORKSPACE_START, | ||
USE_DEFAULT_DEVFILE, | ||
} from '../../../../services/helpers/factoryFlow/buildFactoryParams'; | ||
import { Workspace } from '../../../../services/workspace-adapter'; | ||
import { ResourceQueryParams } from '../../../../store/Workspaces'; | ||
|
||
export function applyRestartDefaultLocation(location: Location): void { | ||
const searchParams = new URLSearchParams(location.search); | ||
searchParams.delete(DEBUG_WORKSPACE_START); | ||
searchParams.delete(USE_DEFAULT_DEVFILE); | ||
location.search = searchParams.toString(); | ||
} | ||
|
||
export function applyRestartInDebugModeLocation(location: Location): void { | ||
const searchParams = new URLSearchParams(location.search); | ||
searchParams.set(DEBUG_WORKSPACE_START, 'true'); | ||
searchParams.delete(USE_DEFAULT_DEVFILE); | ||
location.search = searchParams.toString(); | ||
} | ||
|
||
export function applyRestartInSafeModeLocation(location: Location): void { | ||
const searchParams = new URLSearchParams(location.search); | ||
searchParams.set(USE_DEFAULT_DEVFILE, 'true'); | ||
searchParams.delete(DEBUG_WORKSPACE_START); | ||
location.search = searchParams.toString(); | ||
} | ||
|
||
export function resetRestartInSafeModeLocation(location: Location): boolean { | ||
const searchParams = new URLSearchParams(location.search); | ||
const safeMode = searchParams.get(USE_DEFAULT_DEVFILE) === 'true'; | ||
if (safeMode) { | ||
searchParams.delete(USE_DEFAULT_DEVFILE); | ||
location.search = searchParams.toString(); | ||
} | ||
return safeMode; | ||
} | ||
|
||
export async function applyStartWorkspace( | ||
startCallback: (workspace: Workspace, params?: ResourceQueryParams | undefined) => Promise<void>, | ||
workspace: Workspace, | ||
location: Location, | ||
): Promise<void> { | ||
const searchParams = new URLSearchParams(location.search); | ||
const params = | ||
searchParams.get(DEBUG_WORKSPACE_START) === 'true' | ||
? { | ||
'debug-workspace-start': true, | ||
} | ||
: undefined; | ||
await startCallback(workspace, params); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters