Attempt to fix no hint with unkown contexts
diff --git a/dev/js/spec/hintSpec.js b/dev/js/spec/hintSpec.js
index c944410..225ac37 100644
--- a/dev/js/spec/hintSpec.js
+++ b/dev/js/spec/hintSpec.js
@@ -137,6 +137,8 @@
expect(analyzer.test("sgbr/l=")).toEqual("sgbr/l=");
expect(analyzer.test("sgbr/lv=")).toEqual("sgbr/lv=");
expect(analyzer.test("sgbr/p=")).toEqual("sgbr/p=");
+ expect(analyzer.test("")).toEqual(undefined);
+ expect(analyzer.test("abcdecnx/")).toEqual("abcdecnx/");
});
});
@@ -195,7 +197,44 @@
expect(hint.alert().active).toBeFalsy();
expect(hint.active()).toBeFalsy();
+ });
+ it('should view main menu on default', function () {
+ var hint = hintClass.create({
+ inputField : input
+ });
+
+ expect(hint.active()).toBeFalsy();
+
+ hint.inputField().insert('der Baum corenlp/');
+ expect(hint.inputField().container().getElementsByTagName('div').length).toBe(1);
+ expect(hint.inputField().container().getElementsByTagName('ul').length).toBe(0);
+
+ // show with context
+ hint.unshow();
+ hint.show(true);
+
+ expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4);
+ expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
+
+ hint.inputField().insert(' hhhh');
+ // show with context
+ hint.unshow();
+ hint.show(true);
+
+ expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4);
+ expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
+
+ hint.unshow();
+ hint.inputField().insert(' aaaa/');
+
+ // show with context
+ hint.show(true);
+
+ console.log(hint.inputField().container().outerHTML);
+
+ expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4);
+ expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
});
});
@@ -410,7 +449,6 @@
});
describe('KorAP.HintMenu', function () {
-
var list = [
["Constituency", "c=", "Example 1"],
["Lemma", "l="],
@@ -452,7 +490,6 @@
menu.next();
expect(menu.shownItem(2).active()).toBeTruthy();
-
});
});
});
diff --git a/dev/js/src/hint.js b/dev/js/src/hint.js
index 455312d..89003ee 100644
--- a/dev/js/src/hint.js
+++ b/dev/js/src/hint.js
@@ -87,7 +87,6 @@
// create alert
c.appendChild(this._alert.element());
-
var that = this;
this._inputField.container().addEventListener('click', function (e) {
@@ -167,7 +166,6 @@
* Return hint menu and probably init based on an action
*/
menu : function (action) {
-
if (this._menu[action] === undefined) {
// No matching hint menu
@@ -189,10 +187,12 @@
*/
contextMenu : function (ifContext) {
var context = this._inputField.context();
+
if (context === undefined || context.length == 0)
return ifContext ? undefined : this.menu("-");
context = this._analyzer.test(context);
+
if (context === undefined || context.length == 0)
return ifContext ? undefined : this.menu("-");