Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(App): stop showing dialogs after first cancel #4323

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No magic, plain JS implementation 🚀

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