Skip to content

Commit

Permalink
fix(App): stop showing dialogs after first cancel
Browse files Browse the repository at this point in the history
closes #4186
  • Loading branch information
marstamm committed May 30, 2024
1 parent 577041f commit f53a9c7
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 7 deletions.
13 changes: 7 additions & 6 deletions client/src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -1992,13 +1992,14 @@ export class App extends PureComponent {
async quit() {
const { tabs } = this.state;

const quitTasks = tabs.map((tab) => {
return () => this.saveBeforeClose(tab);
});

const quitResults = await pSeries(quitTasks);
let canQuit = true;
for (const tab of tabs) {
canQuit = await this.saveBeforeClose(tab);

const canQuit = quitResults.every(result => result);
if (!canQuit) {
break;
}
}

try {
await this.workspaceChanged(false);
Expand Down
82 changes: 81 additions & 1 deletion client/src/app/__tests__/AppSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,86 @@ describe('<App>', function() {
});


it('should ask user to save or discard changes before quiting', async function() {

// given
const dialog = new Dialog();

const {
app
} = createApp({
globals: {
dialog
}
});

const showCloseFileDialogSpy = spy(dialog, 'showCloseFileDialog'),
saveTabSpy = spy(app, 'saveTab');

const tab = await app.createDiagram();

app.setState({
...app.setDirty(tab)
});

dialog.setShowCloseFileDialogResponse({ button: 'discard' });

// when
await app.quit();

// then
expect(showCloseFileDialogSpy).to.have.been.calledWith({
name: tab.file.name
});

expect(saveTabSpy).not.to.have.been.called;
});


it('should stop asking the user on cancel', async function() {

// given
const dialog = new Dialog();

const {
app
} = createApp({
globals: {
dialog
}
});

const showCloseFileDialogSpy = spy(dialog, 'showCloseFileDialog'),
saveTabSpy = spy(app, 'saveTab');

const tab = await app.createDiagram();
const tab2 = await app.createDiagram();


app.setState({
...app.setDirty(tab)
});

app.setState({
...app.setDirty(tab2)
});

dialog.setShowCloseFileDialogResponse({ button: 'cancel' });

// when
await app.quit();

// then
expect(showCloseFileDialogSpy).to.have.been.calledOnce;

expect(showCloseFileDialogSpy).to.have.been.calledWith({
name: tab.file.name
});

expect(saveTabSpy).not.to.have.been.called;
});


it('should not close tab when saving dialog is canceled', async function() {

// given
Expand Down Expand Up @@ -984,7 +1064,7 @@ describe('<App>', function() {
});


it('should save multiple times', async function() {
it('should save multiple times', async function() {

// given
const file = createFile('diagram_1.bpmn');
Expand Down

0 comments on commit f53a9c7

Please sign in to comment.