Skip to content

Commit

Permalink
chore(dialog): return response instead of button
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Mar 18, 2020
1 parent b1102b4 commit e087fc7
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 25 deletions.
5 changes: 4 additions & 1 deletion app/lib/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ class Dialog {
return this.electronDialog.showMessageBox(
this.browserWindow, options
).then(response => {
return buttons[response.response].id;
return {
...response,
button: buttons[ response.response ].id
};
});
}

Expand Down
42 changes: 37 additions & 5 deletions app/test/spec/dialog-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('Dialog', function() {
expect(dialogArgs.title).to.equal('error');
expect(dialogArgs.buttons).to.have.length(2);

expect(result).to.equal('foo');
expect(result.button).to.equal('foo');
});


Expand Down Expand Up @@ -104,7 +104,7 @@ describe('Dialog', function() {
expect(dialogArgs.title).to.equal('warning');
expect(dialogArgs.buttons).to.have.length(2);

expect(result).to.equal('foo');
expect(result.button).to.equal('foo');
});


Expand Down Expand Up @@ -136,7 +136,7 @@ describe('Dialog', function() {
expect(dialogArgs.title).to.equal('info');
expect(dialogArgs.buttons).to.have.length(2);

expect(result).to.equal('foo');
expect(result.button).to.equal('foo');
});


Expand Down Expand Up @@ -168,7 +168,39 @@ describe('Dialog', function() {
expect(dialogArgs.title).to.equal('question');
expect(dialogArgs.buttons).to.have.length(2);

expect(result).to.equal('foo');
expect(result.button).to.equal('foo');
});


it('should show dialog with checkbox', async function() {

// given
electronDialog.setResponse({
checkboxChecked: true,
response: 0
});

var options = {
buttons: [{
id: 'foo',
label: 'Foo'
}],
title: 'info',
type: 'info',
checkboxLabel: 'Bar'
};

// when
const result = await dialog.showDialog(options);

// then
var dialogArgs = getDialogArgs(electronDialog.showMessageBox);

expect(electronDialog.showMessageBox).to.have.been.called;

expect(dialogArgs.checkboxLabel).to.equal('Bar');

expect(result.checkboxChecked).to.equal(true);
});

});
Expand Down Expand Up @@ -443,5 +475,5 @@ describe('Dialog', function() {
// helpers //////////

function getDialogArgs(method) {
return method.args[0][1];
return method.args[ 0 ][ 1 ];
}
22 changes: 11 additions & 11 deletions client/src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ export class App extends PureComponent {
return tab;
}

const answer = await this.showDialog(getContentChangedDialog());
const { button } = await this.showDialog(getContentChangedDialog());

if (answer === 'ok') {
if (button === 'ok') {
const updatedFile = await fileSystem.readFile(file.path);

return this.updateTab(tab, {
Expand Down Expand Up @@ -370,11 +370,11 @@ export class App extends PureComponent {
const { name } = file;

if (this.isDirty(tab)) {
const response = await this.showCloseFileDialog({ name });
const { button } = await this.showCloseFileDialog({ name });

if (response === 'save') {
if (button === 'save') {
await this.saveTab(tab);
} else if (response === 'cancel') {
} else if (button === 'cancel') {
return false;
}
}
Expand Down Expand Up @@ -548,12 +548,12 @@ export class App extends PureComponent {
return;
}

const response = await dialog.showEmptyFileDialog({
const { button } = await dialog.showEmptyFileDialog({
file,
type: fileType
});

if (response == 'create') {
if (button == 'create') {

let tab = this.addTab(
tabsProvider.createTabForFile({
Expand Down Expand Up @@ -1328,9 +1328,9 @@ export class App extends PureComponent {
return this.tabSaved(tab, savedFile);
} catch (err) {

const response = await this.askForSaveRetry(tab, err, getSaveFileErrorDialog);
const { button } = await this.askForSaveRetry(tab, err, getSaveFileErrorDialog);

if (response !== 'retry') {
if (button !== 'retry') {

// cancel
return false;
Expand Down Expand Up @@ -1519,9 +1519,9 @@ export class App extends PureComponent {
} catch (err) {
console.error('Tab export failed', err);

const response = await this.askForSaveRetry(tab, err, getExportFileErrorDialog);
const { button } = await this.askForSaveRetry(tab, err, getExportFileErrorDialog);

if (response !== 'retry') {
if (button !== 'retry') {

// cancel
return;
Expand Down
4 changes: 3 additions & 1 deletion client/src/app/__tests__/AppSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,9 @@ describe('<App>', function() {

// given
const showSpy = spy(_ => {
return 'ok';
return {
button: 'ok'
};
});

const dialog = new Dialog({
Expand Down
4 changes: 2 additions & 2 deletions client/src/app/tabs/MultiSheetTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ export class MultiSheetTab extends CachedComponent {
type
} = tab;

const answer = await onAction('show-dialog', getErrorDialog({
const { button } = await onAction('show-dialog', getErrorDialog({
error,
name,
type
}));

if (answer === 'ask-in-forum') {
if (button === 'ask-in-forum') {
onAction('open-external-url', {
url: 'https://forum.camunda.org/c/modeler'
});
Expand Down
4 changes: 3 additions & 1 deletion client/src/app/tabs/__tests__/MultiSheetTabSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ describe('<MultiSheetTab>', function() {
// given
const actionSpy = spy(action => {
if (action === 'show-dialog') {
return 'ask-in-forum';
return {
button: 'ask-in-forum'
};
}
});

Expand Down
5 changes: 2 additions & 3 deletions client/src/app/tabs/bpmn/BpmnEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,9 @@ export class BpmnEditor extends CachedComponent {
}

async shouldConvert() {
const { button } = await this.props.onAction('show-dialog', getNamespaceDialog());

const answer = await this.props.onAction('show-dialog', getNamespaceDialog());

return answer === 'yes';
return button === 'yes';
}

handleImport = (error, warnings) => {
Expand Down
4 changes: 3 additions & 1 deletion client/src/app/tabs/bpmn/__tests__/BpmnEditorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,9 @@ describe('<BpmnEditor>', function() {

// given
const onContentUpdated = sinon.spy();
const onAction = sinon.stub().resolves('yes');
const onAction = sinon.stub().resolves({
button: 'yes'
});

// when
renderEditor(activitiXML, {
Expand Down

0 comments on commit e087fc7

Please sign in to comment.