Skip to content

Commit

Permalink
fix(smalltalk) native: confirm, prompt: cancel: resolve -> do nothing (
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Jul 10, 2017
1 parent 4e4b6cb commit 43c2e40
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
8 changes: 7 additions & 1 deletion lib/smalltalk.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ exports.prompt = (title, message, value, options) => {
const noCancel = o && !o.cancel;
const result = prompt(message, value);

if (noCancel)
return;

if (result !== null)
return resolve(result);

Expand All @@ -33,7 +36,10 @@ exports.confirm = (title, message, options) => {
const promise = new Promise((resolve, reject) => {
const is = confirm(message);

if (is || noCancel)
if (noCancel)
return;

if (is)
return resolve();

reject();
Expand Down
25 changes: 17 additions & 8 deletions test/smalltalk.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ test('smalltalk.native: alert: result', (t) => {
});

test('smalltalk.native: confirm', (t) => {
const confirm = sinon.stub();
const confirm = sinon.stub().returns(false);
global.confirm = confirm;

smalltalk.confirm('title', 'message')
.catch(() => {
t.ok(confirm.calledWith('message'), 'confirm should have been called with message');
t.end();
});
.catch(() => {
t.ok(confirm.calledWith('message'), 'confirm should have been called with message');
t.end();
});
});

test('smalltalk.native: confirm: result: ok', (t) => {
Expand Down Expand Up @@ -70,13 +70,19 @@ test('smalltalk.native: confirm: options: cancel', (t) => {
const confirm = sinon.stub().returns(false);
global.confirm = confirm;

smalltalk.confirm('title', 'message', {cancel: false}).then(() => {
t.pass('should resolve');
const cancel = false;

smalltalk.confirm('title', 'message', {cancel}).then(() => {
t.fail('should not resolve');
t.end();
}).catch(() => {
t.fail('should not reject');
t.end();
});

t.pass('should do nothing');

t.end();
});

test('smalltalk.native: prompt', (t) => {
Expand Down Expand Up @@ -121,11 +127,14 @@ test('smalltalk.native: prompt: options: cancel', (t) => {
smalltalk.prompt('title', 'message', 'value', {
cancel: false
}).then(() => {
t.pass('should resolve');
t.fail('should not resolve');
t.end();
}).catch((e) => {
t.fail(`should not reject ${e.message}`);
t.end();
});

t.pass('should do nothing');
t.end();
});

0 comments on commit 43c2e40

Please sign in to comment.