From 43c2e400f4d15352f4d2b170ef206b2a032f219e Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 10 Jul 2017 11:58:57 +0300 Subject: [PATCH] fix(smalltalk) native: confirm, prompt: cancel: resolve -> do nothing (coderaiser/cloudcmd/issues/117) --- lib/smalltalk.native.js | 8 +++++++- test/smalltalk.native.js | 25 +++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/smalltalk.native.js b/lib/smalltalk.native.js index 0003e5b..d9c1ebb 100644 --- a/lib/smalltalk.native.js +++ b/lib/smalltalk.native.js @@ -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); @@ -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(); diff --git a/test/smalltalk.native.js b/test/smalltalk.native.js index 3da5b28..c35c165 100644 --- a/test/smalltalk.native.js +++ b/test/smalltalk.native.js @@ -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) => { @@ -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) => { @@ -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(); });