Make project workspace selectable if no workspace is open yet (#13508)

* allow new workspace location to be editable

* fix workspace inputbox not showing up after toggling open workspace radio buttons

* add a few tests

* cleanup

* fix errors

* addressing comments

* fix filter for windows

* add error message if existing workspace file is selected and change picker to be folder only

* address comments

* fix typos and update tests
This commit is contained in:
Kim Santiago
2020-12-14 13:24:36 -08:00
committed by GitHub
parent c2de462955
commit 1aaf80c3ab
8 changed files with 186 additions and 41 deletions

View File

@@ -7,6 +7,8 @@ import * as should from 'should';
import * as TypeMoq from 'typemoq';
import * as sinon from 'sinon';
import * as vscode from 'vscode';
import * as os from 'os';
import * as path from 'path';
import * as constants from '../../common/constants';
import { promises as fs } from 'fs';
import { WorkspaceService } from '../../services/workspaceService';
@@ -27,6 +29,8 @@ suite('Open Existing Dialog', function (): void {
dialog._targetTypeRadioCardGroup?.updateProperty( 'selectedCardId', constants.Project);
dialog._projectFile = '';
dialog.workspaceInputBox!.value = 'test.code-workspace';
should.equal(await dialog.validate(), false, 'Validation fail because project file does not exist');
// create a project file
@@ -49,6 +53,32 @@ suite('Open Existing Dialog', function (): void {
should.equal(await dialog.validate(), true, 'Validation pass because workspace file exists');
});
test('Should validate new workspace location', async function (): Promise<void> {
const workspaceServiceMock = TypeMoq.Mock.ofType<WorkspaceService>();
workspaceServiceMock.setup(x => x.getAllProjectTypes()).returns(() => Promise.resolve([testProjectType]));
const dialog = new OpenExistingDialog(workspaceServiceMock.object, mockExtensionContext.object);
await dialog.open();
dialog._projectFile = await createProjectFile('testproj');
dialog.workspaceInputBox!.value = 'test';
should.equal(await dialog.validate(), false, 'Validation should fail because workspace does not end in code-workspace');
// use invalid folder
dialog.workspaceInputBox!.value = 'invalidLocation/test.code-workspace';
should.equal(await dialog.validate(), false, 'Validation should fail because the folder is invalid');
// use already existing workspace
const existingWorkspaceFilePath = path.join(os.tmpdir(), `test.code-workspace`);
await fs.writeFile(existingWorkspaceFilePath, '');
dialog.workspaceInputBox!.value = existingWorkspaceFilePath;
should.equal(await dialog.validate(), false, 'Validation should fail because the selected workspace file already exists');
// change workspace name to something that should pass
dialog.workspaceInputBox!.value = path.join(os.tmpdir(), `TestWorkspace_${new Date().getTime()}.code-workspace`);
should.equal(await dialog.validate(), true, 'Validation should pass because the parent directory exists, workspace filepath is unique, and the file extension is correct');
});
test('Should validate workspace in onComplete when opening project', async function (): Promise<void> {
const workspaceServiceMock = TypeMoq.Mock.ofType<WorkspaceService>();
workspaceServiceMock.setup(x => x.validateWorkspace()).returns(() => Promise.resolve(true));