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); const result = plugin.init(RENDER_PURPOSE_SEND);
// Make sure it returns result of showAlert() // Make sure it returns result of showAlert()
expect(result.app.alert()).toBe('dummy-return-value'); expect(result.app.alert('Title')).toBe('dummy-return-value');
expect(result.app.alert({title: 'My message'})).toBe('dummy-return-value'); expect(result.app.alert('Title', 'Message')).toBe('dummy-return-value');
// Make sure it passes correct arguments // Make sure it passes correct arguments
expect(modals.showAlert.mock.calls).toEqual([ expect(modals.showAlert.mock.calls).toEqual([
[{}], [{title: 'Title'}],
[{title: 'My message'}] [{title: 'Title', message: 'Message'}]
]); ]);
}); });
}); });
@ -62,13 +62,13 @@ describe('app.prompt()', () => {
const result = plugin.init(RENDER_PURPOSE_SEND); const result = plugin.init(RENDER_PURPOSE_SEND);
// Make sure it returns result of showAlert() // Make sure it returns result of showAlert()
result.app.prompt(); result.app.prompt('Title');
result.app.prompt({title: 'My message'}); result.app.prompt('Title', {label: 'Label'});
// Make sure it passes correct arguments // Make sure it passes correct arguments
expect(modals.showPrompt.mock.calls).toEqual([ expect(modals.showPrompt.mock.calls).toEqual([
[{cancelable: false, onComplete: expect.any(Function)}], [{title: 'Title', cancelable: false, onComplete: expect.any(Function)}],
[{cancelable: false, onComplete: expect.any(Function), title: 'My message'}] [{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} { export function init (renderPurpose?: string): {app: Object} {
return { return {
app: { app: {
alert (options: {title: string, message: string}): Promise<void> { alert (title: string, message?: string): Promise<void> {
if (renderPurpose !== RENDER_PURPOSE_SEND) { if (renderPurpose !== RENDER_PURPOSE_SEND) {
return Promise.resolve(); 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 || {}; options = options || {};
if (renderPurpose !== RENDER_PURPOSE_SEND) { if (renderPurpose !== RENDER_PURPOSE_SEND) {
@ -23,6 +30,7 @@ export function init (renderPurpose?: string): {app: Object} {
return new Promise(resolve => { return new Promise(resolve => {
showPrompt({ showPrompt({
title,
...(options || {}), ...(options || {}),
cancelable: false, cancelable: false,
onComplete (value: string) { onComplete (value: string) {