Fix app context api

This commit is contained in:
Gregory Schier 2017-12-30 13:39:50 +01:00
parent da442a73d6
commit 11806d5007
2 changed files with 19 additions and 11 deletions

View File

@ -34,13 +34,13 @@ describe('app.alert()', () => {
const result = plugin.init(RENDER_PURPOSE_SEND);
// Make sure it returns result of showAlert()
expect(result.app.alert()).toBe('dummy-return-value');
expect(result.app.alert({title: 'My message'})).toBe('dummy-return-value');
expect(result.app.alert('Title')).toBe('dummy-return-value');
expect(result.app.alert('Title', 'Message')).toBe('dummy-return-value');
// Make sure it passes correct arguments
expect(modals.showAlert.mock.calls).toEqual([
[{}],
[{title: 'My message'}]
[{title: 'Title'}],
[{title: 'Title', message: 'Message'}]
]);
});
});
@ -62,13 +62,13 @@ describe('app.prompt()', () => {
const result = plugin.init(RENDER_PURPOSE_SEND);
// Make sure it returns result of showAlert()
result.app.prompt();
result.app.prompt({title: 'My message'});
result.app.prompt('Title');
result.app.prompt('Title', {label: 'Label'});
// Make sure it passes correct arguments
expect(modals.showPrompt.mock.calls).toEqual([
[{cancelable: false, onComplete: expect.any(Function)}],
[{cancelable: false, onComplete: expect.any(Function), title: 'My message'}]
[{title: 'Title', cancelable: false, onComplete: expect.any(Function)}],
[{title: 'Title', label: 'Label', cancelable: false, onComplete: expect.any(Function)}]
]);
});
});

View File

@ -7,14 +7,21 @@ import {RENDER_PURPOSE_SEND} from '../../common/render';
export function init (renderPurpose?: string): {app: Object} {
return {
app: {
alert (options: {title: string, message: string}): Promise<void> {
alert (title: string, message?: string): Promise<void> {
if (renderPurpose !== RENDER_PURPOSE_SEND) {
return Promise.resolve();
}
return showAlert(options || {});
return showAlert({title, message});
},
prompt (options: {title: string, label?: string, defaultValue?: string, submitName?: string}): Promise<string> {
prompt (
title: string,
options: {
label?: string,
defaultValue?: string,
submitName?: string
}
): Promise<string> {
options = options || {};
if (renderPurpose !== RENDER_PURPOSE_SEND) {
@ -23,6 +30,7 @@ export function init (renderPurpose?: string): {app: Object} {
return new Promise(resolve => {
showPrompt({
title,
...(options || {}),
cancelable: false,
onComplete (value: string) {