mirror of
https://github.com/status-im/status-react.git
synced 2025-01-12 12:04:52 +00:00
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];
|
var char = code[index];
|
||||||
if (char == ')') {
|
if (char == ')') {
|
||||||
level--;
|
level--;
|
||||||
nested = true;
|
// A single unbalanced ')' shouldn't set nested to true.
|
||||||
|
if (level > 0) {
|
||||||
|
nested = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (char == '(') {
|
if (char == '(') {
|
||||||
level++;
|
level++;
|
||||||
@ -343,6 +346,8 @@ function jsSuggestions(params, context) {
|
|||||||
sugestionsMarkup
|
sugestionsMarkup
|
||||||
);
|
);
|
||||||
return {markup: view};
|
return {markup: view};
|
||||||
|
} else {
|
||||||
|
return {markup: null};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
42
bots/console/test.js
Normal file
42
bots/console/test.js
Normal file
@ -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 :input-text]
|
||||||
:<- [:chat-ui-props :validation-messages]
|
:<- [:chat-ui-props :validation-messages]
|
||||||
(fn [[chat-parameter-box show-suggestions? input-text 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 validation-messages)
|
||||||
(not show-suggestions?))))
|
(not show-suggestions?))))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user