Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-grant-work committed Jan 11, 2022
1 parent 145bfc2 commit f129560
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
12 changes: 12 additions & 0 deletions examples/api-tests/src/saveable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('Saveable', function () {
const { Disposable, DisposableCollection } = require('@theia/core/lib/common/disposable');

const container = window.theia.container;
/** @type {EditorManager} */
const editorManager = container.get(EditorManager);
const workspaceService = container.get(WorkspaceService);
const fileService = container.get(FileService);
Expand Down Expand Up @@ -266,6 +267,17 @@ describe('Saveable', function () {
assert.equal(state.value.trimRight(), 'bar', 'fs should be updated');
});

it('no save prompt when multiple editors open for same file', async () => {
const secondWidget = await editorManager.openToSide(fileUri);
editor.getControl().setValue('two widgets');
assert.isTrue(Saveable.isDirty(widget), 'the first widget should be dirty');
assert.isTrue(Saveable.isDirty(secondWidget), 'the second widget should also be dirty');
await Promise.resolve(secondWidget.close());
assert.isTrue(secondWidget.isDisposed, 'the widget should have closed without requesting user action');
assert.isTrue(Saveable.isDirty(widget), 'the original widget should still be dirty.');
assert.equal(editor.getControl().getValue(), 'two widgets', 'should still have the same value');
});

it('normal close', async () => {
editor.getControl().setValue('bar');
assert.isTrue(Saveable.isDirty(widget), 'should be dirty before before close');
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser/saveable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export namespace Saveable {
if (result) {
await Saveable.save(this);
}
await this.closeWithoutSaving(result);
await this.closeWithoutSaving();
}
} finally {
closing = false;
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/browser/shell/application-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1445,8 +1445,7 @@ export class ApplicationShell extends Widget {
* @return an array of all the widgets that were actually closed.
*/
async closeMany(targets: Widget[], options?: ApplicationShell.CloseOptions): Promise<Widget[]> {
const others = this.widgets.filter(widget => !targets.includes(widget));
if (options?.save === false || await Saveable.confirmSaveBeforeClose(targets, others)) {
if (options?.save === false || await Saveable.confirmSaveBeforeClose(targets, this.widgets.filter(widget => !targets.includes(widget)))) {
return (await Promise.all(targets.map(target => this.closeWidget(target.id, options)))).filter((widget): widget is Widget => widget !== undefined);
}
return [];
Expand Down

0 comments on commit f129560

Please sign in to comment.