Skip to content

Commit

Permalink
fix(RemoveFileCommand): ensure only delete file tab was closed
Browse files Browse the repository at this point in the history
  • Loading branch information
sleistner committed Aug 26, 2019
1 parent 881983b commit 557e794
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
3 changes: 1 addition & 2 deletions src/command/RemoveFileCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ export class RemoveFileCommand extends BaseCommand {
public async execute(uri?: Uri) {
const fileItem = await this.controller.showDialog();
if (fileItem) {
await this.controller.execute({ fileItem });
return this.controller.closeCurrentFileEditor();
return this.controller.execute({ fileItem });
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/controller/RemoveFileController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class RemoveFileController extends BaseFileController {
throw new Error();
}

if (!this.confirmDelete) {
if (this.confirmDelete === false) {
return new FileItem(sourcePath);
}

Expand Down
26 changes: 5 additions & 21 deletions test/command/RemoveFileCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ describe('RemoveFileCommand', () => {
beforeEach(async () => {
await helper.openDocument(helper.editorFile1);
helper.createShowInformationMessageStub().resolves(helper.targetFile.path);
helper.createGetConfigurationStub({});
});

afterEach(async () => {
await helper.closeAllEditors();
helper.restoreShowInformationMessage();
helper.restoreGetConfiguration();
});

describe('configuration', () => {
afterEach(async () => helper.restoreGetConfiguration());

describe('delete.useTrash set to false', () => {
beforeEach(async () => {
helper.createGetConfigurationStub({ 'delete.useTrash': false, 'delete.confirm': true });
Expand Down Expand Up @@ -67,7 +67,9 @@ describe('RemoveFileCommand', () => {
});

describe('responding with no', () => {
beforeEach(async () => helper.createShowInformationMessageStub().resolves(false));
beforeEach(async () => {
helper.createShowInformationMessageStub().resolves(false);
});

it('leaves the file untouched', async () => {
try {
Expand All @@ -85,31 +87,13 @@ describe('RemoveFileCommand', () => {
helper.createGetConfigurationStub({ 'delete.useTrash': false, 'delete.confirm': false });
});

afterEach(async () => helper.restoreGetConfiguration());

it('deletes the file without confirmation', async () => {
await subject.execute();
const message = `${helper.editorFile1.path} does not exist`;
expect(window.showInformationMessage).to.have.not.been.called;
expect(fs.existsSync(helper.editorFile1.fsPath), message).to.be.false;
});
});

it('closes file editor', async () => {
let activeEditor;

const retryable = async () => {
await subject.execute();
activeEditor = window.activeTextEditor;

if (activeEditor) {
throw new Error();
}
};

await retry(retryable, { max_tries: 4, interval: 500 });
expect(activeEditor).to.not.exist;
});
});

describe('with no open text document', () => {
Expand Down

0 comments on commit 557e794

Please sign in to comment.