diff --git a/client/commonFramework/bindings.js b/client/commonFramework/bindings.js index b994eca55e..37009a8a2a 100644 --- a/client/commonFramework/bindings.js +++ b/client/commonFramework/bindings.js @@ -1,10 +1,16 @@ -window.common = (function({ $, Rx, common = { init: [] }}) { +window.common = (function(global) { + const { + $, + Rx: { Observable }, + common = { init: [] } + } = global; common.ctrlEnterClickHandler = function ctrlEnterClickHandler(e) { // ctrl + enter or cmd + enter if ( - e.metaKey && e.keyCode === 13 || - e.ctrlKey && e.keyCode === 13 + e.keyCode === 13 && + e.metaKey || + e.ctrlKey ) { $('#complete-courseware-dialog').off('keydown', ctrlEnterClickHandler); if ($('#submit-challenge').length > 0) { @@ -20,6 +26,10 @@ window.common = (function({ $, Rx, common = { init: [] }}) { var $marginFix = $('.innerMarginFix'); $marginFix.css('min-height', $marginFix.height()); + common.submitBtn$ = Observable.fromEvent($('#submitButton'), 'click'); + + common.resetBtn$ = Observable.fromEvent($('#reset-button'), 'click'); + // init modal keybindings on open $('#complete-courseware-dialog').on('shown.bs.modal', function() { $('#complete-courseware-dialog').keydown(common.ctrlEnterClickHandler); @@ -127,10 +137,6 @@ window.common = (function({ $, Rx, common = { init: [] }}) { } }); - common.submitBtn$ = Rx.Observable.fromEvent($('#submitButton'), 'click'); - - common.resetBtn$ = Rx.Observable.fromEvent($('#reset-button'), 'click'); - if (common.challengeName) { window.ga('send', 'event', 'Challenge', 'load', common.challengeName); } diff --git a/client/commonFramework/end.js b/client/commonFramework/end.js index 4a76e9fb58..0ae61ad01c 100644 --- a/client/commonFramework/end.js +++ b/client/commonFramework/end.js @@ -25,15 +25,25 @@ $(document).ready(function() { } ); - common.submitBtn$ + Observable.merge( + common.editorExecute$, + common.submitBtn$ + ) .flatMap(() => { + common.appendToOutputDisplay('\n// testing challenge...'); return common.executeChallenge$(); }) + .map(({ tests, ...rest }) => { + const solved = tests.every(test => !test.err); + return { ...rest, tests, solved }; + }) .subscribe( - ({ output, original, tests }) => { + ({ solved, output, tests }) => { common.updateOutputDisplay(output); - common.codeStorage.updateStorage(challengeName, original); common.displayTestResults(tests); + if (solved) { + common.showCompletion(); + } } ); @@ -58,9 +68,9 @@ $(document).ready(function() { ) { common.executeChallenge$() .subscribe( - ({ original }) => { - // common.updateOutputDisplay('' + output); + ({ original, tests }) => { common.codeStorage.updateStorage(challengeName, original); + common.displayTestResults(tests); }, ({ err }) => { if (err.stack) { diff --git a/client/commonFramework/output-display.js b/client/commonFramework/output-display.js index 7842e16da8..3220510db8 100644 --- a/client/commonFramework/output-display.js +++ b/client/commonFramework/output-display.js @@ -33,7 +33,7 @@ window.common = (function(global) { * Console.log() -type statements * will appear in your browser\'s * DevTools JavaScript console. - */'`); + */`); codeOutput.setSize('100%', '100%'); diff --git a/client/commonFramework/show-completion.js b/client/commonFramework/show-completion.js index b4c4998e8e..434bb685fe 100644 --- a/client/commonFramework/show-completion.js +++ b/client/commonFramework/show-completion.js @@ -6,7 +6,7 @@ window.common = (function(global) { } = global; common.showCompletion = function showCompletion() { - var time = Math.floor(Date.now()) - window.started; + var time = Math.floor(Date.now() - window.started); ga( 'send', diff --git a/client/plugin.js b/client/plugin.js index 2cc3c54904..c6fd8f793a 100644 --- a/client/plugin.js +++ b/client/plugin.js @@ -20,7 +20,7 @@ function run(code, cb) { result.type = typeof codeExec; result.output = stringify(codeExec); } catch (e) { - err = e.mesage; + err = e.message; } if (err) {