diff --git a/bots/console/bot.js b/bots/console/bot.js index 16807bc0ac..74a9a52175 100644 --- a/bots/console/bot.js +++ b/bots/console/bot.js @@ -141,7 +141,10 @@ function getLastLevel(code) { var char = code[index]; if (char == ')') { level--; - nested = true; + // A single unbalanced ')' shouldn't set nested to true. + if (level > 0) { + nested = true; + } } if (char == '(') { level++; @@ -343,6 +346,8 @@ function jsSuggestions(params, context) { sugestionsMarkup ); return {markup: view}; + } else { + return {markup: null}; } } diff --git a/bots/console/test.js b/bots/console/test.js new file mode 100644 index 0000000000..35b396daba --- /dev/null +++ b/bots/console/test.js @@ -0,0 +1,42 @@ +// Run this in a node REPL +// .load test.js + +// Load dependencies +.load web3_metadata.js +.load bot.js + +// A map from current input text to suggestion titles +var suggestionTests = { + ",": [], + ")": [], + "(": [], + "a)": [], +// Expected? +// "a,": [], +// "a(": [], + "c": ["console"], + "console.": ["log(text)"] +}; + +// Mock localStorage, necessary for suggestions functions in bot.js +var STORE = {}; +var localStorage = function() {}; +localStorage.getItem = function(k) { return STORE[k]; }; +localStorage.setItem = function(k, v) { STORE[k] = v; }; + +var checkSuggestion = function(input) { + var suggestions = getJsSuggestions(input, {}); + var titles = suggestions.map(function(suggestion) { + return suggestion.title; + }); + var expectedTitles = suggestionTests[input]; + var iseq = JSON.stringify(titles) == JSON.stringify(expectedTitles); + console.log("CHECK", input, " ", iseq); + if (!iseq) { + console.log("EXPECTED", expectedTitles); + console.log("ACTUAL", titles); + } +}; + +// Run tests +Object.keys(suggestionTests).forEach(checkSuggestion); diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index d3cc6d6ce5..03c4225096 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -113,7 +113,7 @@ :<- [:chat :input-text] :<- [:chat-ui-props :validation-messages] (fn [[chat-parameter-box show-suggestions? input-text validation-messages]] - (and chat-parameter-box + (and (get chat-parameter-box :markup) (not validation-messages) (not show-suggestions?))))