console: amend fix of #1207 (bad suggestions)
A single unbalanced ')' shouldn't count as nesting, so ')' and 'a)' etc don't make the form ''. console: add ad-hoc test script for suggestions This creates a quicker feedback loop for testing console suggestions, as well as making sure we don't introduce suggestions regressions. chat, parameter-box: hide parameter-box when {markup: null} is returned
This commit is contained in:
parent
be503447ee
commit
389e79d683
|
@ -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};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
|
@ -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?))))
|
||||
|
||||
|
|
Loading…
Reference in New Issue