Test suite now relies on requirejs as well
diff --git a/dev/js/runner/hint.html b/dev/js/runner/hint.html
index b9028b9..2ec1c9a 100644
--- a/dev/js/runner/hint.html
+++ b/dev/js/runner/hint.html
@@ -5,13 +5,28 @@
<title>Spec Runner for Hint Helper</title>
<link rel="shortcut icon" type="image/png" href="../lib/jasmine-2.1.1/jasmine_favicon.png">
<link rel="stylesheet" href="../lib/jasmine-2.1.1/jasmine.css">
+ <script src="../lib/require.js"></script>
<script src="../lib/jasmine-2.1.1/jasmine.js"></script>
<script src="../lib/jasmine-2.1.1/jasmine-html.js"></script>
<script src="../lib/jasmine-2.1.1/boot.js"></script>
- <script src="../src/menu.js"></script>
- <script src="../src/hint.js"></script>
+ <script>
+ require.config({
+ baseUrl: "../src",
+ paths: {
+ "lib" : "../lib",
+ "spec" : "../spec"
+ }
+ });
+ require([
+ 'lib/domReady!',
+ 'spec/hintSpec'
+ ],
+ function () {
+ if (jsApiReporter.finished === true)
+ jasmine.getEnv().execute();
+ });
+ </script>
</head>
<body>
</body>
- <script src="../spec/hintSpec.js"></script>
</html>
diff --git a/dev/js/runner/match.html b/dev/js/runner/match.html
index 553fae7..564acab 100644
--- a/dev/js/runner/match.html
+++ b/dev/js/runner/match.html
@@ -5,13 +5,27 @@
<title>Spec Runner for Morph Table View</title>
<link rel="shortcut icon" type="image/png" href="../lib/jasmine-2.1.1/jasmine_favicon.png">
<link rel="stylesheet" href="../lib/jasmine-2.1.1/jasmine.css">
+ <script src="../lib/require.js"></script>
<script src="../lib/jasmine-2.1.1/jasmine.js"></script>
<script src="../lib/jasmine-2.1.1/jasmine-html.js"></script>
<script src="../lib/jasmine-2.1.1/boot.js"></script>
- <script src="../lib/dagre/dagre.min.js"></script>
- <script src="../src/menu.js"></script>
- <script src="../src/match.js"></script>
- <script src="../spec/matchSpec.js"></script>
+ <script>
+ require.config({
+ baseUrl: "../src",
+ paths: {
+ "lib" : "../lib",
+ "spec" : "../spec"
+ }
+ });
+ require([
+ 'lib/domReady!',
+ 'spec/matchSpec'
+ ],
+ function () {
+ if (jsApiReporter.finished === true)
+ jasmine.getEnv().execute();
+ });
+ </script>
</head>
<body>
</body>
diff --git a/dev/js/runner/menu.html b/dev/js/runner/menu.html
index 2b05abc..acf96d4 100644
--- a/dev/js/runner/menu.html
+++ b/dev/js/runner/menu.html
@@ -5,11 +5,27 @@
<title>Spec Runner for Menu Helper</title>
<link rel="shortcut icon" type="image/png" href="../lib/jasmine-2.1.1/jasmine_favicon.png">
<link rel="stylesheet" href="../lib/jasmine-2.1.1/jasmine.css">
+ <script src="../lib/require.js"></script>
<script src="../lib/jasmine-2.1.1/jasmine.js"></script>
<script src="../lib/jasmine-2.1.1/jasmine-html.js"></script>
<script src="../lib/jasmine-2.1.1/boot.js"></script>
- <script src="../src/menu.js"></script>
- <script src="../spec/menuSpec.js"></script>
+ <script>
+ require.config({
+ baseUrl: "../src",
+ paths: {
+ "lib" : "../lib",
+ "spec" : "../spec"
+ }
+ });
+ require([
+ 'lib/domReady!',
+ 'spec/menuSpec'
+ ],
+ function () {
+ if (jsApiReporter.finished === true)
+ jasmine.getEnv().execute();
+ });
+ </script>
</head>
<body>
</body>
diff --git a/dev/js/runner/vc.html b/dev/js/runner/vc.html
index f0e8179..2653bb4 100644
--- a/dev/js/runner/vc.html
+++ b/dev/js/runner/vc.html
@@ -1,17 +1,32 @@
<!DOCTYPE html>
<html>
-<head>
- <meta charset="utf-8">
- <title>Spec Runner for Virtual Collection Builder</title>
- <link rel="shortcut icon" type="image/png" href="../lib/jasmine-2.1.1/jasmine_favicon.png">
- <link rel="stylesheet" href="../lib/jasmine-2.1.1/jasmine.css">
- <script src="../lib/jasmine-2.1.1/jasmine.js"></script>
- <script src="../lib/jasmine-2.1.1/jasmine-html.js"></script>
- <script src="../lib/jasmine-2.1.1/boot.js"></script>
- <script src="../src/menu.js"></script>
- <script src="../src/vc.js"></script>
- <script src="../spec/vcSpec.js"></script>
-</head>
-<body>
-</body>
+ <head>
+ <meta charset="utf-8">
+ <title>Spec Runner for Virtual Collection Builder</title>
+ <link rel="shortcut icon" type="image/png" href="../lib/jasmine-2.1.1/jasmine_favicon.png">
+ <link rel="stylesheet" href="../lib/jasmine-2.1.1/jasmine.css">
+ <script src="../lib/require.js"></script>
+ <script src="../lib/jasmine-2.1.1/jasmine.js"></script>
+ <script src="../lib/jasmine-2.1.1/jasmine-html.js"></script>
+ <script src="../lib/jasmine-2.1.1/boot.js"></script>
+ <script>
+ require.config({
+ baseUrl: "../src",
+ paths: {
+ "lib" : "../lib",
+ "spec" : "../spec"
+ }
+ });
+ require([
+ 'lib/domReady!',
+ 'spec/vcSpec'
+ ],
+ function () {
+ if (jsApiReporter.finished === true)
+ jasmine.getEnv().execute();
+ });
+ </script>
+ </head>
+ <body>
+ </body>
</html>
diff --git a/dev/js/spec/hintSpec.js b/dev/js/spec/hintSpec.js
index 45457b4..20935e1 100644
--- a/dev/js/spec/hintSpec.js
+++ b/dev/js/spec/hintSpec.js
@@ -5,7 +5,6 @@
var keyboardEvent = document.createEvent("KeyboardEvent");
var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ?
"initKeyboardEvent" : "initKeyEvent";
-
keyboardEvent[initMethod](
type,
true, // bubbles
@@ -19,394 +18,393 @@
0 // charCodeArgs : unsigned long the Unicode character
// associated with the depressed key, else 0
);
-
element.dispatchEvent(keyboardEvent);
};
-describe('KorAP.InputField', function () {
- var input;
+define(['hint'], function () {
- beforeEach(function () {
- input = document.createElement("input");
- input.setAttribute('type', "text");
- input.setAttribute("value", "abcdefghijklmno");
- input.style.position = 'absolute';
- document.getElementsByTagName('body')[0].appendChild(input);
- input.style.top = "20px";
- input.style.left = "30px";
- input.focus();
- input.selectionStart = 5;
- });
+ var hintClass = require("hint");
+ var inputClass = require("hint/input");
+ var contextClass = require("hint/contextanalyzer");
+ var menuClass = require("hint/menu");
+ var menuItemClass = require("hint/item");
- afterEach(function () {
- document.getElementsByTagName("body")[0].removeChild(
- input
- );
- });
+ describe('KorAP.InputField', function () {
+ var input;
- afterAll(function () {
- try {
- document.getElementsByTagName("body")[0].removeChild(
- document.getElementById("searchMirror")
- );
- }
- catch (e) {};
- });
-
- it('should be initializable', function () {
- // Supports: context, searchField
- var inputField = KorAP.InputField.create(input);
- expect(inputField._element).not.toBe(undefined);
- });
-
- it('should have text', function () {
- expect(input.value).toEqual('abcdefghijklmno');
- var inputField = KorAP.InputField.create(input);
-
- expect(inputField.value()).toEqual("abcdefghijklmno");
-
- expect(input.selectionStart).toEqual(5);
- expect(inputField.element().selectionStart).toEqual(5);
- expect(inputField.split()[0]).toEqual("abcde");
- expect(inputField.split()[1]).toEqual("fghijklmno");
-
- inputField.insert("xyz");
- expect(inputField.value()).toEqual('abcdexyzfghijklmno');
- expect(inputField.split()[0]).toEqual("abcdexyz");
- expect(inputField.split()[1]).toEqual("fghijklmno");
- });
-
- it('should be correctly positioned', function () {
- expect(input.value).toEqual('abcdefghijklmno');
- var inputField = KorAP.InputField.create(input);
- document.getElementsByTagName("body")[0].appendChild(input);
- inputField.reposition();
- expect(input.style.left).toEqual("30px");
- expect(inputField.mirror().style.left.match(/^(\d+)px$/)[1]).toBeGreaterThan(29);
- expect(inputField.mirror().style.top.match(/^(\d+)px$/)[1]).toBeGreaterThan(20);
- });
-
- it('should have a correct context', function () {
- expect(input.value).toEqual('abcdefghijklmno');
- var inputField = KorAP.InputField.create(input);
-
- expect(inputField.value()).toEqual("abcdefghijklmno");
-
- expect(inputField.element().selectionStart).toEqual(5);
- expect(inputField.split()[0]).toEqual("abcde");
- expect(inputField.context()).toEqual("abcde");
- });
-
-/*
- it('should be correctly triggerable', function () {
- // https://developer.mozilla.org/samples/domref/dispatchEvent.html
- var hint = KorAP.Hint.create({ "inputField" : input });
- emitKeyboardEvent(hint.inputField.element, "keypress", 20);
- });
-*/
-});
-
-
-describe('KorAP.ContextAnalyzer', function () {
- it('should be initializable', function () {
- var analyzer = KorAP.ContextAnalyzer.create(")");
- expect(analyzer).toBe(undefined);
-
- analyzer = KorAP.ContextAnalyzer.create(".+?");
- expect(analyzer).not.toBe(undefined);
-
- });
-
- it('should check correctly', function () {
- analyzer = KorAP.ContextAnalyzer.create(KorAP.context);
- expect(analyzer.test("cnx/]cnx/c=")).toEqual("cnx/c=");
- expect(analyzer.test("cnx/c=")).toEqual("cnx/c=");
- expect(analyzer.test("cnx/c=np mate/m=mood:")).toEqual("mate/m=mood:");
- expect(analyzer.test("impcnx/")).toEqual("impcnx/");
- expect(analyzer.test("cnx/c=npcnx/")).toEqual("npcnx/");
- expect(analyzer.test("mate/m=degree:pos corenlp/ne_dewac_175m_600="))
- .toEqual("corenlp/ne_dewac_175m_600=");
- });
-});
-
-
-describe('KorAP.Hint', function () {
- KorAP.hintArray = {
- "corenlp/" : [
- ["Named Entity", "ne=" , "Combined"],
- ["Named Entity", "ne_dewac_175m_600=" , "ne_dewac_175m_600"],
- ["Named Entity", "ne_hgc_175m_600=", "ne_hgc_175m_600"]
- ]
- };
-
- beforeEach(function () {
- input = document.createElement("input");
- input.setAttribute("type", "text");
- input.setAttribute("value", "abcdefghijklmno");
- input.style.position = 'absolute';
- input.style.top = "20px";
- input.style.left = "30px";
- input.focus();
- input.selectionStart = 5;
- });
-
- it('should be initializable', function () {
- // Supports: context, searchField
- var hint = KorAP.Hint.create({
- inputField : input
+ beforeEach(function () {
+ input = document.createElement("input");
+ input.setAttribute('type', "text");
+ input.setAttribute("value", "abcdefghijklmno");
+ input.style.position = 'absolute';
+ document.getElementsByTagName('body')[0].appendChild(input);
+ input.style.top = "20px";
+ input.style.left = "30px";
+ input.focus();
+ input.selectionStart = 5;
});
- expect(hint).toBeTruthy();
- });
-});
+ afterEach(function () {
+ document.getElementsByTagName("body")[0].removeChild(
+ input
+ );
+ });
-describe('KorAP.HintMenuItem', function () {
- it('should be initializable', function () {
- expect(
- function() { KorAP.HintMenuItem.create([]) }
- ).toThrow(new Error("Missing parameters"));
+ afterAll(function () {
+ try {
+ document.getElementsByTagName("body")[0].removeChild(
+ document.getElementById("searchMirror")
+ );
+ }
+ catch (e) {};
+ });
- expect(
- function() { KorAP.HintMenuItem.create(['CoreNLP']) }
- ).toThrow(new Error("Missing parameters"));
+ it('should be initializable', function () {
+ // Supports: context, searchField
+ var inputField = inputClass.create(input);
+ expect(inputField._element).not.toBe(undefined);
+ });
- var menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']);
- expect(menuItem.name()).toEqual('CoreNLP');
- expect(menuItem.action()).toEqual('corenlp/');
- expect(menuItem.desc()).toBeUndefined();
+ it('should have text', function () {
+ expect(input.value).toEqual('abcdefghijklmno');
+ var inputField = inputClass.create(input);
- menuItem = KorAP.HintMenuItem.create(
- ['CoreNLP', 'corenlp/', 'It\'s funny']
- );
- expect(menuItem.name()).toEqual('CoreNLP');
- expect(menuItem.action()).toEqual('corenlp/');
- expect(menuItem.desc()).not.toBeUndefined();
- expect(menuItem.desc()).toEqual('It\'s funny');
- });
+ expect(inputField.value()).toEqual("abcdefghijklmno");
- it('should have an element', function () {
- var menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']);
- expect(menuItem.element()).not.toBe(undefined);
- expect(menuItem.element().nodeName).toEqual("LI");
+ expect(input.selectionStart).toEqual(5);
+ expect(inputField.element().selectionStart).toEqual(5);
+ expect(inputField.split()[0]).toEqual("abcde");
+ expect(inputField.split()[1]).toEqual("fghijklmno");
- var title = menuItem.element().firstChild;
- expect(title.nodeName).toEqual("SPAN");
- expect(title.firstChild.nodeType).toEqual(3);
- expect(title.firstChild.nodeValue).toEqual("CoreNLP");
- expect(menuItem.element().childNodes[0]).not.toBe(undefined);
- expect(menuItem.element().childNodes[1]).toBe(undefined);
+ inputField.insert("xyz");
+ expect(inputField.value()).toEqual('abcdexyzfghijklmno');
+ expect(inputField.split()[0]).toEqual("abcdexyz");
+ expect(inputField.split()[1]).toEqual("fghijklmno");
+ });
- menuItem = KorAP.HintMenuItem.create(
- ['CoreNLP', 'corenlp/', 'my DescRiption']
- );
- expect(menuItem.element()).not.toBe(undefined);
- expect(menuItem.element().nodeName).toEqual("LI");
+ it('should be correctly positioned', function () {
+ expect(input.value).toEqual('abcdefghijklmno');
+ var inputField = inputClass.create(input);
+ document.getElementsByTagName("body")[0].appendChild(input);
+ inputField.reposition();
+ expect(input.style.left).toEqual("30px");
+ expect(inputField.mirror().style.left.match(/^(\d+)px$/)[1]).toBeGreaterThan(29);
+ expect(inputField.mirror().style.top.match(/^(\d+)px$/)[1]).toBeGreaterThan(20);
+ });
- title = menuItem.element().firstChild;
- expect(title.nodeName).toEqual("SPAN");
- expect(title.firstChild.nodeType).toEqual(3); // TextNode
- expect(title.firstChild.nodeValue).toEqual("CoreNLP");
+ it('should have a correct context', function () {
+ expect(input.value).toEqual('abcdefghijklmno');
+ var inputField = inputClass.create(input);
+ expect(inputField.value()).toEqual("abcdefghijklmno");
+ expect(inputField.element().selectionStart).toEqual(5);
+ expect(inputField.split()[0]).toEqual("abcde");
+ expect(inputField.context()).toEqual("abcde");
+ });
- expect(menuItem.element().childNodes[0]).not.toBe(undefined);
- expect(menuItem.element().childNodes[1]).not.toBe(undefined);
-
- var desc = menuItem.element().lastChild;
- expect(desc.nodeName).toEqual("SPAN");
- expect(desc.firstChild.nodeType).toEqual(3); // TextNode
- expect(desc.firstChild.nodeValue).toEqual("my DescRiption");
+ /*
+ it('should be correctly triggerable', function () {
+ // https://developer.mozilla.org/samples/domref/dispatchEvent.html
+ var hint = KorAP.Hint.create({ "inputField" : input });
+ emitKeyboardEvent(hint.inputField.element, "keypress", 20);
+ });
+ */
});
- it('should be activatable and deactivateable by class', function () {
- var menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']);
- expect(menuItem.active()).toBe(false);
- expect(menuItem.element().getAttribute("class")).toBe(null);
- menuItem.active(true);
- expect(menuItem.active()).toBe(true);
- expect(menuItem.element().getAttribute("class")).toEqual("active");
- menuItem.active(false); // Is active
- expect(menuItem.active()).toBe(false);
- expect(menuItem.element().getAttribute("class")).toEqual("");
- menuItem.active(true);
- expect(menuItem.active()).toBe(true);
- expect(menuItem.element().getAttribute("class")).toEqual("active");
+ describe('KorAP.ContextAnalyzer', function () {
+ it('should be initializable', function () {
+ var analyzer = contextClass.create(")");
+ expect(analyzer).toBe(undefined);
+ analyzer = contextClass.create(".+?");
+ expect(analyzer).not.toBe(undefined);
+ });
- menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']);
- expect(menuItem.active()).toBe(false);
- expect(menuItem.element().getAttribute("class")).toBe(null);
- menuItem.active(false); // Is not active
- expect(menuItem.active()).toBe(false);
- expect(menuItem.element().getAttribute("class")).toBe(null);
+ it('should check correctly', function () {
+ analyzer = contextClass.create(KorAP.context);
+ expect(analyzer.test("cnx/]cnx/c=")).toEqual("cnx/c=");
+ expect(analyzer.test("cnx/c=")).toEqual("cnx/c=");
+ expect(analyzer.test("cnx/c=np mate/m=mood:")).toEqual("mate/m=mood:");
+ expect(analyzer.test("impcnx/")).toEqual("impcnx/");
+ expect(analyzer.test("cnx/c=npcnx/")).toEqual("npcnx/");
+ expect(analyzer.test("mate/m=degree:pos corenlp/ne_dewac_175m_600="))
+ .toEqual("corenlp/ne_dewac_175m_600=");
+ });
});
- it('should be set to boundary', function () {
- var menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']);
- expect(menuItem.active()).toBe(false);
- expect(menuItem.element().getAttribute("class")).toBe(null);
- // Set active
- menuItem.active(true);
- expect(menuItem.active()).toBe(true);
- expect(menuItem.noMore()).toBe(false);
- expect(menuItem.element().getAttribute("class")).toEqual("active");
+ describe('KorAP.Hint', function () {
+ KorAP.hintArray = {
+ "corenlp/" : [
+ ["Named Entity", "ne=" , "Combined"],
+ ["Named Entity", "ne_dewac_175m_600=" , "ne_dewac_175m_600"],
+ ["Named Entity", "ne_hgc_175m_600=", "ne_hgc_175m_600"]
+ ]
+ };
- // Set no more
- menuItem.noMore(true);
- expect(menuItem.active()).toBe(true);
- expect(menuItem.noMore()).toBe(true);
- expect(menuItem.element().getAttribute("class")).toEqual("active no-more");
+ beforeEach(function () {
+ input = document.createElement("input");
+ input.setAttribute("type", "text");
+ input.setAttribute("value", "abcdefghijklmno");
+ input.style.position = 'absolute';
+ input.style.top = "20px";
+ input.style.left = "30px";
+ input.focus();
+ input.selectionStart = 5;
+ });
- // No no more
- menuItem.noMore(false);
- expect(menuItem.active()).toBe(true);
- expect(menuItem.noMore()).toBe(false);
- expect(menuItem.element().getAttribute("class")).toEqual("active");
+ it('should be initializable', function () {
+ // Supports: context, searchField
+ var hint = hintClass.create({
+ inputField : input
+ });
- // Set no more, deactivate
- menuItem.noMore(true);
- menuItem.active(false);
- expect(menuItem.active()).toBe(false);
- expect(menuItem.noMore()).toBe(true);
- expect(menuItem.element().getAttribute("class")).toEqual("no-more");
-
- // Set active
- menuItem.active(true);
- expect(menuItem.active()).toBe(true);
- expect(menuItem.noMore()).toBe(true);
- expect(menuItem.element().getAttribute("class")).toEqual("no-more active");
+ expect(hint).toBeTruthy();
+ });
});
- xit('should be highlightable', function () {
- // Highlight in the middle
- var menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']);
- menuItem.highlight("ren");
- expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span>");
+ describe('KorAP.HintMenuItem', function () {
+ it('should be initializable', function () {
+ expect(
+ function() { menuItemClass.create([]) }
+ ).toThrow(new Error("Missing parameters"));
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
+ expect(
+ function() { menuItemClass.create(['CoreNLP']) }
+ ).toThrow(new Error("Missing parameters"));
- // Starting highlight
- menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']);
- menuItem.highlight("cor");
- expect(menuItem.element().innerHTML).toEqual("<span><mark>Cor</mark>eNLP</span>");
+ var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
+ expect(menuItem.name()).toEqual('CoreNLP');
+ expect(menuItem.action()).toEqual('corenlp/');
+ expect(menuItem.desc()).toBeUndefined();
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
-/*
+ menuItem = menuItemClass.create(
+ ['CoreNLP', 'corenlp/', 'It\'s funny']
+ );
+ expect(menuItem.name()).toEqual('CoreNLP');
+ expect(menuItem.action()).toEqual('corenlp/');
+ expect(menuItem.desc()).not.toBeUndefined();
+ expect(menuItem.desc()).toEqual('It\'s funny');
+ });
- // Starting highlight - short
- menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']);
- menuItem.highlight("c");
- expect(menuItem.element().innerHTML).toEqual("<span><mark>C</mark>oreNLP</span>");
+ it('should have an element', function () {
+ var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
+ expect(menuItem.element()).not.toBe(undefined);
+ expect(menuItem.element().nodeName).toEqual("LI");
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
+ var title = menuItem.element().firstChild;
+ expect(title.nodeName).toEqual("SPAN");
+ expect(title.firstChild.nodeType).toEqual(3);
+ expect(title.firstChild.nodeValue).toEqual("CoreNLP");
+ expect(menuItem.element().childNodes[0]).not.toBe(undefined);
+ expect(menuItem.element().childNodes[1]).toBe(undefined);
- // Highlight at the end
- menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']);
- menuItem.highlight("nlp");
- expect(menuItem.element().innerHTML).toEqual("<span>Core<mark>NLP</mark></span>");
+ menuItem = menuItemClass.create(
+ ['CoreNLP', 'corenlp/', 'my DescRiption']
+ );
+ expect(menuItem.element()).not.toBe(undefined);
+ expect(menuItem.element().nodeName).toEqual("LI");
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
+ title = menuItem.element().firstChild;
+ expect(title.nodeName).toEqual("SPAN");
+ expect(title.firstChild.nodeType).toEqual(3); // TextNode
+ expect(title.firstChild.nodeValue).toEqual("CoreNLP");
- // Highlight at the end - short
- menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']);
- menuItem.highlight("p");
- expect(menuItem.element().innerHTML).toEqual("<span>CoreNL<mark>P</mark></span>");
+ expect(menuItem.element().childNodes[0]).not.toBe(undefined);
+ expect(menuItem.element().childNodes[1]).not.toBe(undefined);
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
-
- // No highlight
- menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']);
- menuItem.highlight("xp");
- expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
-
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
+ var desc = menuItem.element().lastChild;
+ expect(desc.nodeName).toEqual("SPAN");
+ expect(desc.firstChild.nodeType).toEqual(3); // TextNode
+ expect(desc.firstChild.nodeValue).toEqual("my DescRiption");
+ });
- // Highlight in the middle - first
- menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
- menuItem.highlight("ren");
- expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span><span class=\"desc\">This is my Example</span>");
+ it('should be activatable and deactivateable by class', function () {
+ var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
+ expect(menuItem.active()).toBe(false);
+ expect(menuItem.element().getAttribute("class")).toBe(null);
+ menuItem.active(true);
+ expect(menuItem.active()).toBe(true);
+ expect(menuItem.element().getAttribute("class")).toEqual("active");
+ menuItem.active(false); // Is active
+ expect(menuItem.active()).toBe(false);
+ expect(menuItem.element().getAttribute("class")).toEqual("");
+ menuItem.active(true);
+ expect(menuItem.active()).toBe(true);
+ expect(menuItem.element().getAttribute("class")).toEqual("active");
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>');
+ menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
+ expect(menuItem.active()).toBe(false);
+ expect(menuItem.element().getAttribute("class")).toBe(null);
+ menuItem.active(false); // Is not active
+ expect(menuItem.active()).toBe(false);
+ expect(menuItem.element().getAttribute("class")).toBe(null);
+ });
- // Highlight in the middle - second
- menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
- menuItem.highlight("ampl");
- expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Ex<mark>ampl</mark>e</span>');
+ it('should be set to boundary', function () {
+ var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
+ expect(menuItem.active()).toBe(false);
+ expect(menuItem.element().getAttribute("class")).toBe(null);
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>');
+ // Set active
+ menuItem.active(true);
+ expect(menuItem.active()).toBe(true);
+ expect(menuItem.noMore()).toBe(false);
+ expect(menuItem.element().getAttribute("class")).toEqual("active");
- // Highlight in the middle - both
- menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
+ // Set no more
+ menuItem.noMore(true);
+ expect(menuItem.active()).toBe(true);
+ expect(menuItem.noMore()).toBe(true);
+ expect(menuItem.element().getAttribute("class")).toEqual("active no-more");
- menuItem.highlight("e");
- expect(menuItem.element().innerHTML).toEqual('<span>Cor<mark>e</mark>NLP</span><span class="desc">This is my <mark>E</mark>xampl<mark>e</mark></span>');
+ // No no more
+ menuItem.noMore(false);
+ expect(menuItem.active()).toBe(true);
+ expect(menuItem.noMore()).toBe(false);
+ expect(menuItem.element().getAttribute("class")).toEqual("active");
+ // Set no more, deactivate
+ menuItem.noMore(true);
+ menuItem.active(false);
+ expect(menuItem.active()).toBe(false);
+ expect(menuItem.noMore()).toBe(true);
+ expect(menuItem.element().getAttribute("class")).toEqual("no-more");
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span>This is my Example</span>");
+ // Set active
+ menuItem.active(true);
+ expect(menuItem.active()).toBe(true);
+ expect(menuItem.noMore()).toBe(true);
+ expect(menuItem.element().getAttribute("class")).toEqual("no-more active");
+ });
- // Highlight in the end - second
- menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
- menuItem.highlight("le");
- expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span>This is my Examp<mark>le</mark></span>");
+ it('should be highlightable', function () {
+ // Highlight in the middle
+ var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
+ menuItem.highlight("ren");
+ expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span>");
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span>This is my Example</span>");
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
- // Highlight at the beginning - second
- menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
- menuItem.highlight("this");
- expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span><mark>This</mark> is my Example</span>");
+ // Starting highlight
+ menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
+ menuItem.highlight("cor");
+ expect(menuItem.element().innerHTML).toEqual("<span><mark>Cor</mark>eNLP</span>");
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span>This is my Example</span>");
-*/
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
+
+ // Starting highlight - short
+ menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
+ menuItem.highlight("c");
+ expect(menuItem.element().innerHTML).toEqual("<span><mark>C</mark>oreNLP</span>");
+
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
+
+ // Highlight at the end
+ menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
+ menuItem.highlight("nlp");
+ expect(menuItem.element().innerHTML).toEqual("<span>Core<mark>NLP</mark></span>");
+
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
+
+ // Highlight at the end - short
+ menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
+ menuItem.highlight("p");
+ expect(menuItem.element().innerHTML).toEqual("<span>CoreNL<mark>P</mark></span>");
+
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
+
+ // No highlight
+ menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
+ menuItem.highlight("xp");
+ expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
+
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
+
+ // Highlight in the middle - first
+ menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
+
+ menuItem.highlight("ren");
+ expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span><span class=\"desc\">This is my Example</span>");
+
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>');
+
+ // Highlight in the middle - second
+ menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
+ menuItem.highlight("ampl");
+ expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Ex<mark>ampl</mark>e</span>');
+
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>');
+
+ // Highlight in the middle - both
+ menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
+
+ menuItem.highlight("e");
+ expect(menuItem.element().innerHTML).toEqual('<span>Cor<mark>e</mark>NLP</span><span class="desc">This is my <mark>E</mark>xampl<mark>e</mark></span>');
+
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
+
+ // Highlight in the end - second
+ menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
+ menuItem.highlight("le");
+ expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Examp<mark>le</mark></span>");
+
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
+
+ // Highlight at the beginning - second
+ menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
+ menuItem.highlight("this");
+ expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\"><mark>This</mark> is my Example</span>");
+
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
+ });
});
-});
+ describe('KorAP.HintMenu', function () {
-describe('KorAP.HintMenu', function () {
+ var list = [
+ ["Constituency", "c=", "Example 1"],
+ ["Lemma", "l="],
+ ["Morphology", "m=", "Example 2"],
+ ["Part-of-Speech", "p="],
+ ["Syntax", "syn="]
+ ];
- var list = [
- ["Constituency", "c=", "Example 1"],
- ["Lemma", "l="],
- ["Morphology", "m=", "Example 2"],
- ["Part-of-Speech", "p="],
- ["Syntax", "syn="]
- ];
+ it('should be initializable', function () {
+ var menu = menuClass.create(null, "cnx/", list);
+ expect(menu.context()).toEqual('cnx/');
+ expect(menu.element().nodeName).toEqual('UL');
+ expect(menu.element().style.opacity).toEqual("0");
- it('should be initializable', function () {
+ menu.limit(8);
- var menu = KorAP.HintMenu.create(null, "cnx/", list);
- expect(menu.context()).toEqual('cnx/');
- expect(menu.element().nodeName).toEqual('UL');
- expect(menu.element().style.opacity).toEqual("0");
+ // view
+ menu.show();
- menu.limit(8);
+ // First element in list
+ expect(menu.item(0).active()).toBe(true);
+ expect(menu.item(0).noMore()).toBe(true);
+
+ // Middle element in list
+ expect(menu.item(2).active()).toBe(false);
+ expect(menu.item(2).noMore()).toBe(false);
- // view
- menu.show();
-
- // First element in list
- expect(menu.item(0).active()).toBe(true);
- expect(menu.item(0).noMore()).toBe(true);
-
- // Middle element in list
- expect(menu.item(2).active()).toBe(false);
- expect(menu.item(2).noMore()).toBe(false);
-
- // Last element in list
- expect(menu.item(menu.length() - 1).active()).toBe(false);
- expect(menu.item(menu.length() - 1).noMore()).toBe(true);
+ // Last element in list
+ expect(menu.item(menu.length() - 1).active()).toBe(false);
+ expect(menu.item(menu.length() - 1).noMore()).toBe(true);
+ });
});
});
diff --git a/dev/js/spec/matchSpec.js b/dev/js/spec/matchSpec.js
index f520557..28eb844 100644
--- a/dev/js/spec/matchSpec.js
+++ b/dev/js/spec/matchSpec.js
@@ -1,3 +1,6 @@
+// Regarding async:
+// http://stackoverflow.com/questions/16423156/getting-requirejs-to-work-with-jasmine
+
var available = [
'base/s=spans',
'corenlp/c=spans',
@@ -140,421 +143,435 @@
};
-// Override getMatchInfo API call
-KorAP.API.getMatchInfo = function (x, param, cb) {
- if (param['spans'] === undefined || param['spans'] === false)
- cb({ "snippet": snippet });
- else
- cb({ "snippet": treeSnippet });
-};
+define(['match'], function () {
-
-describe('KorAP.InfoLayer', function () {
-
- it('should be initializable', function () {
- expect(
- function() { KorAP.InfoLayer.create() }
- ).toThrow(new Error("Missing parameters"));
-
- expect(
- function() { KorAP.InfoLayer.create("base") }
- ).toThrow(new Error("Missing parameters"));
-
- var layer = KorAP.InfoLayer.create("base", "s");
- expect(layer).toBeTruthy();
- expect(layer.foundry).toEqual("base");
- expect(layer.layer).toEqual("s");
- expect(layer.type).toEqual("tokens");
-
- layer = KorAP.InfoLayer.create("cnx", "syn", "spans");
- expect(layer).toBeTruthy();
- expect(layer.foundry).toEqual("cnx");
- expect(layer.layer).toEqual("syn");
- expect(layer.type).toEqual("spans");
- });
-});
-
-
-describe('KorAP.Match', function () {
- var match = {
- 'corpusID' : 'WPD',
- 'docID' : 'UUU',
- 'textID' : '01912',
- 'matchID' : 'p121-122',
- 'available' : available
+ // Override getMatchInfo API call
+ KorAP.API.getMatchInfo = function (x, param, cb) {
+ if (param['spans'] === undefined || param['spans'] === false)
+ cb({ "snippet": snippet });
+ else
+ cb({ "snippet": treeSnippet });
};
- it('should be initializable by Object', function () {
- expect(function() {
- KorAP.Match.create()
- }).toThrow(new Error('Missing parameters'));
+ describe('KorAP.InfoLayer', function () {
+
+ var infoClass = require('match/infolayer');
- expect(KorAP.Match.create(match)).toBeTruthy();
+ it('should be initializable', function () {
+ expect(
+ function() { infoClass.create() }
+ ).toThrow(new Error("Missing parameters"));
- var m = KorAP.Match.create(match);
- expect(m.corpusID).toEqual("WPD");
- expect(m.docID).toEqual("UUU");
- expect(m.textID).toEqual("01912");
- expect(m.matchID).toEqual("p121-122");
+ expect(
+ function() { infoClass.create("base") }
+ ).toThrow(new Error("Missing parameters"));
- // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=*
- var m = KorAP.Match.create(match);
+ var layer = infoClass.create("base", "s");
+ expect(layer).toBeTruthy();
+ expect(layer.foundry).toEqual("base");
+ expect(layer.layer).toEqual("s");
+ expect(layer.type).toEqual("tokens");
- // Spans:
- var spans = m.getSpans();
- expect(spans[0].foundry).toEqual("base");
- expect(spans[0].layer).toEqual("s");
-
- expect(spans[1].foundry).toEqual("corenlp");
- expect(spans[1].layer).toEqual("c");
-
- expect(spans[2].foundry).toEqual("corenlp");
- expect(spans[2].layer).toEqual("s");
-
- expect(spans[spans.length-1].foundry).toEqual("tt");
- expect(spans[spans.length-1].layer).toEqual("s");
-
- // Tokens:
- var tokens = m.getTokens();
- expect(tokens[0].foundry).toEqual("corenlp");
- expect(tokens[0].layer).toEqual("ne");
-
- expect(tokens[1].foundry).toEqual("corenlp");
- expect(tokens[1].layer).toEqual("p");
-
- expect(tokens[tokens.length-1].foundry).toEqual("tt");
- expect(tokens[tokens.length-1].layer).toEqual("p");
- });
-
-
- it('should be initializable by Node', function () {
- var m = KorAP.Match.create(matchElementFactory());
- expect(m.corpusID).toEqual("WPD");
- expect(m.docID).toEqual("FFF");
- expect(m.textID).toEqual("01460");
- expect(m.matchID).toEqual("p119-120");
-
- // Spans:
- var spans = m.getSpans();
- expect(spans[0].foundry).toEqual("base");
- expect(spans[0].layer).toEqual("s");
-
- expect(spans[1].foundry).toEqual("corenlp");
- expect(spans[1].layer).toEqual("c");
-
- expect(spans[2].foundry).toEqual("corenlp");
- expect(spans[2].layer).toEqual("s");
-
- expect(spans[spans.length-1].foundry).toEqual("tt");
- expect(spans[spans.length-1].layer).toEqual("s");
-
- // Tokens:
- var tokens = m.getTokens();
- expect(tokens[0].foundry).toEqual("corenlp");
- expect(tokens[0].layer).toEqual("ne");
-
- expect(tokens[1].foundry).toEqual("corenlp");
- expect(tokens[1].layer).toEqual("p");
-
- expect(tokens[tokens.length-1].foundry).toEqual("tt");
- expect(tokens[tokens.length-1].layer).toEqual("p");
-
- });
-
- it('should react to gui actions', function () {
- var e = matchElementFactory();
-
- expect(e.classList.contains('active')).toBe(false);
- expect(e["_match"]).toBe(undefined);
-
- var m = KorAP.Match.create(e);
-
- expect(e.classList.contains('active')).toBe(false);
- expect(e["_match"]).not.toBe(undefined);
-
- // Open the match
- m.open();
-
- expect(e.classList.contains('active')).toBe(true);
- expect(e["_match"]).not.toBe(undefined);
-
- // Close the match
- m.close();
- expect(e.classList.contains('active')).toBe(false);
- expect(e["_match"]).not.toBe(undefined);
-
- });
-});
-
-
-describe('KorAP.MatchInfo', function () {
-
- var m = KorAP.Match.create(match);
- var info = m.info();
-
- it('should contain a valid info', function () {
- expect(m._info).toEqual(info);
- });
-
- var table1, table2;
-
- // Async preparation
- it('should fail to load a table async', function (done) {
- expect(info).toBeTruthy();
-
- info.getTable([], function (tablen) {
- table1 = tablen;
- done();
+ layer = infoClass.create("cnx", "syn", "spans");
+ expect(layer).toBeTruthy();
+ expect(layer.foundry).toEqual("cnx");
+ expect(layer.layer).toEqual("syn");
+ expect(layer.type).toEqual("spans");
});
});
- it('should\'nt be parsable (async)', function () {
- expect(table1).not.toBeTruthy();
- });
- it('should load a working table async', function(done) {
- expect(info).toBeTruthy();
- info.getTable(undefined, function (tablem) {
- table2 = tablem;
- done();
+ describe('KorAP.Match', function () {
+ var match = {
+ 'corpusID' : 'WPD',
+ 'docID' : 'UUU',
+ 'textID' : '01912',
+ 'matchID' : 'p121-122',
+ 'available' : available
+ };
+
+ var matchClass = require('match');
+
+ it('should be initializable by Object', function () {
+ expect(function() {
+ matchClass.create()
+ }).toThrow(new Error('Missing parameters'));
+
+ expect(matchClass.create(match)).toBeTruthy();
+
+ var m = matchClass.create(match);
+ expect(m.corpusID).toEqual("WPD");
+ expect(m.docID).toEqual("UUU");
+ expect(m.textID).toEqual("01912");
+ expect(m.matchID).toEqual("p121-122");
+
+ // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=*
+ var m = matchClass.create(match);
+
+ // Spans:
+ var spans = m.getSpans();
+ expect(spans[0].foundry).toEqual("base");
+ expect(spans[0].layer).toEqual("s");
+
+ expect(spans[1].foundry).toEqual("corenlp");
+ expect(spans[1].layer).toEqual("c");
+
+ expect(spans[2].foundry).toEqual("corenlp");
+ expect(spans[2].layer).toEqual("s");
+
+ expect(spans[spans.length-1].foundry).toEqual("tt");
+ expect(spans[spans.length-1].layer).toEqual("s");
+
+ // Tokens:
+ var tokens = m.getTokens();
+ expect(tokens[0].foundry).toEqual("corenlp");
+ expect(tokens[0].layer).toEqual("ne");
+
+ expect(tokens[1].foundry).toEqual("corenlp");
+ expect(tokens[1].layer).toEqual("p");
+
+ expect(tokens[tokens.length-1].foundry).toEqual("tt");
+ expect(tokens[tokens.length-1].layer).toEqual("p");
});
- });
-
- it('should parse into a table (async)', function () {
- expect(table2).toBeTruthy();
-
- expect(table2.length()).toBe(3);
-
- expect(table2.getToken(0)).toBe("meist");
- expect(table2.getToken(1)).toBe("deutlich");
- expect(table2.getToken(2)).toBe("leistungsfähiger");
-
- expect(table2.getValue(0, "cnx", "p")[0]).toBe("ADV");
- expect(table2.getValue(0, "cnx", "syn")[0]).toBe("@PREMOD");
-
- expect(table2.getValue(2, "cnx", "l")[0]).toBe("fähig");
- expect(table2.getValue(2, "cnx", "l")[1]).toBe("leistung");
- });
- it('should parse into a table view', function () {
- var matchElement = matchElementFactory();
- expect(matchElement.tagName).toEqual('LI');
+ it('should be initializable by Node', function () {
+ var m = matchClass.create(matchElementFactory());
+ expect(m.corpusID).toEqual("WPD");
+ expect(m.docID).toEqual("FFF");
+ expect(m.textID).toEqual("01460");
+ expect(m.matchID).toEqual("p119-120");
- // Match
- expect(matchElement.children[0].tagName).toEqual('DIV');
+ // Spans:
+ var spans = m.getSpans();
+ expect(spans[0].foundry).toEqual("base");
+ expect(spans[0].layer).toEqual("s");
- // snippet
- expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
- expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
- expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
+ expect(spans[1].foundry).toEqual("corenlp");
+ expect(spans[1].layer).toEqual("c");
- // reference
- expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
- expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
+ expect(spans[2].foundry).toEqual("corenlp");
+ expect(spans[2].layer).toEqual("s");
- // not yet
- expect(matchElement.children[0].children[1]).toBe(undefined);
+ expect(spans[spans.length-1].foundry).toEqual("tt");
+ expect(spans[spans.length-1].layer).toEqual("s");
- var info = KorAP.Match.create(matchElement).info();
- info.toggle();
+ // Tokens:
+ var tokens = m.getTokens();
+ expect(tokens[0].foundry).toEqual("corenlp");
+ expect(tokens[0].layer).toEqual("ne");
- // Match
- expect(matchElement.children[0].tagName).toEqual('DIV');
+ expect(tokens[1].foundry).toEqual("corenlp");
+ expect(tokens[1].layer).toEqual("p");
- // snippet
- expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
- expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
- expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
+ expect(tokens[tokens.length-1].foundry).toEqual("tt");
+ expect(tokens[tokens.length-1].layer).toEqual("p");
- // reference
- expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
- expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
+ });
- // now
- var infotable = matchElement.children[0].children[1];
- expect(infotable.tagName).toEqual('DIV');
- expect(infotable.classList.contains('matchinfo')).toBeTruthy();
+ it('should react to gui actions', function () {
+ var e = matchElementFactory();
- expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
- expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
- });
+ expect(e.classList.contains('active')).toBe(false);
+ expect(e["_match"]).toBe(undefined);
- var tree;
- it('should parse into a tree (async) 1', function (done) {
- var info = KorAP.Match.create(match).info();
- expect(info).toBeTruthy();
- info.getTree(undefined, undefined, function (treem) {
- tree = treem;
- done();
+ var m = matchClass.create(e);
+
+ expect(e.classList.contains('active')).toBe(false);
+ expect(e["_match"]).not.toBe(undefined);
+
+ // Open the match
+ m.open();
+
+ expect(e.classList.contains('active')).toBe(true);
+ expect(e["_match"]).not.toBe(undefined);
+
+ // Close the match
+ m.close();
+ expect(e.classList.contains('active')).toBe(false);
+ expect(e["_match"]).not.toBe(undefined);
+
});
});
- it('should parse into a tree (async) 2', function () {
- expect(tree).toBeTruthy();
- expect(tree.nodes()).toEqual(49);
- });
+
+ describe('KorAP.MatchInfo', function () {
+
+ var matchClass = require('match');
+
+ var m = matchClass.create(match);
+ var info = m.info();
+
+ it('should contain a valid info', function () {
+ expect(m._info).toEqual(info);
+ });
+
+ var table1, table2;
+
+ // Async preparation
+ it('should fail to load a table async', function (done) {
+ expect(info).toBeTruthy();
+
+ info.getTable([], function (tablen) {
+ table1 = tablen;
+ done();
+ });
+ });
+
+ it('should\'nt be parsable (async)', function () {
+ expect(table1).not.toBeTruthy();
+ });
+
+ it('should load a working table async', function(done) {
+ expect(info).toBeTruthy();
+ info.getTable(undefined, function (tablem) {
+ table2 = tablem;
+ done();
+ });
+ });
+
+ it('should parse into a table (async)', function () {
+ expect(table2).toBeTruthy();
+
+ expect(table2.length()).toBe(3);
+
+ expect(table2.getToken(0)).toBe("meist");
+ expect(table2.getToken(1)).toBe("deutlich");
+ expect(table2.getToken(2)).toBe("leistungsfähiger");
+
+ expect(table2.getValue(0, "cnx", "p")[0]).toBe("ADV");
+ expect(table2.getValue(0, "cnx", "syn")[0]).toBe("@PREMOD");
+
+ expect(table2.getValue(2, "cnx", "l")[0]).toBe("fähig");
+ expect(table2.getValue(2, "cnx", "l")[1]).toBe("leistung");
+ });
+
+ it('should parse into a table view', function () {
+ var matchElement = matchElementFactory();
+ expect(matchElement.tagName).toEqual('LI');
+
+ // Match
+ expect(matchElement.children[0].tagName).toEqual('DIV');
+
+ // snippet
+ expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
+ expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
+ expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
+
+ // reference
+ expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
+ expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
+
+ // not yet
+ expect(matchElement.children[0].children[1]).toBe(undefined);
+
+ var info = matchClass.create(matchElement).info();
+ info.toggle();
+
+ // Match
+ expect(matchElement.children[0].tagName).toEqual('DIV');
+
+ // snippet
+ expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
+ expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
+ expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
+
+ // reference
+ expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
+ expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
+
+ // now
+ var infotable = matchElement.children[0].children[1];
+ expect(infotable.tagName).toEqual('DIV');
+ expect(infotable.classList.contains('matchinfo')).toBeTruthy();
+
+ expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
+ expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
+ });
+
+ var tree;
+ it('should parse into a tree (async) 1', function (done) {
+ var info = matchClass.create(match).info();
+ expect(info).toBeTruthy();
+ info.getTree(undefined, undefined, function (treem) {
+ tree = treem;
+ done();
+ });
+ });
+
+ it('should parse into a tree (async) 2', function () {
+ expect(tree).toBeTruthy();
+ expect(tree.nodes()).toEqual(49);
+ });
- var info, matchElement;
- it('should parse into a tree view', function () {
- matchElement = matchElementFactory();
- expect(matchElement.tagName).toEqual('LI');
+ var info, matchElement;
+ it('should parse into a tree view', function () {
+ matchElement = matchElementFactory();
+ expect(matchElement.tagName).toEqual('LI');
- info = KorAP.Match.create(matchElement).info();
- info.toggle();
+ info = matchClass.create(matchElement).info();
+ info.toggle();
- // Match
- expect(matchElement.children[0].tagName).toEqual('DIV');
+ // Match
+ expect(matchElement.children[0].tagName).toEqual('DIV');
- // snippet
- expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
- expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
- expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
+ // snippet
+ expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
+ expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
+ expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
- // reference
- expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
- expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
+ // reference
+ expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
+ expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
- // now
- var infotable = matchElement.children[0].children[1];
- expect(infotable.tagName).toEqual('DIV');
- expect(infotable.classList.contains('matchinfo')).toBeTruthy();
- expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
- expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
- });
+ // now
+ var infotable = matchElement.children[0].children[1];
+ expect(infotable.tagName).toEqual('DIV');
+ expect(infotable.classList.contains('matchinfo')).toBeTruthy();
+ expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
+ expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
+ });
- it('should add a tree view async 1', function (done) {
- expect(info).toBeTruthy();
- info.addTree('mate', 'beebop', function () {
- done();
+ it('should add a tree view async 1', function (done) {
+ expect(info).toBeTruthy();
+ info.addTree('mate', 'beebop', function () {
+ done();
+ });
+ });
+
+ it('should add a tree view async 2', function () {
+ // With added tree
+ var infotable = matchElement.children[0].children[1];
+ expect(infotable.tagName).toEqual('DIV');
+ expect(infotable.classList.contains('matchinfo')).toBeTruthy();
+ expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
+ expect(infotable.children[1].classList.contains('addtree')).toBe(false);
+
+ var tree = infotable.children[1];
+ expect(tree.tagName).toEqual('DIV');
+ expect(tree.classList.contains('matchtree')).toBeTruthy();
+ expect(tree.children[0].tagName).toEqual('H6');
+ expect(tree.children[0].children[0].tagName).toEqual('SPAN');
+ expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
+ expect(tree.children[0].children[1].tagName).toEqual('SPAN');
+ expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
+
+ expect(tree.children[1].tagName).toEqual('DIV');
});
});
- it('should add a tree view async 2', function () {
- // With added tree
- var infotable = matchElement.children[0].children[1];
- expect(infotable.tagName).toEqual('DIV');
- expect(infotable.classList.contains('matchinfo')).toBeTruthy();
- expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
- expect(infotable.children[1].classList.contains('addtree')).toBe(false);
- var tree = infotable.children[1];
- expect(tree.tagName).toEqual('DIV');
- expect(tree.classList.contains('matchtree')).toBeTruthy();
- expect(tree.children[0].tagName).toEqual('H6');
- expect(tree.children[0].children[0].tagName).toEqual('SPAN');
- expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
- expect(tree.children[0].children[1].tagName).toEqual('SPAN');
- expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
+ describe('KorAP.MatchTable', function () {
- expect(tree.children[1].tagName).toEqual('DIV');
- });
-});
+ var matchClass = require('match');
+ var table;
+ it('should be retrieved async', function (done) {
+ var info = matchClass.create(match).info();
+ expect(info).toBeTruthy();
+ info.getTable(undefined, function (x) {
+ table = x;
+ done();
+ });
+ });
-describe('KorAP.MatchTable', function () {
+ it('should be rendered async', function () {
+ var e = table.element();
+
+ expect(e.nodeName).toBe('TABLE');
+ expect(e.children[0].nodeName).toBe('THEAD');
+ var tr = e.children[0].children[0];
+ expect(tr.nodeName).toBe('TR');
+ expect(tr.children[0].nodeName).toBe('TH');
- var table;
- it('should be retrieved async', function (done) {
- var info = KorAP.Match.create(match).info();
- expect(info).toBeTruthy();
- info.getTable(undefined, function (x) {
- table = x;
- done();
+ expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
+ expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
+ expect(tr.children[2].firstChild.nodeValue).toBe('meist');
+ expect(tr.children[3].firstChild.nodeValue).toBe('deutlich');
+ expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger');
+
+ // first row
+ tr = e.children[1].children[0];
+ expect(tr.nodeName).toBe('TR');
+ expect(tr.getAttribute('tabindex')).toEqual('0');
+ expect(tr.children[0].nodeName).toBe('TH');
+ expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
+ expect(tr.children[1].firstChild.nodeValue).toEqual('l');
+ expect(tr.children[2].firstChild.nodeValue).toEqual('meist');
+ expect(tr.children[3].firstChild.nodeValue).toEqual('deutlich');
+ expect(tr.children[4].firstChild.nodeValue).toEqual('fähig');
+ expect(tr.children[4].lastChild.nodeValue).toEqual('leistung');
+
+ // second row
+ tr = e.children[1].children[1];
+ expect(tr.nodeName).toBe('TR');
+ expect(tr.getAttribute('tabindex')).toEqual('0');
+ expect(tr.children[0].nodeName).toBe('TH');
+ expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
+ expect(tr.children[1].firstChild.nodeValue).toEqual('p');
+ expect(tr.children[2].firstChild.nodeValue).toEqual('ADV');
+ expect(tr.children[3].firstChild.nodeValue).toEqual('A');
+ expect(tr.children[4].firstChild.nodeValue).toEqual('A');
});
});
- it('should be rendered async', function () {
- var e = table.element();
+ describe('KorAP.MatchTree', function () {
+ var tree;
+ var matchClass = require('match');
- expect(e.nodeName).toBe('TABLE');
- expect(e.children[0].nodeName).toBe('THEAD');
- var tr = e.children[0].children[0];
- expect(tr.nodeName).toBe('TR');
- expect(tr.children[0].nodeName).toBe('TH');
+ it('should be rendered async 1', function (done) {
+ var info = matchClass.create(match).info();
+ expect(info).toBeTruthy();
+ info.getTree(undefined, undefined, function (y) {
+ tree = y;
+ done();
+ });
+ });
- expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
- expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
- expect(tr.children[2].firstChild.nodeValue).toBe('meist');
- expect(tr.children[3].firstChild.nodeValue).toBe('deutlich');
- expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger');
-
- // first row
- tr = e.children[1].children[0];
- expect(tr.nodeName).toBe('TR');
- expect(tr.getAttribute('tabindex')).toEqual('0');
- expect(tr.children[0].nodeName).toBe('TH');
- expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
- expect(tr.children[1].firstChild.nodeValue).toEqual('l');
- expect(tr.children[2].firstChild.nodeValue).toEqual('meist');
- expect(tr.children[3].firstChild.nodeValue).toEqual('deutlich');
- expect(tr.children[4].firstChild.nodeValue).toEqual('fähig');
- expect(tr.children[4].lastChild.nodeValue).toEqual('leistung');
-
- // second row
- tr = e.children[1].children[1];
- expect(tr.nodeName).toBe('TR');
- expect(tr.getAttribute('tabindex')).toEqual('0');
- expect(tr.children[0].nodeName).toBe('TH');
- expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
- expect(tr.children[1].firstChild.nodeValue).toEqual('p');
- expect(tr.children[2].firstChild.nodeValue).toEqual('ADV');
- expect(tr.children[3].firstChild.nodeValue).toEqual('A');
- expect(tr.children[4].firstChild.nodeValue).toEqual('A');
- });
-});
-
-describe('KorAP.MatchTree', function () {
- var tree;
-
- it('should be rendered async 1', function (done) {
- var info = KorAP.Match.create(match).info();
- expect(info).toBeTruthy();
- info.getTree(undefined, undefined, function (y) {
- tree = y;
- done();
+ it('should be rendered async 2', function () {
+ var e = tree.element();
+ expect(e.nodeName).toEqual('svg');
+ expect(e.getElementsByTagName('g').length).toEqual(48);
});
});
- it('should be rendered async 2', function () {
- var e = tree.element();
- expect(e.nodeName).toEqual('svg');
- expect(e.getElementsByTagName('g').length).toEqual(48);
+
+ describe('KorAP.MatchTreeItem', function () {
+ var matchTreeItemClass = require('match/treeitem');
+ it('should be initializable', function () {
+ var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c'])
+ expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
+ expect(mi.lcField()).toEqual(' cnx/c');
+ expect(mi.foundry()).toEqual('cnx');
+ expect(mi.layer()).toEqual('c');
+ });
});
-});
-describe('KorAP.MatchTreeItem', function () {
- it('should be initializable', function () {
- var mi = KorAP.MatchTreeItem.create(['cnx/c', 'cnx', 'c'])
- expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
- expect(mi.lcField()).toEqual(' cnx/c');
- expect(mi.foundry()).toEqual('cnx');
- expect(mi.layer()).toEqual('c');
+ describe('KorAP.MatchTreeMenu', function () {
+ var matchTreeMenu = require('match/treemenu');
+ var matchTreeItem = require('match/treeitem');
+
+ it('should be initializable', function () {
+ var menu = matchTreeMenu.create(undefined, [
+ ['cnx/c', 'cnx', 'c'],
+ ['xip/c', 'xip', 'c']
+ ]);
+
+ expect(menu.itemClass()).toEqual(matchTreeItem);
+ expect(menu.element().nodeName).toEqual('UL');
+ expect(menu.element().style.opacity).toEqual("0");
+ expect(menu.limit()).toEqual(6);
+ menu.show();
+ expect(menu.item(0).active()).toBe(true);
+ });
});
+
+ // table = view.toTable();
+ // table.sortBy('');
+ // table.element();
+ // tree = view.toTree();
+ // tree.element();
+
});
-
-
-describe('KorAP.MatchTreeMenu', function () {
- it('should be initializable', function () {
- var menu = KorAP.MatchTreeMenu.create(undefined, [
- ['cnx/c', 'cnx', 'c'],
- ['xip/c', 'xip', 'c']
- ]);
-
- expect(menu.itemClass()).toEqual(KorAP.MatchTreeItem);
- expect(menu.element().nodeName).toEqual('UL');
- expect(menu.element().style.opacity).toEqual("0");
- expect(menu.limit()).toEqual(6);
- menu.show();
- expect(menu.item(0).active()).toBe(true);
- });
-});
-
-// table = view.toTable();
-// table.sortBy('');
-// table.element();
-// tree = view.toTree();
-// tree.element();
-
diff --git a/dev/js/spec/menuSpec.js b/dev/js/spec/menuSpec.js
index 6692753..7436e4d 100644
--- a/dev/js/spec/menuSpec.js
+++ b/dev/js/spec/menuSpec.js
@@ -1,1057 +1,1060 @@
-// The OwnMenu item
-KorAP.OwnMenuItem = {
- create : function (params) {
- return Object.create(KorAP.MenuItem).upgradeTo(KorAP.OwnMenuItem)._init(params);
- },
- content : function (content) {
- if (arguments.length === 1) {
- this._content = content;
- };
- return this._content;
- },
- _init : function (params) {
- if (params[0] === undefined)
- throw new Error("Missing parameters");
+define(['menu'], function () {
- this._content = document.createTextNode(params[0]);
- this._lcField = ' ' + this.content().textContent.toLowerCase();
+ var menuItemClass = require('menu/item');
+ var menuClass = require('menu');
- return this;
- }
-};
+ // The OwnMenu item
+ KorAP.OwnMenuItem = {
+ create : function (params) {
+ return Object.create(menuItemClass).upgradeTo(KorAP.OwnMenuItem)._init(params);
+ },
+ content : function (content) {
+ if (arguments.length === 1) {
+ this._content = content;
+ };
+ return this._content;
+ },
+ _init : function (params) {
+ if (params[0] === undefined)
+ throw new Error("Missing parameters");
+
+ this._content = document.createTextNode(params[0]);
+ this._lcField = ' ' + this.content().textContent.toLowerCase();
+
+ return this;
+ }
+ };
+
+ // The OwnMenu
+ KorAP.OwnMenu = {
+ create : function (params) {
+ return Object.create(menuClass)
+ .upgradeTo(KorAP.OwnMenu)
+ ._init(KorAP.OwnMenuItem, undefined, params);
+ }
+ };
-// The OwnMenu
-KorAP.OwnMenu = {
- create : function (params) {
- return Object.create(KorAP.Menu)
- .upgradeTo(KorAP.OwnMenu)
- ._init(KorAP.OwnMenuItem, undefined, params);
- }
-};
+ // HintMenuItem
+ KorAP.HintMenuItem = {
+ create : function (params) {
+ return Object.create(menuItemClass)
+ .upgradeTo(KorAP.HintMenuItem)
+ ._init(params);
+ },
+ content : function (content) {
+ if (arguments.length === 1) {
+ this._content = content;
+ };
+ return this._content;
+ },
+ _init : function (params) {
+ if (params[0] === undefined || params[1] === undefined)
+ throw new Error("Missing parameters");
+
+ this._name = params[0];
+ this._action = params[1];
+ this._lcField = ' ' + this._name.toLowerCase();
+
+ if (params.length > 2) {
+ this._desc = params[2];
+ this._lcField += " " + this._desc.toLowerCase();
+ };
+
+ return this;
+ },
+
+ name : function () {
+ return this._name;
+ },
+ action : function () {
+ return this._action;
+ },
+ desc : function () {
+ return this._desc;
+ },
+ element : function () {
+ // already defined
+ if (this._element !== undefined)
+ return this._element;
+
+ // Create list item
+ var li = document.createElement("li");
+ li.setAttribute("data-action", this._action);
+
+ // Create title
+ var name = document.createElement("strong");
+ name.appendChild(document.createTextNode(this._name));
+
+ li.appendChild(name);
+
+ // Create description
+ if (this._desc !== undefined) {
+ var desc = document.createElement("span");
+ desc.appendChild(document.createTextNode(this._desc));
+ li.appendChild(desc);
+ };
+ return this._element = li;
+ }
+ };
-// HintMenuItem
-KorAP.HintMenuItem = {
- create : function (params) {
- return Object.create(KorAP.MenuItem)
- .upgradeTo(KorAP.HintMenuItem)
- ._init(params);
- },
- content : function (content) {
- if (arguments.length === 1) {
- this._content = content;
- };
- return this._content;
- },
- _init : function (params) {
- if (params[0] === undefined || params[1] === undefined)
- throw new Error("Missing parameters");
-
- this._name = params[0];
- this._action = params[1];
- this._lcField = ' ' + this._name.toLowerCase();
-
- if (params.length > 2) {
- this._desc = params[2];
- this._lcField += " " + this._desc.toLowerCase();
- };
-
- return this;
- },
- name : function () {
- return this._name;
- },
- action : function () {
- return this._action;
- },
- desc : function () {
- return this._desc;
- },
- element : function () {
- // already defined
- if (this._element !== undefined)
- return this._element;
-
- // Create list item
- var li = document.createElement("li");
- li.setAttribute("data-action", this._action);
-
- // Create title
- var name = document.createElement("strong");
- name.appendChild(document.createTextNode(this._name));
-
- li.appendChild(name);
-
- // Create description
- if (this._desc !== undefined) {
- var desc = document.createElement("span");
- desc.appendChild(document.createTextNode(this._desc));
- li.appendChild(desc);
- };
- return this._element = li;
- }
-};
+ // HintMenu
+ KorAP.HintMenu = {
+ create : function (context, params) {
+ var obj = Object.create(menuClass)
+ .upgradeTo(KorAP.HintMenu)
+ ._init(KorAP.HintMenuItem, undefined, params);
+ obj._context = context;
+ return obj;
+ }
+ };
-// HintMenu
-KorAP.HintMenu = {
- create : function (context, params) {
- var obj = Object.create(KorAP.Menu)
- .upgradeTo(KorAP.HintMenu)
- ._init(KorAP.HintMenuItem, undefined, params);
- obj._context = context;
- return obj;
- }
-};
+ // The ComplexMenuItem
+ KorAP.ComplexMenuItem = {
+ create : function (params) {
+ return Object.create(menuItemClass)
+ .upgradeTo(KorAP.ComplexMenuItem)
+ ._init(params);
+ },
+ content : function (content) {
+ if (arguments.length === 1) {
+ this._content = content;
+ };
+ return this._content;
+ },
+ _init : function (params) {
+ if (params[0] === undefined)
+ throw new Error("Missing parameters");
+
+ var r = document.createElement('div');
+ for (var i = 1; i <= params.length; i++) {
+ var h = document.createElement('h' + i);
+ h.appendChild(document.createTextNode(params[i-1]));
+ r.appendChild(h);
+ };
+
+ this._content = r;
+ this._lcField = ' ' + this.content().textContent.toLowerCase();
+
+ return this;
+ }
+ };
-// The ComplexMenuItem
-KorAP.ComplexMenuItem = {
- create : function (params) {
- return Object.create(KorAP.MenuItem)
- .upgradeTo(KorAP.ComplexMenuItem)
- ._init(params);
- },
- content : function (content) {
- if (arguments.length === 1) {
- this._content = content;
- };
- return this._content;
- },
- _init : function (params) {
- if (params[0] === undefined)
- throw new Error("Missing parameters");
+ describe('KorAP.MenuItem', function () {
+ it('should be initializable', function () {
+ expect(
+ function() { menuItemClass.create([]) }
+ ).toThrow(new Error("Missing parameters"));
- var r = document.createElement('div');
- for (var i = 1; i <= params.length; i++) {
- var h = document.createElement('h' + i);
- h.appendChild(document.createTextNode(params[i-1]));
- r.appendChild(h);
- };
+ expect(
+ function() { KorAP.OwnMenuItem.create([]) }
+ ).toThrow(new Error("Missing parameters"));
- this._content = r;
- this._lcField = ' ' + this.content().textContent.toLowerCase();
+ var mi = KorAP.OwnMenuItem.create(["Baum"]);
+ expect(mi.element().firstChild.nodeValue).toEqual('Baum');
+ expect(mi.lcField()).toEqual(' baum');
+ });
- return this;
- }
-};
+ it('shouldn\'t have a reference to the menu', function () {
+ var menuItem = KorAP.OwnMenuItem.create(['Test']);
+ expect(menuItem.menu()).toBe(undefined);
+ });
+
+ it('should be activatable and deactivateable by class', function () {
+ var menuItem = KorAP.OwnMenuItem.create(['Test']);
+
+ expect(menuItem.active()).toBe(false);
+ expect(menuItem.element().getAttribute("class")).toBe(null);
+ menuItem.active(true);
+ expect(menuItem.active()).toBe(true);
+ expect(menuItem.element().getAttribute("class")).toEqual("active");
+ menuItem.active(false); // Is active
+ expect(menuItem.active()).toBe(false);
+ expect(menuItem.element().getAttribute("class")).toEqual("");
+ menuItem.active(true);
+ expect(menuItem.active()).toBe(true);
+ expect(menuItem.element().getAttribute("class")).toEqual("active");
+
+ menuItem = KorAP.OwnMenuItem.create(['Spiegel']);
+ expect(menuItem.active()).toBe(false);
+ expect(menuItem.element().getAttribute("class")).toBe(null);
+ menuItem.active(false); // Is not active
+ expect(menuItem.active()).toBe(false);
+ expect(menuItem.element().getAttribute("class")).toBe(null);
+ });
+
+ it('should be set to boundary', function () {
+ var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
+ expect(menuItem.active()).toBe(false);
+ expect(menuItem.element().getAttribute("class")).toBe(null);
+
+ // Set active
+ menuItem.active(true);
+ expect(menuItem.active()).toBe(true);
+ expect(menuItem.noMore()).toBe(false);
+ expect(menuItem.element().getAttribute("class")).toEqual("active");
+
+ // Set no more
+ menuItem.noMore(true);
+ expect(menuItem.active()).toBe(true);
+ expect(menuItem.noMore()).toBe(true);
+ expect(menuItem.element().getAttribute("class")).toEqual("active no-more");
+
+ // No no more
+ menuItem.noMore(false);
+ expect(menuItem.active()).toBe(true);
+ expect(menuItem.noMore()).toBe(false);
+ expect(menuItem.element().getAttribute("class")).toEqual("active");
+
+ // Set no more, deactivate
+ menuItem.noMore(true);
+ menuItem.active(false);
+ expect(menuItem.active()).toBe(false);
+ expect(menuItem.noMore()).toBe(true);
+ expect(menuItem.element().getAttribute("class")).toEqual("no-more");
+
+ // Set active
+ menuItem.active(true);
+ expect(menuItem.active()).toBe(true);
+ expect(menuItem.noMore()).toBe(true);
+ expect(menuItem.element().getAttribute("class")).toEqual("no-more active");
+ });
+ it('should be highlightable', function () {
+ // Highlight in the middle
+ var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
+ menuItem.highlight("ren");
+ expect(menuItem.element().innerHTML).toEqual("Co<mark>reN</mark>LP");
-describe('KorAP.MenuItem', function () {
- it('should be initializable', function () {
- expect(
- function() { KorAP.MenuItem.create([]) }
- ).toThrow(new Error("Missing parameters"));
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual("CoreNLP");
- expect(
- function() { KorAP.OwnMenuItem.create([]) }
- ).toThrow(new Error("Missing parameters"));
+ var plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2></div>";
- var mi = KorAP.OwnMenuItem.create(["Baum"]);
- expect(mi.element().firstChild.nodeValue).toEqual('Baum');
- expect(mi.lcField()).toEqual(' baum');
- });
+ // Starting highlight
+ menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
+ menuItem.highlight("cor");
+ expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>Cor</mark>eNLP</h1><h2><mark>cor</mark>enlp/</h2></div>");
- it('shouldn\'t have a reference to the menu', function () {
- var menuItem = KorAP.OwnMenuItem.create(['Test']);
- expect(menuItem.menu()).toBe(undefined);
- });
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual(plain);
- it('should be activatable and deactivateable by class', function () {
- var menuItem = KorAP.OwnMenuItem.create(['Test']);
+ // Starting highlight - short
+ menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
+ menuItem.highlight("c");
+ expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>C</mark>oreNLP</h1><h2><mark>c</mark>orenlp/</h2></div>");
- expect(menuItem.active()).toBe(false);
- expect(menuItem.element().getAttribute("class")).toBe(null);
- menuItem.active(true);
- expect(menuItem.active()).toBe(true);
- expect(menuItem.element().getAttribute("class")).toEqual("active");
- menuItem.active(false); // Is active
- expect(menuItem.active()).toBe(false);
- expect(menuItem.element().getAttribute("class")).toEqual("");
- menuItem.active(true);
- expect(menuItem.active()).toBe(true);
- expect(menuItem.element().getAttribute("class")).toEqual("active");
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual(plain);
- menuItem = KorAP.OwnMenuItem.create(['Spiegel']);
- expect(menuItem.active()).toBe(false);
- expect(menuItem.element().getAttribute("class")).toBe(null);
- menuItem.active(false); // Is not active
- expect(menuItem.active()).toBe(false);
- expect(menuItem.element().getAttribute("class")).toBe(null);
- });
+ // Highlight at the end
+ menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
+ menuItem.highlight("nlp");
+ expect(menuItem.element().innerHTML).toEqual("<div><h1>Core<mark>NLP</mark></h1><h2>core<mark>nlp</mark>/</h2></div>");
- it('should be set to boundary', function () {
- var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
- expect(menuItem.active()).toBe(false);
- expect(menuItem.element().getAttribute("class")).toBe(null);
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual(plain);
- // Set active
- menuItem.active(true);
- expect(menuItem.active()).toBe(true);
- expect(menuItem.noMore()).toBe(false);
- expect(menuItem.element().getAttribute("class")).toEqual("active");
+ // Highlight at the end - short
+ menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
+ menuItem.highlight("p");
+ expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNL<mark>P</mark></h1><h2>corenl<mark>p</mark>/</h2></div>");
- // Set no more
- menuItem.noMore(true);
- expect(menuItem.active()).toBe(true);
- expect(menuItem.noMore()).toBe(true);
- expect(menuItem.element().getAttribute("class")).toEqual("active no-more");
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual(plain);
- // No no more
- menuItem.noMore(false);
- expect(menuItem.active()).toBe(true);
- expect(menuItem.noMore()).toBe(false);
- expect(menuItem.element().getAttribute("class")).toEqual("active");
+ // No highlight
+ menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
+ menuItem.highlight("xp");
+ expect(menuItem.element().innerHTML).toEqual(plain);
- // Set no more, deactivate
- menuItem.noMore(true);
- menuItem.active(false);
- expect(menuItem.active()).toBe(false);
- expect(menuItem.noMore()).toBe(true);
- expect(menuItem.element().getAttribute("class")).toEqual("no-more");
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual(plain);
- // Set active
- menuItem.active(true);
- expect(menuItem.active()).toBe(true);
- expect(menuItem.noMore()).toBe(true);
- expect(menuItem.element().getAttribute("class")).toEqual("no-more active");
+ // Highlight in the middle - first
+ menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
+ menuItem.highlight("ren");
+ expect(menuItem.element().innerHTML).toEqual("<div><h1>Co<mark>reN</mark>LP</h1><h2>co<mark>ren</mark>lp/</h2><h3>This is my Example</h3></div>");
+
+ plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Example</h3></div>"
+
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual(plain);
+
+ // Highlight in the middle - second
+ menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
+ menuItem.highlight("ampl");
+ expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Ex<mark>ampl</mark>e</h3></div>");
+
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual(plain);
+
+ // Highlight in the middle - both
+ menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
+ menuItem.highlight("e");
+ expect(menuItem.element().innerHTML).toEqual("<div><h1>Cor<mark>e</mark>NLP</h1><h2>cor<mark>e</mark>nlp/</h2><h3>This is my <mark>E</mark>xampl<mark>e</mark></h3></div>");
+
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual(plain);
+
+ // Highlight in the end - second
+ menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
+ menuItem.highlight("le");
+ expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Examp<mark>le</mark></h3></div>");
+
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual(plain);
+
+ // Highlight at the beginning - second
+ menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
+ menuItem.highlight("this");
+ expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3><mark>This</mark> is my Example</h3></div>");
+
+ menuItem.lowlight();
+ expect(menuItem.element().innerHTML).toEqual(plain);
+ });
});
- it('should be highlightable', function () {
- // Highlight in the middle
- var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
- menuItem.highlight("ren");
- expect(menuItem.element().innerHTML).toEqual("Co<mark>reN</mark>LP");
-
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual("CoreNLP");
-
- var plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2></div>";
-
- // Starting highlight
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
- menuItem.highlight("cor");
- expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>Cor</mark>eNLP</h1><h2><mark>cor</mark>enlp/</h2></div>");
-
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual(plain);
-
- // Starting highlight - short
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
- menuItem.highlight("c");
- expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>C</mark>oreNLP</h1><h2><mark>c</mark>orenlp/</h2></div>");
-
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual(plain);
-
- // Highlight at the end
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
- menuItem.highlight("nlp");
- expect(menuItem.element().innerHTML).toEqual("<div><h1>Core<mark>NLP</mark></h1><h2>core<mark>nlp</mark>/</h2></div>");
-
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual(plain);
-
- // Highlight at the end - short
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
- menuItem.highlight("p");
- expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNL<mark>P</mark></h1><h2>corenl<mark>p</mark>/</h2></div>");
-
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual(plain);
-
- // No highlight
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
- menuItem.highlight("xp");
- expect(menuItem.element().innerHTML).toEqual(plain);
-
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual(plain);
-
- // Highlight in the middle - first
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
- menuItem.highlight("ren");
- expect(menuItem.element().innerHTML).toEqual("<div><h1>Co<mark>reN</mark>LP</h1><h2>co<mark>ren</mark>lp/</h2><h3>This is my Example</h3></div>");
-
- plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Example</h3></div>"
-
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual(plain);
-
- // Highlight in the middle - second
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
- menuItem.highlight("ampl");
- expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Ex<mark>ampl</mark>e</h3></div>");
-
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual(plain);
-
- // Highlight in the middle - both
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
- menuItem.highlight("e");
- expect(menuItem.element().innerHTML).toEqual("<div><h1>Cor<mark>e</mark>NLP</h1><h2>cor<mark>e</mark>nlp/</h2><h3>This is my <mark>E</mark>xampl<mark>e</mark></h3></div>");
-
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual(plain);
-
- // Highlight in the end - second
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
- menuItem.highlight("le");
- expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Examp<mark>le</mark></h3></div>");
-
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual(plain);
-
- // Highlight at the beginning - second
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
- menuItem.highlight("this");
- expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3><mark>This</mark> is my Example</h3></div>");
-
- menuItem.lowlight();
- expect(menuItem.element().innerHTML).toEqual(plain);
- });
-});
-
-
-describe('KorAP.Menu', function () {
- var list = [
- ["Constituency", "c=", "Example 1"],
- ["Lemma", "l="],
- ["Morphology", "m=", "Example 2"],
- ["Part-of-Speech", "p="],
- ["Syntax", "syn="]
- ];
-
- var demolist = [
- ['Titel', 'title'],
- ['Untertitel', 'subTitle'],
- ['Veröffentlichungsdatum', 'pubDate'],
- ['Länge', 'length'],
- ['Autor', 'author']
- ];
-
- var demolonglist = [
- ['Titel', 'title'],
- ['Untertitel', 'subTitle'],
- ['Veröffentlichungsdatum', 'pubDate'],
- ['Länge', 'length'],
- ['Autor', 'author'],
- ['Genre', 'genre'],
- ['corpusID', 'corpusID'],
- ['docID', 'docID'],
- ['textID', 'textID'],
- ];
-
- it('should be initializable', function () {
+ describe('KorAP.Menu', function () {
var list = [
- ["Constituency"],
- ["Lemma"],
- ["Morphology"],
- ["Part-of-Speech"],
- ["Syntax"]
+ ["Constituency", "c=", "Example 1"],
+ ["Lemma", "l="],
+ ["Morphology", "m=", "Example 2"],
+ ["Part-of-Speech", "p="],
+ ["Syntax", "syn="]
];
- var menu = KorAP.OwnMenu.create(list);
- expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem);
- expect(menu.element().nodeName).toEqual('UL');
- expect(menu.element().style.opacity).toEqual("0");
- expect(menu.limit()).toEqual(8);
+ var demolist = [
+ ['Titel', 'title'],
+ ['Untertitel', 'subTitle'],
+ ['Veröffentlichungsdatum', 'pubDate'],
+ ['Länge', 'length'],
+ ['Autor', 'author']
+ ];
- menu.limit(9);
- expect(menu.limit()).toEqual(9);
+ var demolonglist = [
+ ['Titel', 'title'],
+ ['Untertitel', 'subTitle'],
+ ['Veröffentlichungsdatum', 'pubDate'],
+ ['Länge', 'length'],
+ ['Autor', 'author'],
+ ['Genre', 'genre'],
+ ['corpusID', 'corpusID'],
+ ['docID', 'docID'],
+ ['textID', 'textID'],
+ ];
- menu.limit(8);
+ it('should be initializable', function () {
+ var list = [
+ ["Constituency"],
+ ["Lemma"],
+ ["Morphology"],
+ ["Part-of-Speech"],
+ ["Syntax"]
+ ];
- // view
- menu.show();
+ var menu = KorAP.OwnMenu.create(list);
+ expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem);
+ expect(menu.element().nodeName).toEqual('UL');
+ expect(menu.element().style.opacity).toEqual("0");
+ expect(menu.limit()).toEqual(8);
- // First element in list
- expect(menu.item(0).active()).toBe(true);
- expect(menu.item(0).noMore()).toBe(true);
+ menu.limit(9);
+ expect(menu.limit()).toEqual(9);
- // Middle element in list
- expect(menu.item(2).active()).toBe(false);
- expect(menu.item(2).noMore()).toBe(false);
+ menu.limit(8);
- // Last element in list
- expect(menu.item(menu.length() - 1).active()).toBe(false);
- expect(menu.item(menu.length() - 1).noMore()).toBe(true);
+ // view
+ menu.show();
+
+ // First element in list
+ expect(menu.item(0).active()).toBe(true);
+ expect(menu.item(0).noMore()).toBe(true);
+
+ // Middle element in list
+ expect(menu.item(2).active()).toBe(false);
+ expect(menu.item(2).noMore()).toBe(false);
+
+ // Last element in list
+ expect(menu.item(menu.length() - 1).active()).toBe(false);
+ expect(menu.item(menu.length() - 1).noMore()).toBe(true);
+ });
+
+ it('should have a reference to the menu', function () {
+ var menu = KorAP.HintMenu.create("cnx/", list);
+ expect(menu.item(0).menu()).toEqual(menu);
+
+ menu = KorAP.HintMenu.create("cnx/", list);
+ expect(menu.element().menu).toEqual(menu);
+ });
+
+
+ it('should be visible', function () {
+ var menu = KorAP.HintMenu.create("cnx/", list);
+ expect(menu.delete()).toBe(undefined);
+ menu.limit(3);
+
+ expect(menu.show()).toBe(true);
+
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
+ expect(menu.element().childNodes[2].getAttribute("data-action")).toEqual("l=");
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.element().childNodes[4]).toBe(undefined);
+
+ // Check boundaries
+ expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true);
+ expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false);
+ expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(false);
+ });
+
+ it('should be filterable', function () {
+ var menu = KorAP.HintMenu.create("cnx/", list);
+ menu.limit(3);
+ expect(menu.prefix("o").show()).toBe(true);
+ expect(menu.element().childNodes[0].innerHTML).toEqual("o");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
+ expect(menu.element().childNodes[4]).toBe(undefined);
+
+ // Check boundaries
+ expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true);
+ expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false);
+ expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true);
+
+ menu.limit(2);
+
+ expect(menu.prefix("o").show()).toBe(true);
+ expect(menu.element().childNodes[0].innerHTML).toEqual("o");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
+ expect(menu.element().childNodes[3]).toBe(undefined);
+
+ // Check boundaries
+ expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true);
+ expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false);
+ expect(menu.element().childNodes[3]).toBe(undefined);
+
+ expect(menu.prefix("e").show()).toBe(true);
+ expect(menu.element().childNodes[0].innerHTML).toEqual("e");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
+ expect(menu.element().childNodes[3]).toBe(undefined);
+
+ menu.limit(5);
+ expect(menu.prefix("a").show()).toBe(true);
+ expect(menu.element().childNodes[0].innerHTML).toEqual("a");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>");
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>");
+ expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>");
+ expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>");
+ expect(menu.element().childNodes[6]).toBe(undefined);
+ });
+
+
+ it('should be nextable', function () {
+ var menu = KorAP.HintMenu.create("cnx/", list);
+
+ // Show only 3 items
+ menu.limit(3);
+ expect(menu.show()).toBe(true);
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().childNodes[4]).toBe(undefined);
+
+ // Activate next (1)
+ menu.next();
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().childNodes[4]).toBe(undefined);
+
+ // Activate next (2)
+ menu.next();
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu.element().childNodes[4]).toBe(undefined);
+
+ // Activate next (3)
+ // scroll!
+ menu.next();
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu.element().childNodes[4]).toBe(undefined);
+
+ // Activate next (4)
+ menu.next();
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>");
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu.element().childNodes[4]).toBe(undefined);
+
+ // Activate next (5) - ROLL
+ menu.next();
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().childNodes[4]).toBe(undefined);
+
+ // Active next (6)
+ menu.next();
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().childNodes[4]).toBe(undefined);
+ });
+
+ it('should be prevable', function () {
+ var menu = KorAP.HintMenu.create("cnx/", list);
+ menu.limit(3);
+ expect(menu.show()).toBe(true);
+
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().childNodes[4]).toBe(undefined);
+
+ // Activate prev (1) - roll to bottom
+ menu.prev();
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>");
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu.element().childNodes[4]).toBe(undefined);
+
+ // Activate prev (2)
+ menu.prev();
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().childNodes[4]).toBe(undefined);
+
+ // Activate prev (3)
+ menu.prev();
+ expect(menu.shownItem(0).name()).toEqual("Morphology");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Syntax");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().childNodes[4]).toBe(undefined);
+
+ // Activate prev (4)
+ menu.prev();
+ expect(menu.shownItem(0).name()).toEqual("Lemma");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Part-of-Speech");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().childNodes[4]).toBe(undefined);
+
+ // Activate prev (5)
+ menu.prev();
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Lemma");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Morphology");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().childNodes[4]).toBe(undefined);
+
+ // Activate next (1)
+ menu.next();
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Lemma");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2).name()).toEqual("Morphology");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().childNodes[4]).toBe(undefined);
+
+ // Activate prev (6)
+ menu.prev();
+
+ // Activate prev (7)
+ menu.prev();
+ expect(menu.shownItem(0).name()).toEqual("Morphology");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Syntax");
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu.element().childNodes[4]).toBe(undefined);
+ });
+
+
+ it('should be navigatable and filterable (prefix = "o")', function () {
+ var menu = KorAP.HintMenu.create("cnx/", list);
+ menu.limit(2);
+
+ expect(menu.prefix("o").show()).toBe(true);
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Next (1)
+ menu.next();
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Next (2)
+ menu.next();
+ expect(menu.shownItem(0).name()).toEqual("Morphology");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Next (3) - to prefix
+ menu.next();
+ expect(menu.shownItem(0).name()).toEqual("Morphology");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ menu.next();
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+ });
+
+
+ it('should be navigatable and filterable (prefix = "ex", "e")', function () {
+ var menu = KorAP.HintMenu.create("cnx/", list);
+
+ menu.limit(2);
+ expect(menu.prefix("ex").show()).toBe(true);
+
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Next (1)
+ menu.next();
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Next (2)
+ menu.next();
+
+ expect(menu.prefix()).toEqual('ex');
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Reset limit
+ menu.limit(5);
+
+ // Change show
+ expect(menu.prefix("e").show()).toBe(true);
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Next (1)
+ menu.next();
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu.prefix()).toEqual('e');
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Next (2)
+ menu.next();
+ expect(menu._prefix.active()).toBe(true);
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Next (3)
+ menu.next();
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+ });
+
+
+ it('shouldn\'t be viewable with failing prefix', function () {
+ var menu = KorAP.HintMenu.create("cnx/", list);
+ menu.limit(2);
+ expect(menu.prefix("exit").show()).toBe(false);
+ });
+
+ it('should be navigatable with prefix', function () {
+ var menu = KorAP.HintMenu.create("cnx/", demolist);
+ menu.limit(3);
+
+ expect(menu.show()).toBe(true);
+ expect(menu.prefix()).toEqual("");
+
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.shownItem(3)).toBe(undefined);
+
+ menu._prefix.add('a');
+ expect(menu.show()).toBe(true);
+ expect(menu.prefix()).toEqual("a");
+ expect(menu.shownItem(0).name()).toEqual("Autor");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
+
+ menu._prefix.add('u');
+ expect(menu.show()).toBe(true);
+ expect(menu.prefix()).toEqual("au");
+ expect(menu.shownItem(0).name()).toEqual("Autor");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>");
+
+ menu._prefix.backspace();
+ expect(menu.show()).toBe(true);
+ expect(menu.prefix()).toEqual("a");
+ expect(menu.shownItem(0).name()).toEqual("Autor");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
+
+ menu._prefix.backspace();
+ expect(menu.show()).toBe(true);
+ expect(menu.prefix()).toEqual("");
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.shownItem(3)).toBe(undefined);
+
+ // Forward
+ menu._prefix.backspace();
+ expect(menu.show()).toBe(true);
+ expect(menu.prefix()).toEqual("");
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
+ expect(menu.shownItem(2).active()).toBe(false);
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("");
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.shownItem(3)).toBe(undefined);
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("");
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu.shownItem(3)).toBe(undefined);
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("");
+ expect(menu.shownItem(0).name()).toEqual("Untertitel");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Untertitel</strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Länge");
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Länge</strong>");
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu.shownItem(3)).toBe(undefined);
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("");
+ expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Länge");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Länge</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Autor");
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Autor</strong>");
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu.shownItem(3)).toBe(undefined);
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("");
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
+ expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ });
+
+
+ it('should be navigatable with a prefix (1)', function () {
+ var menu = KorAP.HintMenu.create("cnx/", demolist);
+ menu.limit(3);
+
+ expect(menu.show()).toBe(true);
+ expect(menu.prefix()).toEqual("");
+
+ menu.prefix('el');
+ expect(menu.show()).toBe(true);
+
+ expect(menu.prefix()).toEqual("el");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("el");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("el");
+ expect(menu._prefix.active()).toEqual(true);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Backward
+ menu.prev();
+ expect(menu.prefix()).toEqual("el");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2)).toBe(undefined);
+ });
+
+
+ it('should be navigatable with a prefix (2)', function () {
+ var menu = KorAP.HintMenu.create("cnx/", demolist);
+ menu.limit(3);
+ expect(menu.show()).toBe(true);
+ expect(menu.prefix()).toEqual("");
+ menu.prefix('el');
+ expect(menu.show()).toBe(true);
+
+ expect(menu.prefix()).toEqual("el");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Backward
+ menu.prev();
+ expect(menu._prefix.active()).toEqual(true);
+
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Backward
+ menu.prev();
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2)).toBe(undefined);
+ });
+
+ it('should be navigatable with a prefix (3)', function () {
+ var menu = KorAP.HintMenu.create("cnx/", demolist);
+ menu.limit(3);
+ expect(menu.show()).toBe(true);
+ expect(menu.prefix()).toEqual("");
+ menu.prefix('el');
+ expect(menu.show()).toBe(true);
+
+ expect(menu.prefix()).toEqual("el");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Backward
+ menu.prev();
+ expect(menu._prefix.active()).toEqual(true);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("el");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ });
+
+ xit('should be page downable');
+ xit('should be page upable');
+
+ xit('should scroll to a chosen value')
+ xit('should highlight a chosen value')
});
-
- it('should have a reference to the menu', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
- expect(menu.item(0).menu()).toEqual(menu);
-
- menu = KorAP.HintMenu.create("cnx/", list);
- expect(menu.element().menu).toEqual(menu);
- });
-
-
- it('should be visible', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
- expect(menu.delete()).toBe(undefined);
- menu.limit(3);
-
- expect(menu.show()).toBe(true);
-
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
- expect(menu.element().childNodes[2].getAttribute("data-action")).toEqual("l=");
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
- expect(menu.element().childNodes[4]).toBe(undefined);
-
- // Check boundaries
- expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true);
- expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false);
- expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(false);
- });
-
- it('should be filterable', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
- menu.limit(3);
- expect(menu.prefix("o").show()).toBe(true);
- expect(menu.element().childNodes[0].innerHTML).toEqual("o");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
- expect(menu.element().childNodes[4]).toBe(undefined);
-
- // Check boundaries
- expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true);
- expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false);
- expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true);
-
- menu.limit(2);
-
- expect(menu.prefix("o").show()).toBe(true);
- expect(menu.element().childNodes[0].innerHTML).toEqual("o");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
- expect(menu.element().childNodes[3]).toBe(undefined);
-
- // Check boundaries
- expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true);
- expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false);
- expect(menu.element().childNodes[3]).toBe(undefined);
-
- expect(menu.prefix("e").show()).toBe(true);
- expect(menu.element().childNodes[0].innerHTML).toEqual("e");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
- expect(menu.element().childNodes[3]).toBe(undefined);
-
- menu.limit(5);
- expect(menu.prefix("a").show()).toBe(true);
- expect(menu.element().childNodes[0].innerHTML).toEqual("a");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>");
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>");
- expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>");
- expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>");
- expect(menu.element().childNodes[6]).toBe(undefined);
- });
-
-
- it('should be nextable', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
-
- // Show only 3 items
- menu.limit(3);
- expect(menu.show()).toBe(true);
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
- expect(menu.shownItem(2).active()).toBe(false);
- expect(menu.element().childNodes[4]).toBe(undefined);
-
- // Activate next (1)
- menu.next();
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
- expect(menu.shownItem(1).active()).toBe(true);
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
- expect(menu.shownItem(2).active()).toBe(false);
- expect(menu.element().childNodes[4]).toBe(undefined);
-
- // Activate next (2)
- menu.next();
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
- expect(menu.shownItem(2).active()).toBe(true);
- expect(menu.element().childNodes[4]).toBe(undefined);
-
- // Activate next (3)
- // scroll!
- menu.next();
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
- expect(menu.shownItem(2).active()).toBe(true);
- expect(menu.element().childNodes[4]).toBe(undefined);
-
- // Activate next (4)
- menu.next();
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>");
- expect(menu.shownItem(2).active()).toBe(true);
- expect(menu.element().childNodes[4]).toBe(undefined);
-
- // Activate next (5) - ROLL
- menu.next();
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
- expect(menu.shownItem(2).active()).toBe(false);
- expect(menu.element().childNodes[4]).toBe(undefined);
-
- // Active next (6)
- menu.next();
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
- expect(menu.shownItem(1).active()).toBe(true);
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
- expect(menu.shownItem(2).active()).toBe(false);
- expect(menu.element().childNodes[4]).toBe(undefined);
- });
-
- it('should be prevable', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
- menu.limit(3);
- expect(menu.show()).toBe(true);
-
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
- expect(menu.shownItem(2).active()).toBe(false);
- expect(menu.element().childNodes[4]).toBe(undefined);
-
- // Activate prev (1) - roll to bottom
- menu.prev();
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>");
- expect(menu.shownItem(2).active()).toBe(true);
- expect(menu.element().childNodes[4]).toBe(undefined);
-
- // Activate prev (2)
- menu.prev();
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
- expect(menu.shownItem(1).active()).toBe(true);
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>");
- expect(menu.shownItem(2).active()).toBe(false);
- expect(menu.element().childNodes[4]).toBe(undefined);
-
- // Activate prev (3)
- menu.prev();
- expect(menu.shownItem(0).name()).toEqual("Morphology");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2).name()).toEqual("Syntax");
- expect(menu.shownItem(2).active()).toBe(false);
- expect(menu.element().childNodes[4]).toBe(undefined);
-
- // Activate prev (4)
- menu.prev();
- expect(menu.shownItem(0).name()).toEqual("Lemma");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.shownItem(1).name()).toEqual("Morphology");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2).name()).toEqual("Part-of-Speech");
- expect(menu.shownItem(2).active()).toBe(false);
- expect(menu.element().childNodes[4]).toBe(undefined);
-
- // Activate prev (5)
- menu.prev();
- expect(menu.shownItem(0).name()).toEqual("Constituency");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.shownItem(1).name()).toEqual("Lemma");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2).name()).toEqual("Morphology");
- expect(menu.shownItem(2).active()).toBe(false);
- expect(menu.element().childNodes[4]).toBe(undefined);
-
- // Activate next (1)
- menu.next();
- expect(menu.shownItem(0).name()).toEqual("Constituency");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.shownItem(1).name()).toEqual("Lemma");
- expect(menu.shownItem(1).active()).toBe(true);
- expect(menu.shownItem(2).name()).toEqual("Morphology");
- expect(menu.shownItem(2).active()).toBe(false);
- expect(menu.element().childNodes[4]).toBe(undefined);
-
- // Activate prev (6)
- menu.prev();
-
- // Activate prev (7)
- menu.prev();
- expect(menu.shownItem(0).name()).toEqual("Morphology");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2).name()).toEqual("Syntax");
- expect(menu.shownItem(2).active()).toBe(true);
- expect(menu.element().childNodes[4]).toBe(undefined);
- });
-
-
- it('should be navigatable and filterable (prefix = "o")', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
- menu.limit(2);
-
- expect(menu.prefix("o").show()).toBe(true);
- expect(menu.shownItem(0).name()).toEqual("Constituency");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.shownItem(1).name()).toEqual("Morphology");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2)).toBe(undefined);
-
- // Next (1)
- menu.next();
- expect(menu.shownItem(0).name()).toEqual("Constituency");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.shownItem(1).name()).toEqual("Morphology");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
- expect(menu.shownItem(1).active()).toBe(true);
- expect(menu.shownItem(2)).toBe(undefined);
-
- // Next (2)
- menu.next();
- expect(menu.shownItem(0).name()).toEqual("Morphology");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
- expect(menu.shownItem(1).active()).toBe(true);
- expect(menu.shownItem(2)).toBe(undefined);
-
- // Next (3) - to prefix
- menu.next();
- expect(menu.shownItem(0).name()).toEqual("Morphology");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2)).toBe(undefined);
-
- menu.next();
- expect(menu.shownItem(0).name()).toEqual("Constituency");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.shownItem(1).name()).toEqual("Morphology");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2)).toBe(undefined);
- });
-
-
- it('should be navigatable and filterable (prefix = "ex", "e")', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
-
- menu.limit(2);
- expect(menu.prefix("ex").show()).toBe(true);
-
- expect(menu.shownItem(0).name()).toEqual("Constituency");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.shownItem(1).name()).toEqual("Morphology");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2)).toBe(undefined);
-
- // Next (1)
- menu.next();
- expect(menu.shownItem(0).name()).toEqual("Constituency");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.shownItem(1).name()).toEqual("Morphology");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
- expect(menu.shownItem(1).active()).toBe(true);
- expect(menu.shownItem(2)).toBe(undefined);
-
- // Next (2)
- menu.next();
-
- expect(menu.prefix()).toEqual('ex');
- expect(menu.shownItem(0).name()).toEqual("Constituency");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
- expect(menu.shownItem(0).active()).toBe(false);
-
- expect(menu.shownItem(1).name()).toEqual("Morphology");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2)).toBe(undefined);
-
- // Reset limit
- menu.limit(5);
-
- // Change show
- expect(menu.prefix("e").show()).toBe(true);
- expect(menu._prefix.active()).toBe(false);
- expect(menu.shownItem(0).name()).toEqual("Constituency");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.shownItem(1).name()).toEqual("Morphology");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2)).toBe(undefined);
-
- // Next (1)
- menu.next();
- expect(menu._prefix.active()).toBe(false);
- expect(menu.prefix()).toEqual('e');
- expect(menu.shownItem(0).name()).toEqual("Constituency");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.shownItem(1).name()).toEqual("Morphology");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
- expect(menu.shownItem(1).active()).toBe(true);
- expect(menu.shownItem(2)).toBe(undefined);
-
- // Next (2)
- menu.next();
- expect(menu._prefix.active()).toBe(true);
- expect(menu.shownItem(0).name()).toEqual("Constituency");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.shownItem(1).name()).toEqual("Morphology");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2)).toBe(undefined);
-
- // Next (3)
- menu.next();
- expect(menu._prefix.active()).toBe(false);
- expect(menu.shownItem(0).name()).toEqual("Constituency");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.shownItem(1).name()).toEqual("Morphology");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2)).toBe(undefined);
- });
-
-
- it('shouldn\'t be viewable with failing prefix', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
- menu.limit(2);
- expect(menu.prefix("exit").show()).toBe(false);
- });
-
- it('should be navigatable with prefix', function () {
- var menu = KorAP.HintMenu.create("cnx/", demolist);
- menu.limit(3);
-
- expect(menu.show()).toBe(true);
- expect(menu.prefix()).toEqual("");
-
- expect(menu.shownItem(0).name()).toEqual("Titel");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.shownItem(1).name()).toEqual("Untertitel");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
- expect(menu.shownItem(2).active()).toBe(false);
- expect(menu.shownItem(3)).toBe(undefined);
-
- menu._prefix.add('a');
- expect(menu.show()).toBe(true);
- expect(menu.prefix()).toEqual("a");
- expect(menu.shownItem(0).name()).toEqual("Autor");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
-
- menu._prefix.add('u');
- expect(menu.show()).toBe(true);
- expect(menu.prefix()).toEqual("au");
- expect(menu.shownItem(0).name()).toEqual("Autor");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>");
-
- menu._prefix.backspace();
- expect(menu.show()).toBe(true);
- expect(menu.prefix()).toEqual("a");
- expect(menu.shownItem(0).name()).toEqual("Autor");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
-
- menu._prefix.backspace();
- expect(menu.show()).toBe(true);
- expect(menu.prefix()).toEqual("");
- expect(menu.shownItem(0).name()).toEqual("Titel");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.shownItem(1).name()).toEqual("Untertitel");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
- expect(menu.shownItem(2).active()).toBe(false);
- expect(menu.shownItem(3)).toBe(undefined);
-
- // Forward
- menu._prefix.backspace();
- expect(menu.show()).toBe(true);
- expect(menu.prefix()).toEqual("");
- expect(menu.shownItem(0).name()).toEqual("Titel");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.shownItem(1).name()).toEqual("Untertitel");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
- expect(menu.shownItem(2).active()).toBe(false);
-
- // Forward
- menu.next();
- expect(menu.prefix()).toEqual("");
- expect(menu.shownItem(0).name()).toEqual("Titel");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.shownItem(1).name()).toEqual("Untertitel");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
- expect(menu.shownItem(1).active()).toBe(true);
- expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
- expect(menu.shownItem(2).active()).toBe(false);
- expect(menu.shownItem(3)).toBe(undefined);
-
- // Forward
- menu.next();
- expect(menu.prefix()).toEqual("");
- expect(menu.shownItem(0).name()).toEqual("Titel");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.shownItem(1).name()).toEqual("Untertitel");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
- expect(menu.shownItem(2).active()).toBe(true);
- expect(menu.shownItem(3)).toBe(undefined);
-
- // Forward
- menu.next();
- expect(menu.prefix()).toEqual("");
- expect(menu.shownItem(0).name()).toEqual("Untertitel");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Untertitel</strong>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2).name()).toEqual("Länge");
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Länge</strong>");
- expect(menu.shownItem(2).active()).toBe(true);
- expect(menu.shownItem(3)).toBe(undefined);
-
- // Forward
- menu.next();
- expect(menu.prefix()).toEqual("");
- expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.shownItem(1).name()).toEqual("Länge");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Länge</strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2).name()).toEqual("Autor");
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Autor</strong>");
- expect(menu.shownItem(2).active()).toBe(true);
- expect(menu.shownItem(3)).toBe(undefined);
-
- // Forward
- menu.next();
- expect(menu.prefix()).toEqual("");
- expect(menu.shownItem(0).name()).toEqual("Titel");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.shownItem(1).name()).toEqual("Untertitel");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
- expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
- expect(menu.shownItem(2).active()).toBe(false);
-
- });
-
-
- it('should be navigatable with a prefix (1)', function () {
- var menu = KorAP.HintMenu.create("cnx/", demolist);
- menu.limit(3);
-
- expect(menu.show()).toBe(true);
- expect(menu.prefix()).toEqual("");
-
- menu.prefix('el');
- expect(menu.show()).toBe(true);
-
- expect(menu.prefix()).toEqual("el");
- expect(menu._prefix.active()).toEqual(false);
- expect(menu.shownItem(0).name()).toEqual("Titel");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.shownItem(1).name()).toEqual("Untertitel");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2)).toBe(undefined);
-
- // Forward
- menu.next();
- expect(menu.prefix()).toEqual("el");
- expect(menu._prefix.active()).toEqual(false);
- expect(menu.shownItem(0).name()).toEqual("Titel");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.shownItem(1).name()).toEqual("Untertitel");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
- expect(menu.shownItem(1).active()).toBe(true);
- expect(menu.shownItem(2)).toBe(undefined);
-
- // Forward
- menu.next();
- expect(menu.prefix()).toEqual("el");
- expect(menu._prefix.active()).toEqual(true);
- expect(menu.shownItem(0).name()).toEqual("Titel");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.shownItem(1).name()).toEqual("Untertitel");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2)).toBe(undefined);
-
-
- // Backward
- menu.prev();
- expect(menu.prefix()).toEqual("el");
- expect(menu._prefix.active()).toEqual(false);
- expect(menu.shownItem(0).name()).toEqual("Titel");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
- expect(menu.shownItem(0).active()).toBe(false);
-
- expect(menu.shownItem(1).name()).toEqual("Untertitel");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
- expect(menu.shownItem(1).active()).toBe(true);
- expect(menu.shownItem(2)).toBe(undefined);
- });
-
-
- it('should be navigatable with a prefix (2)', function () {
- var menu = KorAP.HintMenu.create("cnx/", demolist);
- menu.limit(3);
- expect(menu.show()).toBe(true);
- expect(menu.prefix()).toEqual("");
- menu.prefix('el');
- expect(menu.show()).toBe(true);
-
- expect(menu.prefix()).toEqual("el");
- expect(menu._prefix.active()).toEqual(false);
- expect(menu.shownItem(0).name()).toEqual("Titel");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.shownItem(1).name()).toEqual("Untertitel");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2)).toBe(undefined);
-
- // Backward
- menu.prev();
- expect(menu._prefix.active()).toEqual(true);
-
- expect(menu.shownItem(0).name()).toEqual("Titel");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
- expect(menu.shownItem(0).active()).toBe(false);
-
- expect(menu.shownItem(1).name()).toEqual("Untertitel");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2)).toBe(undefined);
-
- // Backward
- menu.prev();
- expect(menu._prefix.active()).toEqual(false);
- expect(menu.shownItem(0).name()).toEqual("Titel");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.shownItem(1).name()).toEqual("Untertitel");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
- expect(menu.shownItem(1).active()).toBe(true);
- expect(menu.shownItem(2)).toBe(undefined);
- });
-
- it('should be navigatable with a prefix (3)', function () {
- var menu = KorAP.HintMenu.create("cnx/", demolist);
- menu.limit(3);
- expect(menu.show()).toBe(true);
- expect(menu.prefix()).toEqual("");
- menu.prefix('el');
- expect(menu.show()).toBe(true);
-
- expect(menu.prefix()).toEqual("el");
- expect(menu._prefix.active()).toEqual(false);
- expect(menu.shownItem(0).name()).toEqual("Titel");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.shownItem(1).name()).toEqual("Untertitel");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2)).toBe(undefined);
-
- // Backward
- menu.prev();
- expect(menu._prefix.active()).toEqual(true);
- expect(menu.shownItem(0).name()).toEqual("Titel");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
- expect(menu.shownItem(0).active()).toBe(false);
- expect(menu.shownItem(1).name()).toEqual("Untertitel");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2)).toBe(undefined);
-
-
- // Forward
- menu.next();
- expect(menu.prefix()).toEqual("el");
- expect(menu._prefix.active()).toEqual(false);
- expect(menu.shownItem(0).name()).toEqual("Titel");
- expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
- expect(menu.shownItem(0).active()).toBe(true);
- expect(menu.shownItem(1).name()).toEqual("Untertitel");
- expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
- expect(menu.shownItem(1).active()).toBe(false);
- expect(menu.shownItem(2)).toBe(undefined);
-
- });
-
- xit('should be page downable');
- xit('should be page upable');
-
- xit('should scroll to a chosen value')
- xit('should highlight a chosen value')
});
diff --git a/dev/js/spec/vcSpec.js b/dev/js/spec/vcSpec.js
index 1a24fb6..3dd0749 100644
--- a/dev/js/spec/vcSpec.js
+++ b/dev/js/spec/vcSpec.js
@@ -1,1898 +1,1918 @@
/*
-Todo: In demoSpec: Create "and" on the last element of the top "or"-Group
-*/
+ * Todo: In demoSpec: Create "and" on the last element of the top "or"-Group
+ */
+define(['vc'], function () {
+ var vcClass = require('vc');
+ var docClass = require('vc/doc');
+ var docGroupClass = require('vc/docgroup');
+ var unspecifiedClass = require('vc/unspecified');
+ var operatorsClass = require('vc/operators');
+ var rewriteClass = require('vc/rewrite');
-// Helper method for building factories
-buildFactory = function (objClass, defaults) {
- return {
- create : function (overwrites) {
- var newObj = {};
- for (var prop in defaults) {
- newObj[prop] = defaults[prop];
- };
- for (var prop in overwrites) {
- newObj[prop] = overwrites[prop];
- };
- if (objClass === KorAP.VirtualCollection)
- return objClass.render(newObj);
- else
- return objClass.create().fromJson(newObj);
+ // Helper method for building factories
+ buildFactory = function (objClass, defaults) {
+ return {
+ create : function (overwrites) {
+ var newObj = {};
+ for (var prop in defaults) {
+ newObj[prop] = defaults[prop];
+ };
+ for (var prop in overwrites) {
+ newObj[prop] = overwrites[prop];
+ };
+ if (objClass === vcClass)
+ return objClass.render(newObj);
+ else
+ return objClass.create().fromJson(newObj);
+ }
}
- }
-};
+ };
-function _andOn (obj) {
- KorAP._and.bind(obj.element().lastChild.firstChild).apply();
-};
+ function _andOn (obj) {
+ KorAP._and.bind(obj.element().lastChild.firstChild).apply();
+ };
-function _orOn (obj) {
- KorAP._or.bind(obj.element().lastChild.firstChild).apply();
-};
+ function _orOn (obj) {
+ KorAP._or.bind(obj.element().lastChild.firstChild).apply();
+ };
-function _delOn (obj) {
- KorAP._delete.bind(obj.element().lastChild.firstChild).apply();
-};
+ function _delOn (obj) {
+ KorAP._delete.bind(obj.element().lastChild.firstChild).apply();
+ };
-var demoFactory = buildFactory(KorAP.VirtualCollection, {
- "@type":"koral:docGroup",
- "operation":"operation:or",
- "operands":[
- {
- "@type":"koral:docGroup",
- "operation":"operation:and",
- "operands":[
- {
- "@type":"koral:doc",
- "key":"Titel",
- "value":"Baum",
- "match":"match:eq"
- },
- {
- "@type":"koral:doc",
- "key":"Veröffentlichungsort",
- "value":"hihi",
- "match":"match:eq"
- },
- {
- "@type":"koral:docGroup",
- "operation":"operation:or",
- "operands":[
- {
- "@type":"koral:doc",
- "key":"Titel",
- "value":"Baum",
- "match":"match:eq"
- },
- {
- "@type":"koral:doc",
- "key":"Veröffentlichungsort",
- "value":"hihi",
- "match":"match:eq"
- }
- ]
- }
- ]
- },
- {
- "@type":"koral:doc",
- "key":"Untertitel",
- "value":"huhu",
- "match":"match:eq"
- }
- ]
-});
-
-
-describe('KorAP.Doc', function () {
-
- // Create example factories
- var stringFactory = buildFactory(KorAP.Doc, {
- "key" : "author",
- "value" : "Max Birkendale",
- "@type" : "koral:doc"
- });
-
- // Create example factories
- var dateFactory = buildFactory(KorAP.Doc, {
- "key" : "pubDate",
- "type" : "type:date",
- "match" : "match:eq",
- "value" : "2014-11-05",
- "@type" : "koral:doc"
- });
-
- // Create example factories
- var regexFactory = buildFactory(KorAP.Doc, {
- "key" : "title",
- "type" : "type:regex",
- "value" : "[^b]ee.+?",
- "@type" : "koral:doc"
- });
-
- it('should be initializable', function () {
- var doc = KorAP.Doc.create();
- expect(doc.matchop()).toEqual('eq');
- expect(doc.key()).toBeUndefined();
- expect(doc.value()).toBeUndefined();
- expect(doc.type()).toEqual("string");
- });
-
- it('should be definable', function () {
-
- // Empty doc
- var doc = KorAP.Doc.create();
-
- // Set values
- doc.key("title");
- doc.value("Der alte Mann");
- expect(doc.matchop()).toEqual('eq');
- expect(doc.key()).toEqual("title");
- expect(doc.type()).toEqual("string");
- expect(doc.value()).toEqual("Der alte Mann");
- });
-
-
- it('should deserialize JSON-LD string', function () {
- var doc;
-
- // String default
- doc = stringFactory.create();
- expect(doc.matchop()).toEqual('eq');
- expect(doc.key()).toEqual("author");
- expect(doc.type()).toEqual("string");
- expect(doc.value()).toEqual("Max Birkendale");
-
- // No valid string
- doc = stringFactory.create({
- value : undefined
- });
- expect(doc).toBeUndefined();
-
- // No valid string
- doc = stringFactory.create({
- value : { "foo" : "bar" }
- });
- expect(doc).toBeUndefined();
-
- // Change match type
- doc = stringFactory.create({
- "match" : "match:ne"
- });
-
- expect(doc.matchop()).toEqual('ne');
- expect(doc.key()).toEqual("author");
- expect(doc.type()).toEqual("string");
- expect(doc.value()).toEqual("Max Birkendale");
-
-
- // Invalid match type
- doc = stringFactory.create({
- "match" : { "foo" : "bar" }
- });
- expect(doc).toBeUndefined();
- });
-
- it('should deserialize JSON-LD regex', function () {
- var doc = regexFactory.create();
- expect(doc.key()).toEqual("title");
- expect(doc.type()).toEqual("regex");
- expect(doc.value()).toEqual("[^b]ee.+?");
- expect(doc.matchop()).toEqual('eq');
-
- // change matcher
- doc = regexFactory.create({
- match : "match:ne"
- });
- expect(doc.matchop()).toEqual('ne');
-
- // Invalid matcher
- doc = regexFactory.create({
- match : "match:chook"
- });
- expect(doc).toBeUndefined();
-
- // Invalid regex
- doc = regexFactory.create({
- value : "[^b"
- });
- expect(doc).toBeUndefined();
- });
-
- it('should deserialize JSON-LD date', function () {
-
- // Normal date
- doc = dateFactory.create({});
-
- expect(doc.matchop()).toEqual('eq');
- expect(doc.key()).toEqual("pubDate");
- expect(doc.type()).toEqual("date");
- expect(doc.value()).toEqual("2014-11-05");
-
- // Short date 1
- doc = dateFactory.create({
- "value" : "2014-11"
- });
-
- expect(doc.matchop()).toEqual('eq');
- expect(doc.key()).toEqual("pubDate");
- expect(doc.type()).toEqual("date");
- expect(doc.value()).toEqual("2014-11");
-
- // Short date 2
- doc = dateFactory.create({
- "value" : "2014"
- });
-
- expect(doc.matchop()).toEqual('eq');
- expect(doc.key()).toEqual("pubDate");
- expect(doc.type()).toEqual("date");
- expect(doc.value()).toEqual("2014");
-
- // Invalid date!
- doc = dateFactory.create({
- "value" : "2014-11-050"
- });
- expect(doc).toBeUndefined();
-
- // Invalid matcher!
- doc = dateFactory.create({
- "match" : "match:ne",
- });
- expect(doc).toBeUndefined();
- });
-
- it('should be serializale to JSON', function () {
-
- // Empty doc
- var doc = KorAP.Doc.create();
- expect(doc.toJson()).toEqual(jasmine.any(Object));
-
- // Serialize string
- doc = stringFactory.create();
- expect(doc.toJson()).toEqual(jasmine.objectContaining({
- "@type" : "koral:doc",
- "type" : "type:string",
- "key" : "author",
- "value" : "Max Birkendale",
- "match" : "match:eq"
- }));
-
- // Serialize regex
- doc = regexFactory.create();
- expect(doc.toJson()).toEqual(jasmine.objectContaining({
- "@type" : "koral:doc",
- "type" : "type:regex",
- "value" : "[^b]ee.+?",
- "match" : "match:eq",
- "key" : 'title'
- }));
-
- doc = regexFactory.create({
- match: "match:ne"
- });
- expect(doc.toJson()).toEqual(jasmine.objectContaining({
- "@type" : "koral:doc",
- "type" : "type:regex",
- "value" : "[^b]ee.+?",
- "match" : "match:ne",
- "key" : 'title'
- }));
-
- doc = dateFactory.create();
- expect(doc.toJson()).toEqual(jasmine.objectContaining({
- "@type" : "koral:doc",
- "type" : "type:date",
- "value" : "2014-11-05",
- "match" : "match:eq",
- "key" : 'pubDate'
- }));
-
- doc = dateFactory.create({
- value : "2014"
- });
- expect(doc.toJson()).toEqual(jasmine.objectContaining({
- "@type" : "koral:doc",
- "type" : "type:date",
- "value" : "2014",
- "match" : "match:eq",
- "key" : 'pubDate'
- }));
- });
-
- it('should be serializale to String', function () {
-
- // Empty doc
- var doc = KorAP.Doc.create();
- expect(doc.toQuery()).toEqual("");
-
- // Serialize string
- doc = stringFactory.create();
- expect(doc.toQuery()).toEqual('author = "Max Birkendale"');
-
- // Serialize string with quotes
- doc = stringFactory.create({ "value" : 'Max "Der Coole" Birkendate'});
- expect(doc.toQuery()).toEqual('author = "Max \\"Der Coole\\" Birkendate"');
-
- // Serialize regex
- doc = regexFactory.create();
- expect(doc.toQuery()).toEqual('title = /[^b]ee.+?/');
-
- doc = regexFactory.create({
- match: "match:ne"
- });
- expect(doc.toQuery()).toEqual('title != /[^b]ee.+?/');
-
- doc = dateFactory.create();
- expect(doc.toQuery()).toEqual('pubDate in 2014-11-05');
-
- doc = dateFactory.create({
- value : "2014"
- });
- expect(doc.toQuery()).toEqual('pubDate in 2014');
- });
-});
-
-
-describe('KorAP.DocGroup', function () {
- // Create example factories
- var docFactory = buildFactory(
- KorAP.Doc,
- {
- "@type" : "koral:doc",
- "match":"match:eq",
- "key" : "author",
- "value" : "Max Birkendale"
- }
- );
-
- var docGroupFactory = buildFactory(
- KorAP.DocGroup, {
- "@type" : "koral:docGroup",
- "operation" : "operation:and",
- "operands" : [
- docFactory.create().toJson(),
- docFactory.create({
- "key" : "pubDate",
- "type" : "type:date",
- "value" : "2014-12-05"
- }).toJson()
- ]
- });
-
-
- it('should be initializable', function () {
- // Create empty group
- var docGroup = KorAP.DocGroup.create();
- expect(docGroup.operation()).toEqual('and');
-
- // Create empty group
- docGroup = KorAP.DocGroup.create();
- docGroup.operation('or');
- expect(docGroup.operation()).toEqual('or');
- });
-
- it('should be definable', function () {
-
- // Empty group
- var docGroup = KorAP.DocGroup.create();
- expect(docGroup.operation()).toEqual('and');
-
- // Set values
- docGroup.operation("or");
- expect(docGroup.operation()).toEqual('or');
-
- // Set invalid values
- docGroup.operation("hui");
- expect(docGroup.operation()).toEqual('or');
- });
-
- it('should be deserializable', function () {
- var docGroup = docGroupFactory.create();
- expect(docGroup.operation()).toEqual("and");
- expect(docGroup.operands().length).toEqual(2);
-
- var op1 = docGroup.getOperand(0);
- expect(op1.type()).toEqual("string");
- expect(op1.key()).toEqual("author");
- expect(op1.value()).toEqual("Max Birkendale");
- expect(op1.matchop()).toEqual("eq");
-
- var op2 = docGroup.getOperand(1);
- expect(op2.type()).toEqual("date");
- expect(op2.key()).toEqual("pubDate");
- expect(op2.value()).toEqual("2014-12-05");
- expect(op2.matchop()).toEqual("eq");
-
- // Append empty group
- var newGroup = docGroup.append(KorAP.DocGroup.create());
- newGroup.operation('or');
- newGroup.append(docFactory.create());
- newGroup.append(docFactory.create({
- "type" : "type:regex",
- "key" : "title",
- "value" : "^e.+?$",
- "match" : "match:ne"
- }));
-
- expect(docGroup.operation()).toEqual("and");
- expect(docGroup.operands().length).toEqual(3);
-
- var op1 = docGroup.getOperand(0);
- expect(op1.ldType()).toEqual("doc");
- expect(op1.type()).toEqual("string");
- expect(op1.key()).toEqual("author");
- expect(op1.value()).toEqual("Max Birkendale");
- expect(op1.matchop()).toEqual("eq");
-
- var op2 = docGroup.getOperand(1);
- expect(op2.ldType()).toEqual("doc");
- expect(op2.type()).toEqual("date");
- expect(op2.key()).toEqual("pubDate");
- expect(op2.value()).toEqual("2014-12-05");
- expect(op2.matchop()).toEqual("eq");
-
- var op3 = docGroup.getOperand(2);
- expect(op3.ldType()).toEqual("docGroup");
- expect(op3.operation()).toEqual("or");
-
- var op4 = op3.getOperand(0);
- expect(op4.ldType()).toEqual("doc");
- expect(op4.type()).toEqual("string");
- expect(op4.key()).toEqual("author");
- expect(op4.value()).toEqual("Max Birkendale");
- expect(op4.matchop()).toEqual("eq");
-
- var op5 = op3.getOperand(1);
- expect(op5.ldType()).toEqual("doc");
- expect(op5.type()).toEqual("regex");
- expect(op5.key()).toEqual("title");
- expect(op5.value()).toEqual("^e.+?$");
- expect(op5.matchop()).toEqual("ne");
- });
-
- it('should be serializable to JSON', function () {
- var docGroup = docGroupFactory.create();
-
- expect(docGroup.toJson()).toEqual(jasmine.objectContaining({
- "@type" : "koral:docGroup",
- "operation" : "operation:and",
- "operands" : [
- {
- "@type": 'koral:doc',
- "key" : 'author',
- "match": 'match:eq',
- "value": 'Max Birkendale',
- "type": 'type:string'
- },
- {
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:eq',
- "value": '2014-12-05',
- "type": 'type:date'
- }
- ]
- }));
- });
-
- it('should be serializable to String', function () {
- var docGroup = docGroupFactory.create();
- expect(docGroup.toQuery()).toEqual('author = "Max Birkendale" & pubDate in 2014-12-05');
-
- docGroup = docGroupFactory.create({
- "@type" : "koral:docGroup",
- "operation" : "operation:or",
- "operands" : [
- {
- "@type": 'koral:doc',
- "key" : 'author',
- "match": 'match:eq',
- "value": 'Max Birkendale',
- "type": 'type:string'
- },
- {
- "@type" : "koral:docGroup",
- "operation" : "operation:and",
- "operands" : [
- {
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:geq',
- "value": '2014-05-12',
- "type": 'type:date'
- },
- {
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:leq',
- "value": '2014-12-05',
- "type": 'type:date'
- },
- {
- "@type": 'koral:doc',
- "key": 'foo',
- "match": 'match:ne',
- "value": '[a]?bar',
- "type": 'type:regex'
- }
- ]
- }
- ]
- });
- expect(docGroup.toQuery()).toEqual(
- 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05 & foo != /[a]?bar/)'
- );
- });
-});
-
-describe('KorAP.UnspecifiedDoc', function () {
- it('should be initializable', function () {
- var doc = KorAP.UnspecifiedDoc.create();
- var docElement = doc.element();
- expect(docElement.getAttribute('class')).toEqual('doc unspecified');
- expect(docElement.firstChild.firstChild.data).toEqual('⋯');
- expect(docElement.lastChild.lastChild.data).toEqual('⋯');
- expect(doc.toQuery()).toEqual('');
-
- // Only removable
- expect(docElement.lastChild.children.length).toEqual(0);
- });
-
- it('should be removable, when no root', function () {
- var docGroup = KorAP.DocGroup.create();
- docGroup.operation('or');
- expect(docGroup.operation()).toEqual('or');
-
- docGroup.append({
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:eq',
- "value": '2014-12-05',
- "type": 'type:date'
- });
-
- // Add unspecified object
- docGroup.append();
-
- expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
- expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
-
- var unspec = docGroup.element().children[1];
- expect(unspec.getAttribute('class')).toEqual('doc unspecified');
-
- // Removable
- expect(unspec.lastChild.children.length).toEqual(1);
- expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
- });
-
- it('should be replaceable by a doc', function () {
- var doc = KorAP.UnspecifiedDoc.create();
- expect(doc.ldType()).toEqual("non");
- // No parent, therefor not updateable
- expect(doc.key("baum")).toBeNull();
-
- var docGroup = KorAP.DocGroup.create();
- docGroup.operation('or');
- expect(docGroup.operation()).toEqual('or');
-
- docGroup.append({
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:eq',
- "value": '2014-12-05',
- "type": 'type:date'
- });
-
- expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05");
- docGroup.append();
-
- expect(docGroup.getOperand(0).ldType()).toEqual("doc");
- expect(docGroup.getOperand(1).ldType()).toEqual("non");
-
- var op = docGroup.getOperand(1).element().lastChild;
- expect(op.getAttribute('class')).toEqual('operators');
- expect(op.children[0].getAttribute('class')).toEqual('delete');
- expect(op.children.length).toEqual(1);
-
- // Replace unspecified doc
- expect(docGroup.getOperand(1).key("name")).not.toBeNull();
- expect(docGroup.getOperand(1).ldType()).toEqual("doc");
- expect(docGroup.getOperand(1).key()).toEqual("name");
- expect(docGroup.getOperand(1).value()).toEqual("");
-
- op = docGroup.getOperand(1).element().lastChild;
- expect(op.getAttribute('class')).toEqual('operators');
- expect(op.children[0].getAttribute('class')).toEqual('and');
- expect(op.children[1].getAttribute('class')).toEqual('or');
- expect(op.children[2].getAttribute('class')).toEqual('delete');
- expect(op.children.length).toEqual(3);
-
- docGroup.getOperand(1).value("Pachelbel");
- expect(docGroup.getOperand(1).value()).toEqual("Pachelbel");
- expect(docGroup.getOperand(1).type()).toEqual("string");
- expect(docGroup.getOperand(1).matchop()).toEqual("eq");
-
- // Specified!
- expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"');
- });
-
- it('should be replaceable on root', function () {
- var vc = KorAP.VirtualCollection.render();
- expect(vc.toQuery()).toEqual("");
-
- expect(vc.root().ldType()).toEqual("non");
-
- // No operators on root
- op = vc.root().element().lastChild;
- expect(op.lastChild.textContent).toEqual('⋯');
-
- // Replace
- expect(vc.root().key("baum")).not.toBeNull();
- expect(vc.root().ldType()).toEqual("doc");
-
- op = vc.root().element().lastChild;
- expect(op.getAttribute('class')).toEqual('operators');
- expect(op.children[0].getAttribute('class')).toEqual('and');
- expect(op.children[1].getAttribute('class')).toEqual('or');
- expect(op.children[2].getAttribute('class')).toEqual('delete');
- expect(op.children.length).toEqual(3);
- });
-});
-
-describe('KorAP.Doc element', function () {
- it('should be initializable', function () {
- var docElement = KorAP.Doc.create(undefined, {
- "@type" : "koral:doc",
- "key":"Titel",
- "value":"Baum",
- "match":"match:eq"
- });
- expect(docElement.key()).toEqual('Titel');
- expect(docElement.matchop()).toEqual('eq');
- expect(docElement.value()).toEqual('Baum');
-
- var docE = docElement.element();
- expect(docE.children[0].firstChild.data).toEqual('Titel');
- expect(docE.children[1].firstChild.data).toEqual('eq');
- expect(docE.children[1].getAttribute('data-type')).toEqual('string');
- expect(docE.children[2].firstChild.data).toEqual('Baum');
- expect(docE.children[2].getAttribute('data-type')).toEqual('string');
-
- expect(docElement.toJson()).toEqual(jasmine.objectContaining({
- "@type" : "koral:doc",
- "key":"Titel",
- "value":"Baum",
- "match":"match:eq"
- }));
- });
-});
-
-describe('KorAP.DocGroup element', function () {
- it('should be initializable', function () {
-
- var docGroup = KorAP.DocGroup.create(undefined, {
- "@type" : "koral:docGroup",
- "operation" : "operation:and",
- "operands" : [
- {
- "@type": 'koral:doc',
- "key" : 'author',
- "match": 'match:eq',
- "value": 'Max Birkendale',
- "type": 'type:string'
- },
- {
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:eq',
- "value": '2014-12-05',
- "type": 'type:date'
- }
- ]
- });
-
- expect(docGroup.operation()).toEqual('and');
- var e = docGroup.element();
- expect(e.getAttribute('class')).toEqual('docGroup');
- expect(e.getAttribute('data-operation')).toEqual('and');
-
- var first = e.children[0];
- expect(first.getAttribute('class')).toEqual('doc');
- expect(first.children[0].getAttribute('class')).toEqual('key');
- expect(first.children[1].getAttribute('class')).toEqual('match');
- expect(first.children[2].getAttribute('class')).toEqual('value');
- expect(first.children[2].getAttribute('data-type')).toEqual('string');
- expect(first.children[0].firstChild.data).toEqual('author');
- expect(first.children[1].firstChild.data).toEqual('eq');
- expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
-
- var second = e.children[1];
- expect(second.getAttribute('class')).toEqual('doc');
- expect(second.children[0].getAttribute('class')).toEqual('key');
- expect(second.children[1].getAttribute('class')).toEqual('match');
- expect(second.children[2].getAttribute('class')).toEqual('value');
- expect(second.children[2].getAttribute('data-type')).toEqual('date');
- expect(second.children[0].firstChild.data).toEqual('pubDate');
- expect(second.children[1].firstChild.data).toEqual('eq');
- expect(second.children[2].firstChild.data).toEqual('2014-12-05');
-
- });
-
- it('should be deserializable with nested groups', function () {
- var docGroup = KorAP.DocGroup.create(undefined, {
- "@type" : "koral:docGroup",
- "operation" : "operation:or",
- "operands" : [
- {
- "@type": 'koral:doc',
- "key" : 'author',
- "match": 'match:eq',
- "value": 'Max Birkendale',
- "type": 'type:string'
- },
- {
- "@type" : "koral:docGroup",
- "operation" : "operation:and",
- "operands" : [
- {
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:geq',
- "value": '2014-05-12',
- "type": 'type:date'
- },
- {
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:leq',
- "value": '2014-12-05',
- "type": 'type:date'
- }
- ]
- }
- ]
- });
-
- expect(docGroup.operation()).toEqual('or');
- var e = docGroup.element();
- expect(e.getAttribute('class')).toEqual('docGroup');
- expect(e.getAttribute('data-operation')).toEqual('or');
-
- expect(e.children[0].getAttribute('class')).toEqual('doc');
- var docop = e.children[0].lastChild;
- expect(docop.getAttribute('class')).toEqual('operators');
- expect(docop.children[0].getAttribute('class')).toEqual('and');
- expect(docop.children[1].getAttribute('class')).toEqual('or');
- expect(docop.children[2].getAttribute('class')).toEqual('delete');
-
- expect(e.children[1].getAttribute('class')).toEqual('docGroup');
- expect(e.children[1].getAttribute('data-operation')).toEqual('and');
-
- // This and-operation can be "or"ed or "delete"d
- var secop = e.children[1].children[2];
- expect(secop.getAttribute('class')).toEqual('operators');
- expect(secop.children[0].getAttribute('class')).toEqual('or');
- expect(secop.children[1].getAttribute('class')).toEqual('delete');
-
- // This or-operation can be "and"ed or "delete"d
- expect(e.children[2].getAttribute('class')).toEqual('operators');
- expect(e.lastChild.getAttribute('class')).toEqual('operators');
- expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
- expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
-
- });
-});
-
-describe('KorAP.VirtualCollection', function () {
-
- var simpleGroupFactory = buildFactory(KorAP.DocGroup, {
- "@type" : "koral:docGroup",
- "operation" : "operation:and",
- "operands" : [
+ var demoFactory = buildFactory(vcClass, {
+ "@type":"koral:docGroup",
+ "operation":"operation:or",
+ "operands":[
{
- "@type": 'koral:doc',
- "key" : 'author',
- "match": 'match:eq',
- "value": 'Max Birkendale',
- "type": 'type:string'
+ "@type":"koral:docGroup",
+ "operation":"operation:and",
+ "operands":[
+ {
+ "@type":"koral:doc",
+ "key":"Titel",
+ "value":"Baum",
+ "match":"match:eq"
+ },
+ {
+ "@type":"koral:doc",
+ "key":"Veröffentlichungsort",
+ "value":"hihi",
+ "match":"match:eq"
+ },
+ {
+ "@type":"koral:docGroup",
+ "operation":"operation:or",
+ "operands":[
+ {
+ "@type":"koral:doc",
+ "key":"Titel",
+ "value":"Baum",
+ "match":"match:eq"
+ },
+ {
+ "@type":"koral:doc",
+ "key":"Veröffentlichungsort",
+ "value":"hihi",
+ "match":"match:eq"
+ }
+ ]
+ }
+ ]
},
{
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:eq',
- "value": '2014-12-05',
- "type": 'type:date'
+ "@type":"koral:doc",
+ "key":"Untertitel",
+ "value":"huhu",
+ "match":"match:eq"
}
]
});
- var nestedGroupFactory = buildFactory(KorAP.VirtualCollection, {
- "@type" : "koral:docGroup",
- "operation" : "operation:or",
- "operands" : [
+ describe('KorAP.Doc', function () {
+ // Create example factories
+ var stringFactory = buildFactory(docClass, {
+ "key" : "author",
+ "value" : "Max Birkendale",
+ "@type" : "koral:doc"
+ });
+
+ // Create example factories
+ var dateFactory = buildFactory(docClass, {
+ "key" : "pubDate",
+ "type" : "type:date",
+ "match" : "match:eq",
+ "value" : "2014-11-05",
+ "@type" : "koral:doc"
+ });
+
+ // Create example factories
+ var regexFactory = buildFactory(docClass, {
+ "key" : "title",
+ "type" : "type:regex",
+ "value" : "[^b]ee.+?",
+ "@type" : "koral:doc"
+ });
+
+ it('should be initializable', function () {
+ var doc = docClass.create();
+ expect(doc.matchop()).toEqual('eq');
+ expect(doc.key()).toBeUndefined();
+ expect(doc.value()).toBeUndefined();
+ expect(doc.type()).toEqual("string");
+ });
+
+ it('should be definable', function () {
+
+ // Empty doc
+ var doc = docClass.create();
+
+ // Set values
+ doc.key("title");
+ doc.value("Der alte Mann");
+ expect(doc.matchop()).toEqual('eq');
+ expect(doc.key()).toEqual("title");
+ expect(doc.type()).toEqual("string");
+ expect(doc.value()).toEqual("Der alte Mann");
+ });
+
+
+ it('should deserialize JSON-LD string', function () {
+ var doc;
+
+ // String default
+ doc = stringFactory.create();
+ expect(doc.matchop()).toEqual('eq');
+ expect(doc.key()).toEqual("author");
+ expect(doc.type()).toEqual("string");
+ expect(doc.value()).toEqual("Max Birkendale");
+
+ // No valid string
+ doc = stringFactory.create({
+ value : undefined
+ });
+ expect(doc).toBeUndefined();
+
+ // No valid string
+ doc = stringFactory.create({
+ value : { "foo" : "bar" }
+ });
+ expect(doc).toBeUndefined();
+
+ // Change match type
+ doc = stringFactory.create({
+ "match" : "match:ne"
+ });
+
+ expect(doc.matchop()).toEqual('ne');
+ expect(doc.key()).toEqual("author");
+ expect(doc.type()).toEqual("string");
+ expect(doc.value()).toEqual("Max Birkendale");
+
+ // Invalid match type
+ doc = stringFactory.create({
+ "match" : { "foo" : "bar" }
+ });
+ expect(doc).toBeUndefined();
+ });
+
+ it('should deserialize JSON-LD regex', function () {
+ var doc = regexFactory.create();
+ expect(doc.key()).toEqual("title");
+ expect(doc.type()).toEqual("regex");
+ expect(doc.value()).toEqual("[^b]ee.+?");
+ expect(doc.matchop()).toEqual('eq');
+
+ // change matcher
+ doc = regexFactory.create({
+ match : "match:ne"
+ });
+ expect(doc.matchop()).toEqual('ne');
+
+ // Invalid matcher
+ doc = regexFactory.create({
+ match : "match:chook"
+ });
+ expect(doc).toBeUndefined();
+
+ // Invalid regex
+ doc = regexFactory.create({
+ value : "[^b"
+ });
+ expect(doc).toBeUndefined();
+ });
+
+ it('should deserialize JSON-LD date', function () {
+
+ // Normal date
+ doc = dateFactory.create({});
+
+ expect(doc.matchop()).toEqual('eq');
+ expect(doc.key()).toEqual("pubDate");
+ expect(doc.type()).toEqual("date");
+ expect(doc.value()).toEqual("2014-11-05");
+
+ // Short date 1
+ doc = dateFactory.create({
+ "value" : "2014-11"
+ });
+
+ expect(doc.matchop()).toEqual('eq');
+ expect(doc.key()).toEqual("pubDate");
+ expect(doc.type()).toEqual("date");
+ expect(doc.value()).toEqual("2014-11");
+
+ // Short date 2
+ doc = dateFactory.create({
+ "value" : "2014"
+ });
+
+ expect(doc.matchop()).toEqual('eq');
+ expect(doc.key()).toEqual("pubDate");
+ expect(doc.type()).toEqual("date");
+ expect(doc.value()).toEqual("2014");
+
+ // Invalid date!
+ doc = dateFactory.create({
+ "value" : "2014-11-050"
+ });
+ expect(doc).toBeUndefined();
+
+ // Invalid matcher!
+ doc = dateFactory.create({
+ "match" : "match:ne",
+ });
+ expect(doc).toBeUndefined();
+ });
+
+ it('should be serializale to JSON', function () {
+
+ // Empty doc
+ var doc = docClass.create();
+ expect(doc.toJson()).toEqual(jasmine.any(Object));
+
+ // Serialize string
+ doc = stringFactory.create();
+ expect(doc.toJson()).toEqual(jasmine.objectContaining({
+ "@type" : "koral:doc",
+ "type" : "type:string",
+ "key" : "author",
+ "value" : "Max Birkendale",
+ "match" : "match:eq"
+ }));
+
+ // Serialize regex
+ doc = regexFactory.create();
+ expect(doc.toJson()).toEqual(jasmine.objectContaining({
+ "@type" : "koral:doc",
+ "type" : "type:regex",
+ "value" : "[^b]ee.+?",
+ "match" : "match:eq",
+ "key" : 'title'
+ }));
+
+ doc = regexFactory.create({
+ match: "match:ne"
+ });
+ expect(doc.toJson()).toEqual(jasmine.objectContaining({
+ "@type" : "koral:doc",
+ "type" : "type:regex",
+ "value" : "[^b]ee.+?",
+ "match" : "match:ne",
+ "key" : 'title'
+ }));
+
+ doc = dateFactory.create();
+ expect(doc.toJson()).toEqual(jasmine.objectContaining({
+ "@type" : "koral:doc",
+ "type" : "type:date",
+ "value" : "2014-11-05",
+ "match" : "match:eq",
+ "key" : 'pubDate'
+ }));
+
+ doc = dateFactory.create({
+ value : "2014"
+ });
+ expect(doc.toJson()).toEqual(jasmine.objectContaining({
+ "@type" : "koral:doc",
+ "type" : "type:date",
+ "value" : "2014",
+ "match" : "match:eq",
+ "key" : 'pubDate'
+ }));
+ });
+
+
+ it('should be serializale to String', function () {
+ // Empty doc
+ var doc = docClass.create();
+ expect(doc.toQuery()).toEqual("");
+
+ // Serialize string
+ doc = stringFactory.create();
+ expect(doc.toQuery()).toEqual('author = "Max Birkendale"');
+
+ // Serialize string with quotes
+ doc = stringFactory.create({ "value" : 'Max "Der Coole" Birkendate'});
+ expect(doc.toQuery()).toEqual('author = "Max \\"Der Coole\\" Birkendate"');
+
+ // Serialize regex
+ doc = regexFactory.create();
+ expect(doc.toQuery()).toEqual('title = /[^b]ee.+?/');
+
+ doc = regexFactory.create({
+ match: "match:ne"
+ });
+ expect(doc.toQuery()).toEqual('title != /[^b]ee.+?/');
+
+ doc = dateFactory.create();
+ expect(doc.toQuery()).toEqual('pubDate in 2014-11-05');
+
+ doc = dateFactory.create({
+ value : "2014"
+ });
+ expect(doc.toQuery()).toEqual('pubDate in 2014');
+ });
+ });
+
+
+ describe('KorAP.DocGroup', function () {
+ // Create example factories
+ var docFactory = buildFactory(
+ docClass,
{
- "@type": 'koral:doc',
- "key" : 'author',
- "match": 'match:eq',
- "value": 'Max Birkendale',
- "type": 'type:string'
- },
- {
+ "@type" : "koral:doc",
+ "match":"match:eq",
+ "key" : "author",
+ "value" : "Max Birkendale"
+ }
+ );
+
+ var docGroupFactory = buildFactory(
+ docGroupClass, {
+ "@type" : "koral:docGroup",
+ "operation" : "operation:and",
+ "operands" : [
+ docFactory.create().toJson(),
+ docFactory.create({
+ "key" : "pubDate",
+ "type" : "type:date",
+ "value" : "2014-12-05"
+ }).toJson()
+ ]
+ });
+
+ it('should be initializable', function () {
+ // Create empty group
+ var docGroup = docGroupClass.create();
+ expect(docGroup.operation()).toEqual('and');
+
+ // Create empty group
+ docGroup = docGroupClass.create();
+ docGroup.operation('or');
+ expect(docGroup.operation()).toEqual('or');
+ });
+
+ it('should be definable', function () {
+
+ // Empty group
+ var docGroup = docGroupClass.create();
+ expect(docGroup.operation()).toEqual('and');
+
+ // Set values
+ docGroup.operation("or");
+ expect(docGroup.operation()).toEqual('or');
+
+ // Set invalid values
+ docGroup.operation("hui");
+ expect(docGroup.operation()).toEqual('or');
+ });
+
+ it('should be deserializable', function () {
+ var docGroup = docGroupFactory.create();
+ expect(docGroup.operation()).toEqual("and");
+ expect(docGroup.operands().length).toEqual(2);
+
+ var op1 = docGroup.getOperand(0);
+ expect(op1.type()).toEqual("string");
+ expect(op1.key()).toEqual("author");
+ expect(op1.value()).toEqual("Max Birkendale");
+ expect(op1.matchop()).toEqual("eq");
+
+ var op2 = docGroup.getOperand(1);
+ expect(op2.type()).toEqual("date");
+ expect(op2.key()).toEqual("pubDate");
+ expect(op2.value()).toEqual("2014-12-05");
+ expect(op2.matchop()).toEqual("eq");
+
+ // Append empty group
+ var newGroup = docGroup.append(docGroupClass.create());
+ newGroup.operation('or');
+ newGroup.append(docFactory.create());
+ newGroup.append(docFactory.create({
+ "type" : "type:regex",
+ "key" : "title",
+ "value" : "^e.+?$",
+ "match" : "match:ne"
+ }));
+
+ expect(docGroup.operation()).toEqual("and");
+ expect(docGroup.operands().length).toEqual(3);
+
+ var op1 = docGroup.getOperand(0);
+ expect(op1.ldType()).toEqual("doc");
+ expect(op1.type()).toEqual("string");
+ expect(op1.key()).toEqual("author");
+ expect(op1.value()).toEqual("Max Birkendale");
+ expect(op1.matchop()).toEqual("eq");
+
+ var op2 = docGroup.getOperand(1);
+ expect(op2.ldType()).toEqual("doc");
+ expect(op2.type()).toEqual("date");
+ expect(op2.key()).toEqual("pubDate");
+ expect(op2.value()).toEqual("2014-12-05");
+ expect(op2.matchop()).toEqual("eq");
+
+ var op3 = docGroup.getOperand(2);
+ expect(op3.ldType()).toEqual("docGroup");
+ expect(op3.operation()).toEqual("or");
+
+ var op4 = op3.getOperand(0);
+ expect(op4.ldType()).toEqual("doc");
+ expect(op4.type()).toEqual("string");
+ expect(op4.key()).toEqual("author");
+ expect(op4.value()).toEqual("Max Birkendale");
+ expect(op4.matchop()).toEqual("eq");
+
+ var op5 = op3.getOperand(1);
+ expect(op5.ldType()).toEqual("doc");
+ expect(op5.type()).toEqual("regex");
+ expect(op5.key()).toEqual("title");
+ expect(op5.value()).toEqual("^e.+?$");
+ expect(op5.matchop()).toEqual("ne");
+ });
+
+ it('should be serializable to JSON', function () {
+ var docGroup = docGroupFactory.create();
+
+ expect(docGroup.toJson()).toEqual(jasmine.objectContaining({
"@type" : "koral:docGroup",
"operation" : "operation:and",
"operands" : [
{
"@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:geq',
- "value": '2014-05-12',
- "type": 'type:date'
+ "key" : 'author',
+ "match": 'match:eq',
+ "value": 'Max Birkendale',
+ "type": 'type:string'
},
{
"@type": 'koral:doc',
"key": 'pubDate',
- "match": 'match:leq',
- "value": '2014-12-05',
- "type": 'type:date'
- }
- ]
- }
- ]
- });
-
- var flatGroupFactory = buildFactory(KorAP.VirtualCollection, {
- "@type" : "koral:docGroup",
- "operation" : "operation:and",
- "operands" : [
- {
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:geq',
- "value": '2014-05-12',
- "type": 'type:date'
- },
- {
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:leq',
- "value": '2014-12-05',
- "type": 'type:date'
- },
- {
- "@type": 'koral:doc',
- "key": 'foo',
- "match": 'match:eq',
- "value": 'bar',
- "type": 'type:string'
- }
- ]
- });
-
- it('should be initializable', function () {
- var vc = KorAP.VirtualCollection.render();
- expect(vc.element().getAttribute('class')).toEqual('vc');
- expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
-
- // Not removable
- expect(vc.root().element().lastChild.children.length).toEqual(0);
- });
-
- it('should be based on a doc', function () {
- var vc = KorAP.VirtualCollection.render({
- "@type" : "koral:doc",
- "key":"Titel",
- "value":"Baum",
- "match":"match:eq"
- });
-
- expect(vc.element().getAttribute('class')).toEqual('vc');
- expect(vc.root().element().getAttribute('class')).toEqual('doc');
- expect(vc.root().key()).toEqual('Titel');
- expect(vc.root().value()).toEqual('Baum');
- expect(vc.root().matchop()).toEqual('eq');
-
- var docE = vc.root().element();
- expect(docE.children[0].firstChild.data).toEqual('Titel');
- expect(docE.children[1].firstChild.data).toEqual('eq');
- expect(docE.children[1].getAttribute('data-type')).toEqual('string');
- expect(docE.children[2].firstChild.data).toEqual('Baum');
- expect(docE.children[2].getAttribute('data-type')).toEqual('string');
- });
-
- it('should be based on a docGroup', function () {
- var vc = KorAP.VirtualCollection.render(simpleGroupFactory.create().toJson());
-
- expect(vc.element().getAttribute('class')).toEqual('vc');
- expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
- expect(vc.root().operation()).toEqual('and');
-
- var docGroup = vc.root();
-
- var first = docGroup.getOperand(0);
- expect(first.key()).toEqual('author');
- expect(first.value()).toEqual('Max Birkendale');
- expect(first.matchop()).toEqual('eq');
-
- var second = docGroup.getOperand(1);
- expect(second.key()).toEqual('pubDate');
- expect(second.value()).toEqual('2014-12-05');
- expect(second.matchop()).toEqual('eq');
- });
-
-
- it('should be based on a nested docGroup', function () {
- var vc = nestedGroupFactory.create();
-
- expect(vc.element().getAttribute('class')).toEqual('vc');
- expect(vc.element().firstChild.getAttribute('class')).toEqual('docGroup');
- expect(vc.element().firstChild.children[0].getAttribute('class')).toEqual('doc');
- var dg = vc.element().firstChild.children[1];
- expect(dg.getAttribute('class')).toEqual('docGroup');
- expect(dg.children[0].getAttribute('class')).toEqual('doc');
- expect(dg.children[1].getAttribute('class')).toEqual('doc');
- expect(dg.children[2].getAttribute('class')).toEqual('operators');
- expect(vc.element().firstChild.children[2].getAttribute('class')).toEqual('operators');
- });
-
- it('should be modifiable by deletion in flat docGroups', function () {
- var vc = flatGroupFactory.create();
- var docGroup = vc.root();
-
- expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
-
- var doc = docGroup.getOperand(1);
- expect(doc.key()).toEqual("pubDate");
- expect(doc.value()).toEqual("2014-12-05");
-
- // Remove operand 1
- expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
- expect(doc._element).toEqual(undefined);
-
- doc = docGroup.getOperand(1);
- expect(doc.key()).toEqual("foo");
-
- // Remove operand 1
- expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
- expect(doc._element).toEqual(undefined);
-
- // Only one operand left ...
- expect(docGroup.getOperand(1)).toBeUndefined();
- // ... but there shouldn't be a group anymore at all!
- expect(docGroup.getOperand(0)).toBeUndefined();
-
- var obj = vc.root();
- expect(obj.ldType()).toEqual("doc");
- expect(obj.key()).toEqual("pubDate");
- expect(obj.value()).toEqual("2014-05-12");
-
- expect(obj.element().getAttribute('class')).toEqual('doc');
- });
-
-
- it('should be modifiable by deletion in nested docGroups (root case)', function () {
- var vc = nestedGroupFactory.create();
-
- expect(vc.toQuery()).toEqual(
- 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
- );
-
- var docGroup = vc.root();
- expect(docGroup.ldType()).toEqual("docGroup");
- expect(docGroup.operation()).toEqual("or");
-
- var doc = docGroup.getOperand(0);
- expect(doc.key()).toEqual("author");
- expect(doc.value()).toEqual("Max Birkendale");
-
- docGroup = docGroup.getOperand(1);
- expect(docGroup.operation()).toEqual("and");
-
- doc = docGroup.getOperand(0);
- expect(doc.key()).toEqual("pubDate");
- expect(doc.matchop()).toEqual("geq");
- expect(doc.value()).toEqual("2014-05-12");
- expect(doc.type()).toEqual("date");
-
- doc = docGroup.getOperand(1);
- expect(doc.key()).toEqual("pubDate");
- expect(doc.matchop()).toEqual("leq");
- expect(doc.value()).toEqual("2014-12-05");
- expect(doc.type()).toEqual("date");
-
- // Remove first operand so everything becomes root
- expect(
- vc.root().delOperand(
- vc.root().getOperand(0)
- ).update().ldType()
- ).toEqual("docGroup");
-
- expect(vc.root().ldType()).toEqual("docGroup");
- expect(vc.root().operation()).toEqual("and");
- expect(vc.root().getOperand(0).ldType()).toEqual("doc");
-
- expect(vc.toQuery()).toEqual(
- 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
- );
- });
-
- it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
- var vc = nestedGroupFactory.create();
-
- // Get nested group
- var firstGroup = vc.root().getOperand(1);
- firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
-
- // Structur is now:
- // or(doc, and(doc, doc, or(doc, doc)))
-
- // Get nested or in and
- var orGroup = vc.root().getOperand(1).getOperand(2);
- expect(orGroup.ldType()).toEqual("docGroup");
- expect(orGroup.operation()).toEqual("or");
-
- // Remove
- // Structur is now:
- // or(doc, and(doc, doc, doc)))
- expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
- expect(vc.root().getOperand(1).operands().length).toEqual(3);
- });
-
- it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
- var vc = nestedGroupFactory.create();
-
- // Get nested group
- var firstGroup = vc.root().getOperand(1);
- firstGroup.append(simpleGroupFactory.create({
- "operation" : "operation:or"
- }));
- var oldAuthor = firstGroup.getOperand(2).getOperand(0);
- oldAuthor.key("title");
- oldAuthor.value("Der Birnbaum");
-
- // Structur is now:
- // or(doc, and(doc, doc, or(doc, doc)))
- expect(vc.toQuery()).toEqual(
- 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05 & (title = "Der Birnbaum" | pubDate in 2014-12-05))'
- );
-
- var andGroup = vc.root().getOperand(1);
-
- // Get leading docs in and
- var doc1 = andGroup.getOperand(0);
- expect(doc1.ldType()).toEqual("doc");
- expect(doc1.value()).toEqual("2014-05-12");
- var doc2 = andGroup.getOperand(1);
- expect(doc2.ldType()).toEqual("doc");
- expect(doc2.value()).toEqual("2014-12-05");
-
- // Remove 2
- expect(andGroup.delOperand(doc2).update().operation()).toEqual("and");
- // Structur is now:
- // or(doc, and(doc, or(doc, doc)))
-
- expect(vc.toQuery()).toEqual(
- 'author = "Max Birkendale"' +
- ' | (pubDate since 2014-05-12 & ' +
- '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
- );
-
-
- // Remove 1
- expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
- // Structur is now:
- // or(doc, doc, doc)
-
- expect(vc.toQuery()).toEqual(
- 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
- );
- });
-
- it('should be reducible to unspecification', function () {
- var vc = demoFactory.create();
-
- expect(vc.toQuery()).toEqual(vc.root().toQuery());
-
- expect(vc.toQuery()).toEqual(
- '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
- '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
- '| Untertitel = "huhu"');
-
- expect(vc.root().element().lastChild.children[0].firstChild.nodeValue).toEqual('and');
- expect(vc.root().element().lastChild.children[1].firstChild.nodeValue).toEqual('×');
- expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
- expect(vc.toQuery()).toEqual('Untertitel = "huhu"');
-
- var lc = vc.root().element().lastChild;
- expect(lc.children[0].firstChild.nodeValue).toEqual('and');
- expect(lc.children[1].firstChild.nodeValue).toEqual('or');
- expect(lc.children[2].firstChild.nodeValue).toEqual('×');
-
- // Clean everything
- vc.clean();
- expect(vc.toQuery()).toEqual('');
- });
-
- it('should flatten on import', function () {
- var vc = KorAP.VirtualCollection.create().render({
- "@type":"koral:docGroup",
- "operation":"operation:or",
- "operands":[
- {
- "@type":"koral:docGroup",
- "operation":"operation:or",
- "operands":[
- {
- "@type":"koral:doc",
- "key":"Titel",
- "value":"Baum",
- "match":"match:eq"
- },
- {
- "@type":"koral:doc",
- "key":"Veröffentlichungsort",
- "value":"hihi",
- "match":"match:eq"
- },
- {
- "@type":"koral:docGroup",
- "operation":"operation:or",
- "operands":[
- {
- "@type":"koral:doc",
- "key":"Titel",
- "value":"Baum",
- "match":"match:eq"
- },
- {
- "@type":"koral:doc",
- "key":"Veröffentlichungsort",
- "value":"hihi",
- "match":"match:eq"
- }
- ]
- }
- ]
- },
- {
- "@type":"koral:doc",
- "key":"Untertitel",
- "value":"huhu",
- "match":"match:eq"
- }
- ]
- });
-
- expect(vc.toQuery()).toEqual(
- 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel = "huhu"'
- );
-
-
- });
-});
-
-describe('KorAP.Operators', function () {
- it('should be initializable', function () {
- var op = KorAP.Operators.create(true, false, false);
- expect(op.and()).toBeTruthy();
- expect(op.or()).not.toBeTruthy();
- expect(op.del()).not.toBeTruthy();
-
- op.and(false);
- expect(op.and()).not.toBeTruthy();
- expect(op.or()).not.toBeTruthy();
- expect(op.del()).not.toBeTruthy();
-
- op.or(true);
- op.del(true);
- expect(op.and()).not.toBeTruthy();
- expect(op.or()).toBeTruthy();
- expect(op.del()).toBeTruthy();
-
- var e = op.element();
- expect(e.getAttribute('class')).toEqual('operators');
- expect(e.children[0].getAttribute('class')).toEqual('or');
- expect(e.children[0].firstChild.data).toEqual('or');
- expect(e.children[1].getAttribute('class')).toEqual('delete');
- expect(e.children[1].firstChild.data).toEqual('×');
-
- op.and(true);
- op.del(false);
- op.update();
-
- e = op.element();
- expect(e.getAttribute('class')).toEqual('operators');
- expect(e.children[0].getAttribute('class')).toEqual('and');
- expect(e.children[0].firstChild.data).toEqual('and');
- expect(e.children[1].getAttribute('class')).toEqual('or');
- expect(e.children[1].firstChild.data).toEqual('or');
- });
-});
-
-describe('KorAP._delete (event)', function () {
- var complexVCFactory = buildFactory(KorAP.VirtualCollection,{
- "@type": 'koral:docGroup',
- 'operation' : 'operation:and',
- 'operands' : [
- {
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:eq',
- "value": '2014-12-05',
- "type": 'type:date'
- },
- {
- "@type" : 'koral:docGroup',
- 'operation' : 'operation:or',
- 'operands' : [
- {
- '@type' : 'koral:doc',
- 'key' : 'title',
- 'value' : 'Hello World!'
- },
- {
- '@type' : 'koral:doc',
- 'key' : 'foo',
- 'value' : 'bar'
- }
- ]
- }
- ]
- });
-
- it('should clean on root docs', function () {
- var vc = KorAP.VirtualCollection.render({
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:eq',
- "value": '2014-12-05',
- "type": 'type:date'
- });
- expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
- expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators');
-
- // Clean with delete from root
- expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
- _delOn(vc.root());
- expect(vc.root().toQuery()).toEqual('');
- expect(vc.root().element().lastChild.lastChild.data).toEqual('⋯');
- });
-
- it ('should remove on nested docs', function () {
- var vc = KorAP.VirtualCollection.render(
- {
- "@type": 'koral:docGroup',
- 'operation' : 'operation:and',
- 'operands' : [
- {
- "@type": 'koral:doc',
- "key": 'pubDate',
"match": 'match:eq',
"value": '2014-12-05',
"type": 'type:date'
- },
- {
- "@type" : 'koral:doc',
- 'key' : 'foo',
- 'value' : 'bar'
}
]
- }
- );
+ }));
+ });
- // Delete with direct element access
- expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
- _delOn(vc.root().getOperand(0));
+ it('should be serializable to String', function () {
+ var docGroup = docGroupFactory.create();
+ expect(docGroup.toQuery()).toEqual(
+ 'author = "Max Birkendale" & pubDate in 2014-12-05'
+ );
- expect(vc.toQuery()).toEqual('foo = "bar"');
- expect(vc.root().ldType()).toEqual('doc');
- });
-
- it ('should clean on doc groups', function () {
- var vc = KorAP.VirtualCollection.render(
- {
- "@type": 'koral:docGroup',
- 'operation' : 'operation:and',
- 'operands' : [
+ docGroup = docGroupFactory.create({
+ "@type" : "koral:docGroup",
+ "operation" : "operation:or",
+ "operands" : [
{
"@type": 'koral:doc',
- "key": 'pubDate',
+ "key" : 'author',
"match": 'match:eq',
- "value": '2014-12-05',
- "type": 'type:date'
+ "value": 'Max Birkendale',
+ "type": 'type:string'
},
{
- "@type" : 'koral:doc',
- 'key' : 'foo',
- 'value' : 'bar'
- }
- ]
- }
- );
-
- // Cleanwith direct element access
- expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
- _delOn(vc.root());
- expect(vc.toQuery()).toEqual('');
- expect(vc.root().ldType()).toEqual('non');
- });
-
- it ('should remove on nested doc groups (case of ungrouping 1)', function () {
- var vc = complexVCFactory.create();
-
- // Delete with direct element access
- expect(vc.toQuery()).toEqual(
- 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
- );
-
- // Remove hello world:
- _delOn(vc.root().getOperand(1).getOperand(0));
- expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
- expect(vc.root().ldType()).toEqual('docGroup');
- });
-
- it ('should remove on nested doc groups (case of ungrouping 2)', function () {
- var vc = complexVCFactory.create();
-
- // Delete with direct element access
- expect(vc.toQuery()).toEqual(
- 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
- );
-
- // Remove bar
- _delOn(vc.root().getOperand(1).getOperand(1));
- expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
- expect(vc.root().ldType()).toEqual('docGroup');
- expect(vc.root().operation()).toEqual('and');
- });
-
- it ('should remove on nested doc groups (case of root changing)', function () {
- var vc = complexVCFactory.create();
-
- // Delete with direct element access
- expect(vc.toQuery()).toEqual(
- 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
- );
-
- // Remove bar
- _delOn(vc.root().getOperand(0));
- expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
- expect(vc.root().ldType()).toEqual('docGroup');
- expect(vc.root().operation()).toEqual('or');
- });
-
- it ('should remove on nested doc groups (list flattening)', function () {
- var vc = KorAP.VirtualCollection.render(
- {
- "@type": 'koral:docGroup',
- 'operation' : 'operation:or',
- 'operands' : [
- {
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:eq',
- "value": '2014-12-05',
- "type": 'type:date'
- },
- {
- "@type" : 'koral:doc',
- 'key' : 'foo',
- 'value' : 'bar'
- },
- {
- "@type": 'koral:docGroup',
- 'operation' : 'operation:and',
- 'operands' : [
+ "@type" : "koral:docGroup",
+ "operation" : "operation:and",
+ "operands" : [
{
"@type": 'koral:doc',
"key": 'pubDate',
- "match": 'match:eq',
+ "match": 'match:geq',
+ "value": '2014-05-12',
+ "type": 'type:date'
+ },
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:leq',
"value": '2014-12-05',
"type": 'type:date'
},
{
- "@type" : 'koral:docGroup',
- 'operation' : 'operation:or',
- 'operands' : [
+ "@type": 'koral:doc',
+ "key": 'foo',
+ "match": 'match:ne',
+ "value": '[a]?bar',
+ "type": 'type:regex'
+ }
+ ]
+ }
+ ]
+ });
+ expect(docGroup.toQuery()).toEqual(
+ 'author = "Max Birkendale" | ' +
+ '(pubDate since 2014-05-12 & ' +
+ 'pubDate until 2014-12-05 & foo != /[a]?bar/)'
+ );
+ });
+ });
+
+ describe('KorAP.UnspecifiedDoc', function () {
+ it('should be initializable', function () {
+ var doc = unspecifiedClass.create();
+ var docElement = doc.element();
+ expect(docElement.getAttribute('class')).toEqual('doc unspecified');
+ expect(docElement.firstChild.firstChild.data).toEqual('⋯');
+ expect(docElement.lastChild.lastChild.data).toEqual('⋯');
+ expect(doc.toQuery()).toEqual('');
+
+ // Only removable
+ expect(docElement.lastChild.children.length).toEqual(0);
+ });
+
+ it('should be removable, when no root', function () {
+ var docGroup = docGroupClass.create();
+ docGroup.operation('or');
+ expect(docGroup.operation()).toEqual('or');
+
+ docGroup.append({
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:eq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ });
+
+ // Add unspecified object
+ docGroup.append();
+
+ expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
+ expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
+
+ var unspec = docGroup.element().children[1];
+ expect(unspec.getAttribute('class')).toEqual('doc unspecified');
+
+ // Removable
+ expect(unspec.lastChild.children.length).toEqual(1);
+ expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
+ });
+
+ it('should be replaceable by a doc', function () {
+ var doc = unspecifiedClass.create();
+ expect(doc.ldType()).toEqual("non");
+ // No parent, therefor not updateable
+ expect(doc.key("baum")).toBeNull();
+
+ var docGroup = docGroupClass.create();
+ docGroup.operation('or');
+ expect(docGroup.operation()).toEqual('or');
+
+ docGroup.append({
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:eq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ });
+
+ expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05");
+ docGroup.append();
+
+ expect(docGroup.getOperand(0).ldType()).toEqual("doc");
+ expect(docGroup.getOperand(1).ldType()).toEqual("non");
+
+ var op = docGroup.getOperand(1).element().lastChild;
+ expect(op.getAttribute('class')).toEqual('operators');
+ expect(op.children[0].getAttribute('class')).toEqual('delete');
+ expect(op.children.length).toEqual(1);
+
+ // Replace unspecified doc
+ expect(docGroup.getOperand(1).key("name")).not.toBeNull();
+ expect(docGroup.getOperand(1).ldType()).toEqual("doc");
+ expect(docGroup.getOperand(1).key()).toEqual("name");
+ expect(docGroup.getOperand(1).value()).toEqual("");
+
+ op = docGroup.getOperand(1).element().lastChild;
+ expect(op.getAttribute('class')).toEqual('operators');
+ expect(op.children[0].getAttribute('class')).toEqual('and');
+ expect(op.children[1].getAttribute('class')).toEqual('or');
+ expect(op.children[2].getAttribute('class')).toEqual('delete');
+ expect(op.children.length).toEqual(3);
+
+ docGroup.getOperand(1).value("Pachelbel");
+ expect(docGroup.getOperand(1).value()).toEqual("Pachelbel");
+ expect(docGroup.getOperand(1).type()).toEqual("string");
+ expect(docGroup.getOperand(1).matchop()).toEqual("eq");
+
+ // Specified!
+ expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"');
+ });
+
+ it('should be replaceable on root', function () {
+ var vc = vcClass.render();
+ expect(vc.toQuery()).toEqual("");
+
+ expect(vc.root().ldType()).toEqual("non");
+
+ // No operators on root
+ op = vc.root().element().lastChild;
+ expect(op.lastChild.textContent).toEqual('⋯');
+
+ // Replace
+ expect(vc.root().key("baum")).not.toBeNull();
+ expect(vc.root().ldType()).toEqual("doc");
+
+ op = vc.root().element().lastChild;
+ expect(op.getAttribute('class')).toEqual('operators');
+ expect(op.children[0].getAttribute('class')).toEqual('and');
+ expect(op.children[1].getAttribute('class')).toEqual('or');
+ expect(op.children[2].getAttribute('class')).toEqual('delete');
+ expect(op.children.length).toEqual(3);
+ });
+ });
+
+ describe('KorAP.Doc element', function () {
+ it('should be initializable', function () {
+ var docElement = docClass.create(undefined, {
+ "@type" : "koral:doc",
+ "key":"Titel",
+ "value":"Baum",
+ "match":"match:eq"
+ });
+ expect(docElement.key()).toEqual('Titel');
+ expect(docElement.matchop()).toEqual('eq');
+ expect(docElement.value()).toEqual('Baum');
+
+ var docE = docElement.element();
+ expect(docE.children[0].firstChild.data).toEqual('Titel');
+ expect(docE.children[1].firstChild.data).toEqual('eq');
+ expect(docE.children[1].getAttribute('data-type')).toEqual('string');
+ expect(docE.children[2].firstChild.data).toEqual('Baum');
+ expect(docE.children[2].getAttribute('data-type')).toEqual('string');
+
+ expect(docElement.toJson()).toEqual(jasmine.objectContaining({
+ "@type" : "koral:doc",
+ "key":"Titel",
+ "value":"Baum",
+ "match":"match:eq"
+ }));
+ });
+ });
+
+ describe('KorAP.DocGroup element', function () {
+ it('should be initializable', function () {
+
+ var docGroup = docGroupClass.create(undefined, {
+ "@type" : "koral:docGroup",
+ "operation" : "operation:and",
+ "operands" : [
+ {
+ "@type": 'koral:doc',
+ "key" : 'author',
+ "match": 'match:eq',
+ "value": 'Max Birkendale',
+ "type": 'type:string'
+ },
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:eq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ }
+ ]
+ });
+
+ expect(docGroup.operation()).toEqual('and');
+ var e = docGroup.element();
+ expect(e.getAttribute('class')).toEqual('docGroup');
+ expect(e.getAttribute('data-operation')).toEqual('and');
+
+ var first = e.children[0];
+ expect(first.getAttribute('class')).toEqual('doc');
+ expect(first.children[0].getAttribute('class')).toEqual('key');
+ expect(first.children[1].getAttribute('class')).toEqual('match');
+ expect(first.children[2].getAttribute('class')).toEqual('value');
+ expect(first.children[2].getAttribute('data-type')).toEqual('string');
+ expect(first.children[0].firstChild.data).toEqual('author');
+ expect(first.children[1].firstChild.data).toEqual('eq');
+ expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
+
+ var second = e.children[1];
+ expect(second.getAttribute('class')).toEqual('doc');
+ expect(second.children[0].getAttribute('class')).toEqual('key');
+ expect(second.children[1].getAttribute('class')).toEqual('match');
+ expect(second.children[2].getAttribute('class')).toEqual('value');
+ expect(second.children[2].getAttribute('data-type')).toEqual('date');
+ expect(second.children[0].firstChild.data).toEqual('pubDate');
+ expect(second.children[1].firstChild.data).toEqual('eq');
+ expect(second.children[2].firstChild.data).toEqual('2014-12-05');
+ });
+
+ it('should be deserializable with nested groups', function () {
+ var docGroup = docGroupClass.create(undefined, {
+ "@type" : "koral:docGroup",
+ "operation" : "operation:or",
+ "operands" : [
+ {
+ "@type": 'koral:doc',
+ "key" : 'author',
+ "match": 'match:eq',
+ "value": 'Max Birkendale',
+ "type": 'type:string'
+ },
+ {
+ "@type" : "koral:docGroup",
+ "operation" : "operation:and",
+ "operands" : [
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:geq',
+ "value": '2014-05-12',
+ "type": 'type:date'
+ },
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:leq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ }
+ ]
+ }
+ ]
+ });
+
+ expect(docGroup.operation()).toEqual('or');
+ var e = docGroup.element();
+ expect(e.getAttribute('class')).toEqual('docGroup');
+ expect(e.getAttribute('data-operation')).toEqual('or');
+
+ expect(e.children[0].getAttribute('class')).toEqual('doc');
+ var docop = e.children[0].lastChild;
+ expect(docop.getAttribute('class')).toEqual('operators');
+ expect(docop.children[0].getAttribute('class')).toEqual('and');
+ expect(docop.children[1].getAttribute('class')).toEqual('or');
+ expect(docop.children[2].getAttribute('class')).toEqual('delete');
+
+ expect(e.children[1].getAttribute('class')).toEqual('docGroup');
+ expect(e.children[1].getAttribute('data-operation')).toEqual('and');
+
+ // This and-operation can be "or"ed or "delete"d
+ var secop = e.children[1].children[2];
+ expect(secop.getAttribute('class')).toEqual('operators');
+ expect(secop.children[0].getAttribute('class')).toEqual('or');
+ expect(secop.children[1].getAttribute('class')).toEqual('delete');
+
+ // This or-operation can be "and"ed or "delete"d
+ expect(e.children[2].getAttribute('class')).toEqual('operators');
+ expect(e.lastChild.getAttribute('class')).toEqual('operators');
+ expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
+ expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
+ });
+ });
+
+ describe('KorAP.VirtualCollection', function () {
+ var simpleGroupFactory = buildFactory(docGroupClass, {
+ "@type" : "koral:docGroup",
+ "operation" : "operation:and",
+ "operands" : [
+ {
+ "@type": 'koral:doc',
+ "key" : 'author',
+ "match": 'match:eq',
+ "value": 'Max Birkendale',
+ "type": 'type:string'
+ },
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:eq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ }
+ ]
+ });
+
+ var nestedGroupFactory = buildFactory(vcClass, {
+ "@type" : "koral:docGroup",
+ "operation" : "operation:or",
+ "operands" : [
+ {
+ "@type": 'koral:doc',
+ "key" : 'author',
+ "match": 'match:eq',
+ "value": 'Max Birkendale',
+ "type": 'type:string'
+ },
+ {
+ "@type" : "koral:docGroup",
+ "operation" : "operation:and",
+ "operands" : [
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:geq',
+ "value": '2014-05-12',
+ "type": 'type:date'
+ },
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:leq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ }
+ ]
+ }
+ ]
+ });
+
+ var flatGroupFactory = buildFactory(vcClass, {
+ "@type" : "koral:docGroup",
+ "operation" : "operation:and",
+ "operands" : [
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:geq',
+ "value": '2014-05-12',
+ "type": 'type:date'
+ },
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:leq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ },
+ {
+ "@type": 'koral:doc',
+ "key": 'foo',
+ "match": 'match:eq',
+ "value": 'bar',
+ "type": 'type:string'
+ }
+ ]
+ });
+
+ it('should be initializable', function () {
+ var vc = vcClass.render();
+ expect(vc.element().getAttribute('class')).toEqual('vc');
+ expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
+
+ // Not removable
+ expect(vc.root().element().lastChild.children.length).toEqual(0);
+ });
+
+ it('should be based on a doc', function () {
+ var vc = vcClass.render({
+ "@type" : "koral:doc",
+ "key":"Titel",
+ "value":"Baum",
+ "match":"match:eq"
+ });
+
+ expect(vc.element().getAttribute('class')).toEqual('vc');
+ expect(vc.root().element().getAttribute('class')).toEqual('doc');
+ expect(vc.root().key()).toEqual('Titel');
+ expect(vc.root().value()).toEqual('Baum');
+ expect(vc.root().matchop()).toEqual('eq');
+
+ var docE = vc.root().element();
+ expect(docE.children[0].firstChild.data).toEqual('Titel');
+ expect(docE.children[1].firstChild.data).toEqual('eq');
+ expect(docE.children[1].getAttribute('data-type')).toEqual('string');
+ expect(docE.children[2].firstChild.data).toEqual('Baum');
+ expect(docE.children[2].getAttribute('data-type')).toEqual('string');
+ });
+
+ it('should be based on a docGroup', function () {
+ var vc = vcClass.render(simpleGroupFactory.create().toJson());
+
+ expect(vc.element().getAttribute('class')).toEqual('vc');
+ expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
+ expect(vc.root().operation()).toEqual('and');
+
+ var docGroup = vc.root();
+
+ var first = docGroup.getOperand(0);
+ expect(first.key()).toEqual('author');
+ expect(first.value()).toEqual('Max Birkendale');
+ expect(first.matchop()).toEqual('eq');
+
+ var second = docGroup.getOperand(1);
+ expect(second.key()).toEqual('pubDate');
+ expect(second.value()).toEqual('2014-12-05');
+ expect(second.matchop()).toEqual('eq');
+ });
+
+
+ it('should be based on a nested docGroup', function () {
+ var vc = nestedGroupFactory.create();
+
+ expect(vc.element().getAttribute('class')).toEqual('vc');
+ expect(vc.element().firstChild.getAttribute('class')).toEqual('docGroup');
+ expect(vc.element().firstChild.children[0].getAttribute('class')).toEqual('doc');
+ var dg = vc.element().firstChild.children[1];
+ expect(dg.getAttribute('class')).toEqual('docGroup');
+ expect(dg.children[0].getAttribute('class')).toEqual('doc');
+ expect(dg.children[1].getAttribute('class')).toEqual('doc');
+ expect(dg.children[2].getAttribute('class')).toEqual('operators');
+ expect(vc.element().firstChild.children[2].getAttribute('class')).toEqual('operators');
+ });
+
+ it('should be modifiable by deletion in flat docGroups', function () {
+ var vc = flatGroupFactory.create();
+ var docGroup = vc.root();
+
+ expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
+
+ var doc = docGroup.getOperand(1);
+ expect(doc.key()).toEqual("pubDate");
+ expect(doc.value()).toEqual("2014-12-05");
+
+ // Remove operand 1
+ expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
+ expect(doc._element).toEqual(undefined);
+
+ doc = docGroup.getOperand(1);
+ expect(doc.key()).toEqual("foo");
+
+ // Remove operand 1
+ expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
+ expect(doc._element).toEqual(undefined);
+
+ // Only one operand left ...
+ expect(docGroup.getOperand(1)).toBeUndefined();
+ // ... but there shouldn't be a group anymore at all!
+ expect(docGroup.getOperand(0)).toBeUndefined();
+
+ var obj = vc.root();
+ expect(obj.ldType()).toEqual("doc");
+ expect(obj.key()).toEqual("pubDate");
+ expect(obj.value()).toEqual("2014-05-12");
+
+ expect(obj.element().getAttribute('class')).toEqual('doc');
+ });
+
+
+ it('should be modifiable by deletion in nested docGroups (root case)', function () {
+ var vc = nestedGroupFactory.create();
+
+ expect(vc.toQuery()).toEqual(
+ 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
+ );
+
+ var docGroup = vc.root();
+ expect(docGroup.ldType()).toEqual("docGroup");
+ expect(docGroup.operation()).toEqual("or");
+
+ var doc = docGroup.getOperand(0);
+ expect(doc.key()).toEqual("author");
+ expect(doc.value()).toEqual("Max Birkendale");
+
+ docGroup = docGroup.getOperand(1);
+ expect(docGroup.operation()).toEqual("and");
+
+ doc = docGroup.getOperand(0);
+ expect(doc.key()).toEqual("pubDate");
+ expect(doc.matchop()).toEqual("geq");
+ expect(doc.value()).toEqual("2014-05-12");
+ expect(doc.type()).toEqual("date");
+
+ doc = docGroup.getOperand(1);
+ expect(doc.key()).toEqual("pubDate");
+ expect(doc.matchop()).toEqual("leq");
+ expect(doc.value()).toEqual("2014-12-05");
+ expect(doc.type()).toEqual("date");
+
+ // Remove first operand so everything becomes root
+ expect(
+ vc.root().delOperand(
+ vc.root().getOperand(0)
+ ).update().ldType()
+ ).toEqual("docGroup");
+
+ expect(vc.root().ldType()).toEqual("docGroup");
+ expect(vc.root().operation()).toEqual("and");
+ expect(vc.root().getOperand(0).ldType()).toEqual("doc");
+
+ expect(vc.toQuery()).toEqual(
+ 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
+ );
+ });
+
+ it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
+ var vc = nestedGroupFactory.create();
+
+ // Get nested group
+ var firstGroup = vc.root().getOperand(1);
+ firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
+
+ // Structur is now:
+ // or(doc, and(doc, doc, or(doc, doc)))
+
+ // Get nested or in and
+ var orGroup = vc.root().getOperand(1).getOperand(2);
+ expect(orGroup.ldType()).toEqual("docGroup");
+ expect(orGroup.operation()).toEqual("or");
+
+ // Remove
+ // Structur is now:
+ // or(doc, and(doc, doc, doc)))
+ expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
+ expect(vc.root().getOperand(1).operands().length).toEqual(3);
+ });
+
+ it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
+ var vc = nestedGroupFactory.create();
+
+ // Get nested group
+ var firstGroup = vc.root().getOperand(1);
+ firstGroup.append(simpleGroupFactory.create({
+ "operation" : "operation:or"
+ }));
+ var oldAuthor = firstGroup.getOperand(2).getOperand(0);
+ oldAuthor.key("title");
+ oldAuthor.value("Der Birnbaum");
+
+ // Structur is now:
+ // or(doc, and(doc, doc, or(doc, doc)))
+ expect(vc.toQuery()).toEqual(
+ 'author = "Max Birkendale" | ' +
+ '(pubDate since 2014-05-12 & ' +
+ 'pubDate until 2014-12-05 & ' +
+ '(title = "Der Birnbaum" | ' +
+ 'pubDate in 2014-12-05))'
+ );
+
+ var andGroup = vc.root().getOperand(1);
+
+ // Get leading docs in and
+ var doc1 = andGroup.getOperand(0);
+ expect(doc1.ldType()).toEqual("doc");
+ expect(doc1.value()).toEqual("2014-05-12");
+ var doc2 = andGroup.getOperand(1);
+ expect(doc2.ldType()).toEqual("doc");
+ expect(doc2.value()).toEqual("2014-12-05");
+
+ // Remove 2
+ expect(
+ andGroup.delOperand(doc2).update().operation()
+ ).toEqual("and");
+ // Structur is now:
+ // or(doc, and(doc, or(doc, doc)))
+
+ expect(vc.toQuery()).toEqual(
+ 'author = "Max Birkendale"' +
+ ' | (pubDate since 2014-05-12 & ' +
+ '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
+ );
+
+
+ // Remove 1
+ expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
+ // Structur is now:
+ // or(doc, doc, doc)
+
+ expect(vc.toQuery()).toEqual(
+ 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
+ );
+ });
+
+ it('should be reducible to unspecification', function () {
+ var vc = demoFactory.create();
+
+ expect(vc.toQuery()).toEqual(vc.root().toQuery());
+ expect(vc.toQuery()).toEqual(
+ '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
+ '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
+ '| Untertitel = "huhu"');
+ expect(vc.root().element().lastChild.children[0].firstChild.nodeValue).toEqual('and');
+ expect(vc.root().element().lastChild.children[1].firstChild.nodeValue).toEqual('×');
+ expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
+ expect(vc.toQuery()).toEqual('Untertitel = "huhu"');
+
+ var lc = vc.root().element().lastChild;
+ expect(lc.children[0].firstChild.nodeValue).toEqual('and');
+ expect(lc.children[1].firstChild.nodeValue).toEqual('or');
+ expect(lc.children[2].firstChild.nodeValue).toEqual('×');
+
+ // Clean everything
+ vc.clean();
+ expect(vc.toQuery()).toEqual('');
+ });
+
+ it('should flatten on import', function () {
+ var vc = vcClass.create().render({
+ "@type":"koral:docGroup",
+ "operation":"operation:or",
+ "operands":[
+ {
+ "@type":"koral:docGroup",
+ "operation":"operation:or",
+ "operands":[
+ {
+ "@type":"koral:doc",
+ "key":"Titel",
+ "value":"Baum",
+ "match":"match:eq"
+ },
+ {
+ "@type":"koral:doc",
+ "key":"Veröffentlichungsort",
+ "value":"hihi",
+ "match":"match:eq"
+ },
+ {
+ "@type":"koral:docGroup",
+ "operation":"operation:or",
+ "operands":[
{
- '@type' : 'koral:doc',
- 'key' : 'title',
- 'value' : 'Hello World!'
+ "@type":"koral:doc",
+ "key":"Titel",
+ "value":"Baum",
+ "match":"match:eq"
},
{
- '@type' : 'koral:doc',
- 'key' : 'yeah',
- 'value' : 'juhu'
+ "@type":"koral:doc",
+ "key":"Veröffentlichungsort",
+ "value":"hihi",
+ "match":"match:eq"
}
]
- }
- ]
- }
- ]
- }
- );
-
- // Delete with direct element access
- expect(vc.toQuery()).toEqual(
- 'pubDate in 2014-12-05 | foo = "bar" | ' +
- '(pubDate in 2014-12-05 & ' +
- '(title = "Hello World!" | yeah = "juhu"))'
- );
-
- expect(vc.root().ldType()).toEqual('docGroup');
- expect(vc.root().operation()).toEqual('or');
-
- // Operands and operators
- expect(vc.element().firstChild.children.length).toEqual(4);
- expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators');
-
- // Remove inner group and flatten
- _delOn(vc.root().getOperand(2).getOperand(0));
-
- expect(vc.toQuery()).toEqual(
- 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
- );
- expect(vc.root().ldType()).toEqual('docGroup');
- expect(vc.root().operation()).toEqual('or');
-
- // Operands and operators
- expect(vc.element().firstChild.children.length).toEqual(5);
- expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators');
- });
-});
-
-describe('KorAP._add (event)', function () {
- var complexVCFactory = buildFactory(KorAP.VirtualCollection,{
- "@type": 'koral:docGroup',
- 'operation' : 'operation:and',
- 'operands' : [
- {
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:eq',
- "value": '2014-12-05',
- "type": 'type:date'
- },
- {
- "@type" : 'koral:docGroup',
- 'operation' : 'operation:or',
- 'operands' : [
- {
- '@type' : 'koral:doc',
- 'key' : 'title',
- 'value' : 'Hello World!'
- },
- {
- '@type' : 'koral:doc',
- 'key' : 'foo',
- 'value' : 'bar'
- }
- ]
- }
- ]
- });
-
- it ('should add new unspecified doc with "and"', function () {
- var vc = KorAP.VirtualCollection.render(
- {
- "@type": 'koral:docGroup',
- 'operation' : 'operation:and',
- 'operands' : [
- {
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:eq',
- "value": '2014-12-05',
- "type": 'type:date'
- },
- {
- "@type" : 'koral:doc',
- 'key' : 'foo',
- 'value' : 'bar'
- }
- ]
- }
- );
-
- expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
-
- var fc = vc.element().firstChild;
- expect(fc.getAttribute('data-operation')).toEqual('and');
- expect(fc.children.length).toEqual(3);
- expect(fc.lastChild.getAttribute('class')).toEqual('operators');
- expect(fc.children[0].getAttribute('class')).toEqual('doc');
- expect(fc.children[1].getAttribute('class')).toEqual('doc');
-
- // add with 'and' in the middle
- _andOn(vc.root().getOperand(0));
- expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
-
- fc = vc.element().firstChild;
- expect(fc.getAttribute('data-operation')).toEqual('and');
- expect(fc.children.length).toEqual(4);
- expect(fc.lastChild.getAttribute('class')).toEqual('operators');
-
- expect(fc.children[0].getAttribute('class')).toEqual('doc');
- expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
- expect(fc.children[2].getAttribute('class')).toEqual('doc');
- });
-
- it ('should add new unspecified doc with "or"', function () {
- var vc = KorAP.VirtualCollection.render(
- {
- "@type": 'koral:docGroup',
- 'operation' : 'operation:and',
- 'operands' : [
- {
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:eq',
- "value": '2014-12-05',
- "type": 'type:date'
- },
- {
- "@type" : 'koral:doc',
- 'key' : 'foo',
- 'value' : 'bar'
- }
- ]
- }
- );
-
- expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
-
- var fc = vc.element().firstChild;
- expect(fc.children.length).toEqual(3);
- expect(fc.lastChild.getAttribute('class')).toEqual('operators');
- expect(fc.children[0].getAttribute('class')).toEqual('doc');
- expect(fc.children[1].getAttribute('class')).toEqual('doc');
-
- // add with 'or' in the middle
- _orOn(vc.root().getOperand(0));
- expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
- fc = vc.element().firstChild;
-
- expect(fc.getAttribute('data-operation')).toEqual('and');
- expect(fc.children.length).toEqual(3);
- expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
- expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
- expect(fc.children[1].getAttribute('class')).toEqual('doc');
- expect(fc.children[2].getAttribute('class')).toEqual('operators');
- expect(fc.lastChild.getAttribute('class')).toEqual('operators');
-
- fc = vc.element().firstChild.firstChild;
- expect(fc.children.length).toEqual(3);
- expect(fc.children[0].getAttribute('class')).toEqual('doc');
- expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
- expect(fc.children[2].getAttribute('class')).toEqual('operators');
- expect(fc.lastChild.getAttribute('class')).toEqual('operators');
- });
-
- it ('should add new unspecified doc with "and" before group', function () {
- var vc = demoFactory.create();
-
- // Wrap with direct element access
- expect(vc.toQuery()).toEqual(
- '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel = "huhu"'
- );
-
- expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
- expect(vc.root().getOperand(0).operation()).toEqual('and');
- expect(vc.root().getOperand(0).operands().length).toEqual(3);
-
- // Add unspecified on the second doc
- var secDoc = vc.root().getOperand(0).getOperand(1);
- expect(secDoc.value()).toEqual('hihi');
-
- // Add
- _andOn(secDoc);
-
- var fo = vc.root().getOperand(0);
-
- expect(fo.ldType()).toEqual('docGroup');
- expect(fo.operation()).toEqual('and');
- expect(fo.operands().length).toEqual(4);
-
- expect(fo.getOperand(0).ldType()).toEqual('doc');
- expect(fo.getOperand(1).ldType()).toEqual('doc');
- expect(fo.getOperand(2).ldType()).toEqual('non');
- expect(fo.getOperand(3).ldType()).toEqual('docGroup');
- });
-
-
- it ('should remove a doc with an unspecified doc in a nested group', function () {
- var vc = demoFactory.create();
-
- // Wrap with direct element access
- expect(vc.toQuery()).toEqual(
- '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel = "huhu"'
- );
-
- var fo = vc.root().getOperand(0).getOperand(0);
- expect(fo.key()).toEqual('Titel');
- expect(fo.value()).toEqual('Baum');
-
- // Add unspecified on the root group
- _orOn(fo);
-
- fo = vc.root().getOperand(0).getOperand(0);
-
- expect(fo.operation()).toEqual('or');
- expect(fo.getOperand(0).ldType()).toEqual('doc');
- expect(fo.getOperand(1).ldType()).toEqual('non');
-
- // Delete document
- _delOn(fo.getOperand(0));
-
- // The operand is now non
- expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
- expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
- expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
- });
-
- it ('should remove an unspecified doc with an doc in a nested group', function () {
- var vc = demoFactory.create();
-
- // Wrap with direct element access
- expect(vc.toQuery()).toEqual(
- '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel = "huhu"'
- );
-
- var fo = vc.root().getOperand(0).getOperand(0);
- expect(fo.key()).toEqual('Titel');
- expect(fo.value()).toEqual('Baum');
-
- // Add unspecified on the root group
- _orOn(fo);
-
- fo = vc.root().getOperand(0).getOperand(0);
-
- expect(fo.operation()).toEqual('or');
- expect(fo.getOperand(0).ldType()).toEqual('doc');
- expect(fo.getOperand(1).ldType()).toEqual('non');
-
- // Delete unspecified doc
- _delOn(fo.getOperand(1));
-
- // The operand is now non
- fo = vc.root().getOperand(0);
- expect(fo.getOperand(0).ldType()).toEqual('doc');
- expect(fo.getOperand(0).key()).toEqual('Titel');
- expect(fo.getOperand(0).value()).toEqual('Baum');
- expect(fo.getOperand(1).ldType()).toEqual('doc');
- expect(fo.getOperand(2).ldType()).toEqual('docGroup');
- });
-
-
- it ('should add on parent group (case "and")', function () {
- var vc = complexVCFactory.create();
-
- // Wrap with direct element access
- expect(vc.toQuery()).toEqual(
- 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
- );
-
- expect(vc.root().operands().length).toEqual(2);
-
- // Add unspecified on the root group
- _andOn(vc.root().getOperand(1));
- expect(vc.toQuery()).toEqual(
- 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
- );
-
- expect(vc.root().ldType()).toEqual('docGroup');
- expect(vc.root().operands().length).toEqual(3);
- expect(vc.root().getOperand(0).ldType()).toEqual('doc');
- expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
- expect(vc.root().getOperand(1).operation()).toEqual('or');
- expect(vc.root().getOperand(2).ldType()).toEqual('non');
-
- // Add another unspecified on the root group
- _andOn(vc.root().getOperand(1));
-
- expect(vc.root().operands().length).toEqual(4);
- expect(vc.root().getOperand(0).ldType()).toEqual('doc');
- expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
- expect(vc.root().getOperand(2).ldType()).toEqual('non');
- expect(vc.root().getOperand(3).ldType()).toEqual('non');
-
- // Add another unspecified after the first doc
- _andOn(vc.root().getOperand(0));
-
- expect(vc.root().operands().length).toEqual(5);
- expect(vc.root().getOperand(0).ldType()).toEqual('doc');
- expect(vc.root().getOperand(1).ldType()).toEqual('non');
- expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
- expect(vc.root().getOperand(3).ldType()).toEqual('non');
- expect(vc.root().getOperand(4).ldType()).toEqual('non');
- });
-
- it ('should wrap on root', function () {
- var vc = KorAP.VirtualCollection.render(
- {
- "@type": 'koral:docGroup',
- 'operation' : 'operation:and',
- 'operands' : [
- {
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:eq',
- "value": '2014-12-05',
- "type": 'type:date'
- },
- {
- "@type" : 'koral:doc',
- 'key' : 'foo',
- 'value' : 'bar'
- }
- ]
- }
- );
-
- // Wrap on root
- expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
- expect(vc.root().ldType()).toEqual('docGroup');
- expect(vc.root().operation()).toEqual('and');
- _orOn(vc.root());
- expect(vc.root().ldType()).toEqual('docGroup');
- expect(vc.root().operation()).toEqual('or');
-
- expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
- expect(vc.root().getOperand(0).operation()).toEqual('and');
- });
-
- it ('should add on root (case "and")', function () {
- var vc = KorAP.VirtualCollection.render(
- {
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:eq',
- "value": '2014-12-05',
- "type": 'type:date'
- }
- );
-
- expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
- expect(vc.root().ldType()).toEqual('doc');
- expect(vc.root().key()).toEqual('pubDate');
- expect(vc.root().value()).toEqual('2014-12-05');
-
- // Wrap on root
- _andOn(vc.root());
- expect(vc.root().ldType()).toEqual('docGroup');
- expect(vc.root().operation()).toEqual('and');
- });
-
- it ('should add on root (case "or")', function () {
- var vc = KorAP.VirtualCollection.render(
- {
- "@type": 'koral:doc',
- "key": 'pubDate',
- "match": 'match:eq',
- "value": '2014-12-05',
- "type": 'type:date'
- }
- );
-
- expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
- expect(vc.root().key()).toEqual('pubDate');
- expect(vc.root().value()).toEqual('2014-12-05');
-
- // Wrap on root
- _orOn(vc.root());
- expect(vc.root().ldType()).toEqual('docGroup');
- expect(vc.root().operation()).toEqual('or');
- });
-
- it ('should support multiple sub groups per group', function () {
- var vc = KorAP.VirtualCollection.render(
- {
- "@type": 'koral:docGroup',
- 'operation' : 'operation:or',
- 'operands' : [
- {
- "@type": 'koral:docGroup',
- 'operation' : 'operation:and',
- 'operands' : [
- {
- "@type": 'koral:doc',
- "key": 'title',
- "value": 't1',
- },
- {
- "@type" : 'koral:doc',
- 'key' : 'title',
- 'value' : 't2'
- }
+ }
]
},
{
- "@type": 'koral:docGroup',
- 'operation' : 'operation:and',
- 'operands' : [
- {
- "@type": 'koral:doc',
- "key": 'title',
- "value": 't3',
- },
- {
- "@type" : 'koral:doc',
- 'key' : 'title',
- 'value' : 't4'
- }
- ]
+ "@type":"koral:doc",
+ "key":"Untertitel",
+ "value":"huhu",
+ "match":"match:eq"
}
]
- }
- );
- expect(vc.toQuery()).toEqual(
- '(title = "t1" & title = "t2") | (title = "t3" & title = "t4")'
- );
- expect(vc.root().operation()).toEqual('or');
- expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
- expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
+ });
- _andOn(vc.root());
-
- expect(vc.root().operation()).toEqual('and');
- expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
- expect(vc.root().getOperand(1).ldType()).toEqual('non');
- });
-});
-
-describe('KorAP.Rewrite', function () {
-
- it('should be initializable', function () {
- var rewrite = KorAP.Rewrite.create({
- "@type" : "koral:rewrite",
- "operation" : "operation:modification",
- "src" : "querySerializer",
- "scope" : "tree"
+ expect(vc.toQuery()).toEqual(
+ 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel = "huhu"'
+ );
});
- expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
});
- it('should be deserialized by docs', function () {
- var doc = KorAP.Doc.create(undefined,
- {
- "@type":"koral:doc",
- "key":"Titel",
- "value":"Baum",
- "match":"match:eq"
+ describe('KorAP.Operators', function () {
+ it('should be initializable', function () {
+ var op = operatorsClass.create(true, false, false);
+ expect(op.and()).toBeTruthy();
+ expect(op.or()).not.toBeTruthy();
+ expect(op.del()).not.toBeTruthy();
+
+ op.and(false);
+ expect(op.and()).not.toBeTruthy();
+ expect(op.or()).not.toBeTruthy();
+ expect(op.del()).not.toBeTruthy();
+
+ op.or(true);
+ op.del(true);
+ expect(op.and()).not.toBeTruthy();
+ expect(op.or()).toBeTruthy();
+ expect(op.del()).toBeTruthy();
+
+ var e = op.element();
+ expect(e.getAttribute('class')).toEqual('operators');
+ expect(e.children[0].getAttribute('class')).toEqual('or');
+ expect(e.children[0].firstChild.data).toEqual('or');
+ expect(e.children[1].getAttribute('class')).toEqual('delete');
+ expect(e.children[1].firstChild.data).toEqual('×');
+
+ op.and(true);
+ op.del(false);
+ op.update();
+
+ e = op.element();
+ expect(e.getAttribute('class')).toEqual('operators');
+ expect(e.children[0].getAttribute('class')).toEqual('and');
+ expect(e.children[0].firstChild.data).toEqual('and');
+ expect(e.children[1].getAttribute('class')).toEqual('or');
+ expect(e.children[1].firstChild.data).toEqual('or');
+ });
+ });
+
+ describe('KorAP._delete (event)', function () {
+ var complexVCFactory = buildFactory(vcClass,{
+ "@type": 'koral:docGroup',
+ 'operation' : 'operation:and',
+ 'operands' : [
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:eq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ },
+ {
+ "@type" : 'koral:docGroup',
+ 'operation' : 'operation:or',
+ 'operands' : [
+ {
+ '@type' : 'koral:doc',
+ 'key' : 'title',
+ 'value' : 'Hello World!'
+ },
+ {
+ '@type' : 'koral:doc',
+ 'key' : 'foo',
+ 'value' : 'bar'
+ }
+ ]
+ }
+ ]
+ });
+
+ it('should clean on root docs', function () {
+ var vc = vcClass.render({
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:eq',
+ "value": '2014-12-05',
+ "type": 'type:date'
});
+ expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
+ expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators');
- expect(doc.element().classList.contains('doc')).toBeTruthy();
- expect(doc.element().classList.contains('rewritten')).toBe(false);
+ // Clean with delete from root
+ expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
+ _delOn(vc.root());
+ expect(vc.root().toQuery()).toEqual('');
+ expect(vc.root().element().lastChild.lastChild.data).toEqual('⋯');
+ });
- doc = KorAP.Doc.create(undefined,
- {
- "@type":"koral:doc",
- "key":"Titel",
- "value":"Baum",
- "match":"match:eq",
- "rewrites" : [
- {
- "@type" : "koral:rewrite",
- "operation" : "operation:modification",
- "src" : "querySerializer",
- "scope" : "tree"
- }
- ]
+ it('should remove on nested docs', function () {
+ var vc = vcClass.render(
+ {
+ "@type": 'koral:docGroup',
+ 'operation' : 'operation:and',
+ 'operands' : [
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:eq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ },
+ {
+ "@type" : 'koral:doc',
+ 'key' : 'foo',
+ 'value' : 'bar'
+ }
+ ]
+ }
+ );
+
+ // Delete with direct element access
+ expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
+ _delOn(vc.root().getOperand(0));
+
+ expect(vc.toQuery()).toEqual('foo = "bar"');
+ expect(vc.root().ldType()).toEqual('doc');
+ });
+
+ it('should clean on doc groups', function () {
+ var vc = vcClass.render(
+ {
+ "@type": 'koral:docGroup',
+ 'operation' : 'operation:and',
+ 'operands' : [
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:eq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ },
+ {
+ "@type" : 'koral:doc',
+ 'key' : 'foo',
+ 'value' : 'bar'
+ }
+ ]
+ }
+ );
+
+ // Cleanwith direct element access
+ expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
+ _delOn(vc.root());
+ expect(vc.toQuery()).toEqual('');
+ expect(vc.root().ldType()).toEqual('non');
+ });
+
+ it('should remove on nested doc groups (case of ungrouping 1)', function () {
+ var vc = complexVCFactory.create();
+
+ // Delete with direct element access
+ expect(vc.toQuery()).toEqual(
+ 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
+ );
+
+ // Remove hello world:
+ _delOn(vc.root().getOperand(1).getOperand(0));
+ expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
+ expect(vc.root().ldType()).toEqual('docGroup');
+ });
+
+ it('should remove on nested doc groups (case of ungrouping 2)', function () {
+ var vc = complexVCFactory.create();
+
+ // Delete with direct element access
+ expect(vc.toQuery()).toEqual(
+ 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
+ );
+
+ // Remove bar
+ _delOn(vc.root().getOperand(1).getOperand(1));
+ expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
+ expect(vc.root().ldType()).toEqual('docGroup');
+ expect(vc.root().operation()).toEqual('and');
+ });
+
+ it('should remove on nested doc groups (case of root changing)', function () {
+ var vc = complexVCFactory.create();
+
+ // Delete with direct element access
+ expect(vc.toQuery()).toEqual(
+ 'pubDate in 2014-12-05 & ' +
+ '(title = "Hello World!" | foo = "bar")'
+ );
+
+ // Remove bar
+ _delOn(vc.root().getOperand(0));
+ expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
+ expect(vc.root().ldType()).toEqual('docGroup');
+ expect(vc.root().operation()).toEqual('or');
+ });
+
+ it('should remove on nested doc groups (list flattening)', function () {
+ var vc = vcClass.render(
+ {
+ "@type": 'koral:docGroup',
+ 'operation' : 'operation:or',
+ 'operands' : [
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:eq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ },
+ {
+ "@type" : 'koral:doc',
+ 'key' : 'foo',
+ 'value' : 'bar'
+ },
+ {
+ "@type": 'koral:docGroup',
+ 'operation' : 'operation:and',
+ 'operands' : [
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:eq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ },
+ {
+ "@type" : 'koral:docGroup',
+ 'operation' : 'operation:or',
+ 'operands' : [
+ {
+ '@type' : 'koral:doc',
+ 'key' : 'title',
+ 'value' : 'Hello World!'
+ },
+ {
+ '@type' : 'koral:doc',
+ 'key' : 'yeah',
+ 'value' : 'juhu'
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ );
+
+ // Delete with direct element access
+ expect(vc.toQuery()).toEqual(
+ 'pubDate in 2014-12-05 | foo = "bar" | ' +
+ '(pubDate in 2014-12-05 & ' +
+ '(title = "Hello World!" | yeah = "juhu"))'
+ );
+
+ expect(vc.root().ldType()).toEqual('docGroup');
+ expect(vc.root().operation()).toEqual('or');
+
+ // Operands and operators
+ expect(vc.element().firstChild.children.length).toEqual(4);
+ expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators');
+
+ // Remove inner group and flatten
+ _delOn(vc.root().getOperand(2).getOperand(0));
+
+ expect(vc.toQuery()).toEqual(
+ 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
+ );
+ expect(vc.root().ldType()).toEqual('docGroup');
+ expect(vc.root().operation()).toEqual('or');
+
+ // Operands and operators
+ expect(vc.element().firstChild.children.length).toEqual(5);
+ expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators');
+ });
+ });
+
+ describe('KorAP._add (event)', function () {
+ var complexVCFactory = buildFactory(vcClass,{
+ "@type": 'koral:docGroup',
+ 'operation' : 'operation:and',
+ 'operands' : [
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:eq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ },
+ {
+ "@type" : 'koral:docGroup',
+ 'operation' : 'operation:or',
+ 'operands' : [
+ {
+ '@type' : 'koral:doc',
+ 'key' : 'title',
+ 'value' : 'Hello World!'
+ },
+ {
+ '@type' : 'koral:doc',
+ 'key' : 'foo',
+ 'value' : 'bar'
+ }
+ ]
+ }
+ ]
+ });
+
+ it('should add new unspecified doc with "and"', function () {
+ var vc = vcClass.render(
+ {
+ "@type": 'koral:docGroup',
+ 'operation' : 'operation:and',
+ 'operands' : [
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:eq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ },
+ {
+ "@type" : 'koral:doc',
+ 'key' : 'foo',
+ 'value' : 'bar'
+ }
+ ]
+ }
+ );
+
+ expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
+
+ var fc = vc.element().firstChild;
+ expect(fc.getAttribute('data-operation')).toEqual('and');
+ expect(fc.children.length).toEqual(3);
+ expect(fc.lastChild.getAttribute('class')).toEqual('operators');
+ expect(fc.children[0].getAttribute('class')).toEqual('doc');
+ expect(fc.children[1].getAttribute('class')).toEqual('doc');
+
+ // add with 'and' in the middle
+ _andOn(vc.root().getOperand(0));
+ expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
+
+ fc = vc.element().firstChild;
+ expect(fc.getAttribute('data-operation')).toEqual('and');
+ expect(fc.children.length).toEqual(4);
+ expect(fc.lastChild.getAttribute('class')).toEqual('operators');
+
+ expect(fc.children[0].getAttribute('class')).toEqual('doc');
+ expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
+ expect(fc.children[2].getAttribute('class')).toEqual('doc');
+ });
+
+ it('should add new unspecified doc with "or"', function () {
+ var vc = vcClass.render(
+ {
+ "@type": 'koral:docGroup',
+ 'operation' : 'operation:and',
+ 'operands' : [
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:eq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ },
+ {
+ "@type" : 'koral:doc',
+ 'key' : 'foo',
+ 'value' : 'bar'
+ }
+ ]
+ }
+ );
+
+ expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
+
+ var fc = vc.element().firstChild;
+ expect(fc.children.length).toEqual(3);
+ expect(fc.lastChild.getAttribute('class')).toEqual('operators');
+ expect(fc.children[0].getAttribute('class')).toEqual('doc');
+ expect(fc.children[1].getAttribute('class')).toEqual('doc');
+
+ // add with 'or' in the middle
+ _orOn(vc.root().getOperand(0));
+ expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
+ fc = vc.element().firstChild;
+
+ expect(fc.getAttribute('data-operation')).toEqual('and');
+ expect(fc.children.length).toEqual(3);
+ expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
+ expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
+ expect(fc.children[1].getAttribute('class')).toEqual('doc');
+ expect(fc.children[2].getAttribute('class')).toEqual('operators');
+ expect(fc.lastChild.getAttribute('class')).toEqual('operators');
+
+ fc = vc.element().firstChild.firstChild;
+ expect(fc.children.length).toEqual(3);
+ expect(fc.children[0].getAttribute('class')).toEqual('doc');
+ expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
+ expect(fc.children[2].getAttribute('class')).toEqual('operators');
+ expect(fc.lastChild.getAttribute('class')).toEqual('operators');
+ });
+
+ it('should add new unspecified doc with "and" before group', function () {
+ var vc = demoFactory.create();
+
+ // Wrap with direct element access
+ expect(vc.toQuery()).toEqual(
+ '(Titel = "Baum" & ' +
+ 'Veröffentlichungsort = "hihi" & ' +
+ '(Titel = "Baum" | ' +
+ 'Veröffentlichungsort = "hihi")) | ' +
+ 'Untertitel = "huhu"'
+ );
+
+ expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
+ expect(vc.root().getOperand(0).operation()).toEqual('and');
+ expect(vc.root().getOperand(0).operands().length).toEqual(3);
+
+ // Add unspecified on the second doc
+ var secDoc = vc.root().getOperand(0).getOperand(1);
+ expect(secDoc.value()).toEqual('hihi');
+
+ // Add
+ _andOn(secDoc);
+
+ var fo = vc.root().getOperand(0);
+
+ expect(fo.ldType()).toEqual('docGroup');
+ expect(fo.operation()).toEqual('and');
+ expect(fo.operands().length).toEqual(4);
+
+ expect(fo.getOperand(0).ldType()).toEqual('doc');
+ expect(fo.getOperand(1).ldType()).toEqual('doc');
+ expect(fo.getOperand(2).ldType()).toEqual('non');
+ expect(fo.getOperand(3).ldType()).toEqual('docGroup');
+ });
+
+
+ it('should remove a doc with an unspecified doc in a nested group', function () {
+ var vc = demoFactory.create();
+
+ // Wrap with direct element access
+ expect(vc.toQuery()).toEqual(
+ '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel = "huhu"'
+ );
+
+ var fo = vc.root().getOperand(0).getOperand(0);
+ expect(fo.key()).toEqual('Titel');
+ expect(fo.value()).toEqual('Baum');
+
+ // Add unspecified on the root group
+ _orOn(fo);
+
+ fo = vc.root().getOperand(0).getOperand(0);
+
+ expect(fo.operation()).toEqual('or');
+ expect(fo.getOperand(0).ldType()).toEqual('doc');
+ expect(fo.getOperand(1).ldType()).toEqual('non');
+
+ // Delete document
+ _delOn(fo.getOperand(0));
+
+ // The operand is now non
+ expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
+ expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
+ expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
+ });
+
+
+ it('should remove an unspecified doc with an doc in a nested group', function () {
+ var vc = demoFactory.create();
+
+ // Wrap with direct element access
+ expect(vc.toQuery()).toEqual(
+ '(Titel = "Baum" & ' +
+ 'Veröffentlichungsort = "hihi" & ' +
+ '(Titel = "Baum" ' +
+ '| Veröffentlichungsort = "hihi")) | ' +
+ 'Untertitel = "huhu"'
+ );
+
+ var fo = vc.root().getOperand(0).getOperand(0);
+ expect(fo.key()).toEqual('Titel');
+ expect(fo.value()).toEqual('Baum');
+
+ // Add unspecified on the root group
+ _orOn(fo);
+
+ fo = vc.root().getOperand(0).getOperand(0);
+
+ expect(fo.operation()).toEqual('or');
+ expect(fo.getOperand(0).ldType()).toEqual('doc');
+ expect(fo.getOperand(1).ldType()).toEqual('non');
+
+ // Delete unspecified doc
+ _delOn(fo.getOperand(1));
+
+ // The operand is now non
+ fo = vc.root().getOperand(0);
+ expect(fo.getOperand(0).ldType()).toEqual('doc');
+ expect(fo.getOperand(0).key()).toEqual('Titel');
+ expect(fo.getOperand(0).value()).toEqual('Baum');
+ expect(fo.getOperand(1).ldType()).toEqual('doc');
+ expect(fo.getOperand(2).ldType()).toEqual('docGroup');
+ });
+
+
+ it('should add on parent group (case "and")', function () {
+ var vc = complexVCFactory.create();
+
+ // Wrap with direct element access
+ expect(vc.toQuery()).toEqual(
+ 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
+ );
+
+ expect(vc.root().operands().length).toEqual(2);
+
+ // Add unspecified on the root group
+ _andOn(vc.root().getOperand(1));
+ expect(vc.toQuery()).toEqual(
+ 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
+ );
+
+ expect(vc.root().ldType()).toEqual('docGroup');
+ expect(vc.root().operands().length).toEqual(3);
+ expect(vc.root().getOperand(0).ldType()).toEqual('doc');
+ expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
+ expect(vc.root().getOperand(1).operation()).toEqual('or');
+ expect(vc.root().getOperand(2).ldType()).toEqual('non');
+
+ // Add another unspecified on the root group
+ _andOn(vc.root().getOperand(1));
+
+ expect(vc.root().operands().length).toEqual(4);
+ expect(vc.root().getOperand(0).ldType()).toEqual('doc');
+ expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
+ expect(vc.root().getOperand(2).ldType()).toEqual('non');
+ expect(vc.root().getOperand(3).ldType()).toEqual('non');
+
+ // Add another unspecified after the first doc
+ _andOn(vc.root().getOperand(0));
+
+ expect(vc.root().operands().length).toEqual(5);
+ expect(vc.root().getOperand(0).ldType()).toEqual('doc');
+ expect(vc.root().getOperand(1).ldType()).toEqual('non');
+ expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
+ expect(vc.root().getOperand(3).ldType()).toEqual('non');
+ expect(vc.root().getOperand(4).ldType()).toEqual('non');
+ });
+
+ it('should wrap on root', function () {
+ var vc = vcClass.render(
+ {
+ "@type": 'koral:docGroup',
+ 'operation' : 'operation:and',
+ 'operands' : [
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:eq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ },
+ {
+ "@type" : 'koral:doc',
+ 'key' : 'foo',
+ 'value' : 'bar'
+ }
+ ]
+ }
+ );
+
+ // Wrap on root
+ expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
+ expect(vc.root().ldType()).toEqual('docGroup');
+ expect(vc.root().operation()).toEqual('and');
+ _orOn(vc.root());
+ expect(vc.root().ldType()).toEqual('docGroup');
+ expect(vc.root().operation()).toEqual('or');
+
+ expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
+ expect(vc.root().getOperand(0).operation()).toEqual('and');
+ });
+
+ it('should add on root (case "and")', function () {
+ var vc = vcClass.render(
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:eq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ }
+ );
+
+ expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
+ expect(vc.root().ldType()).toEqual('doc');
+ expect(vc.root().key()).toEqual('pubDate');
+ expect(vc.root().value()).toEqual('2014-12-05');
+
+ // Wrap on root
+ _andOn(vc.root());
+ expect(vc.root().ldType()).toEqual('docGroup');
+ expect(vc.root().operation()).toEqual('and');
+ });
+
+ it('should add on root (case "or")', function () {
+ var vc = vcClass.render(
+ {
+ "@type": 'koral:doc',
+ "key": 'pubDate',
+ "match": 'match:eq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ }
+ );
+
+ expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
+ expect(vc.root().key()).toEqual('pubDate');
+ expect(vc.root().value()).toEqual('2014-12-05');
+
+ // Wrap on root
+ _orOn(vc.root());
+ expect(vc.root().ldType()).toEqual('docGroup');
+ expect(vc.root().operation()).toEqual('or');
+ });
+
+ it('should support multiple sub groups per group', function () {
+ var vc = vcClass.render(
+ {
+ "@type": 'koral:docGroup',
+ 'operation' : 'operation:or',
+ 'operands' : [
+ {
+ "@type": 'koral:docGroup',
+ 'operation' : 'operation:and',
+ 'operands' : [
+ {
+ "@type": 'koral:doc',
+ "key": 'title',
+ "value": 't1',
+ },
+ {
+ "@type" : 'koral:doc',
+ 'key' : 'title',
+ 'value' : 't2'
+ }
+ ]
+ },
+ {
+ "@type": 'koral:docGroup',
+ 'operation' : 'operation:and',
+ 'operands' : [
+ {
+ "@type": 'koral:doc',
+ "key": 'title',
+ "value": 't3',
+ },
+ {
+ "@type" : 'koral:doc',
+ 'key' : 'title',
+ 'value' : 't4'
+ }
+ ]
+ }
+ ]
+ }
+ );
+ expect(vc.toQuery()).toEqual(
+ '(title = "t1" & title = "t2") | ' +
+ '(title = "t3" & title = "t4")'
+ );
+ expect(vc.root().operation()).toEqual('or');
+ expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
+ expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
+
+ _andOn(vc.root());
+
+ expect(vc.root().operation()).toEqual('and');
+ expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
+ expect(vc.root().getOperand(1).ldType()).toEqual('non');
+ });
+ });
+
+ describe('KorAP.Rewrite', function () {
+
+ it('should be initializable', function () {
+ var rewrite = rewriteClass.create({
+ "@type" : "koral:rewrite",
+ "operation" : "operation:modification",
+ "src" : "querySerializer",
+ "scope" : "tree"
});
+ expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
+ });
- expect(doc.element().classList.contains('doc')).toBeTruthy();
- expect(doc.element().classList.contains('rewritten')).toBeTruthy();
+ it('should be deserialized by docs', function () {
+ var doc = docClass.create(
+ undefined,
+ {
+ "@type":"koral:doc",
+ "key":"Titel",
+ "value":"Baum",
+ "match":"match:eq"
+ });
+
+ expect(doc.element().classList.contains('doc')).toBeTruthy();
+ expect(doc.element().classList.contains('rewritten')).toBe(false);
+
+ doc = docClass.create(
+ undefined,
+ {
+ "@type":"koral:doc",
+ "key":"Titel",
+ "value":"Baum",
+ "match":"match:eq",
+ "rewrites" : [
+ {
+ "@type" : "koral:rewrite",
+ "operation" : "operation:modification",
+ "src" : "querySerializer",
+ "scope" : "tree"
+ }
+ ]
+ });
+
+ expect(doc.element().classList.contains('doc')).toBeTruthy();
+ expect(doc.element().classList.contains('rewritten')).toBeTruthy();
+ });
+ /*
+ it('should be deserialized by docGroups', function () {
+ });
+ */
});
-/*
- it('should be deserialized by docGroups', function () {
- });
-*/
-});
-/*
-describe('KorAP.DocKey', function () {
- it('should be initializable', function () {
+ /*
+ describe('KorAP.DocKey', function () {
+ it('should be initializable', function () {
var docKey = KorAP.DocKey.create();
expect(docKey.toString()).toEqual('...');
- });
+ });
+ });
+ */
});
-*/
diff --git a/dev/js/src/match.js b/dev/js/src/match.js
index beb4bca..d3aee67 100644
--- a/dev/js/src/match.js
+++ b/dev/js/src/match.js
@@ -9,11 +9,9 @@
* - Scroll to match vertically per default
*/
define([
- 'match/infolayer',
'match/info',
'util'
-], function (infoLayerClass,
- infoClass) {
+], function (infoClass) {
// Localization values
var loc = KorAP.Locale;
@@ -21,8 +19,6 @@
loc.SHOWINFO = loc.SHOWINFO || 'Show information';
loc.CLOSE = loc.CLOSE || 'Close';
- // KorAP._AvailableRE = new RegExp("^([^\/]+?)\/([^=]+?)(?:=(spans|rels|tokens))?$");
- // KorAP._TermRE = new RegExp("^(?:([^\/]+?)\/)?([^:]+?):(.+?)$");
var _matchTerms = ['corpusID', 'docID', 'textID', 'matchID', 'available'];
/**
@@ -39,6 +35,7 @@
return Object.create(this)._init(match);
},
+
/**
* Initialize match.
*/
@@ -74,16 +71,11 @@
// Iterate over allowed match terms
for (var i in _matchTerms) {
var term = _matchTerms[i];
- if (match[term] !== undefined) {
- this[term] = match[term];
- }
- else {
- this[term] = undefined;
- }
+ this[term] = match[term] !== undefined ? match[term] : undefined;
};
};
- this._available = {
+ this._avail = {
tokens : [],
spans : [],
rels : []
@@ -95,8 +87,8 @@
// Create info layer objects
try {
- var layer = infoLayerClass.create(term);
- this._available[layer.type].push(layer);
+ var layer = require('match/infolayer').create(term);
+ this._avail[layer.type].push(layer);
}
catch (e) {
continue;
@@ -111,7 +103,7 @@
* Return a list of parseable tree annotations.
*/
getSpans : function () {
- return this._available.spans;
+ return this._avail.spans;
},
@@ -119,7 +111,7 @@
* Return a list of parseable token annotations.
*/
getTokens : function () {
- return this._available.tokens;
+ return this._avail.tokens;
},
@@ -127,9 +119,10 @@
* Return a list of parseable relation annotations.
*/
getRels : function () {
- return this._available.rels;
+ return this._avail.rels;
},
+
/**
* Open match
*/
@@ -149,13 +142,18 @@
// Add active class to element
element.classList.add('active');
+ // Already there
+ if (element.classList.contains('action'))
+ return true;
+
// Create action buttons
var ul = document.createElement('ul');
ul.classList.add('action', 'right');
- element.appendChild(ul);
- // Use localization
- var loc = KorAP.Locale;
+ element.appendChild(ul);
+ element.classList.add('action');
+
+ // Todo: Open in new frame
// Add close button
var close = document.createElement('li');
@@ -191,17 +189,16 @@
return true;
},
+
/**
* Close info view
*/
close : function () {
this._element.classList.remove('active');
-
-/*
- if (this._info !== undefined) {
- this._info.destroy();
- };
-*/
+ /* if (this._info !== undefined) {
+ * this._info.destroy();
+ * };
+ */
},
@@ -218,7 +215,7 @@
if (this._element === undefined ||
this._element === null)
return this._info;
-
+
// Info is already activated
if (this._info._element !== undefined)
return this._info;
@@ -226,14 +223,12 @@
return this._info;
},
-
+
/**
* Get match element.
*/
element : function () {
-
- // May be null
- return this._element;
+ return this._element; // May be null
}
};
});
diff --git a/dev/js/src/match/info.js b/dev/js/src/match/info.js
index b24bed5..c47f5ae 100644
--- a/dev/js/src/match/info.js
+++ b/dev/js/src/match/info.js
@@ -1,7 +1,16 @@
/**
* Information about a match.
*/
-define(['match/infolayer','match/table','match/tree', 'match/treemenu', 'util'], function (infoLayerClass, matchTableClass, matchTreeClass, matchTreeMenuClass) {
+define([
+ 'match/infolayer',
+ 'match/table',
+ 'match/tree',
+ 'match/treemenu',
+ 'util'
+], function (infoLayerClass,
+ matchTableClass,
+ matchTreeClass,
+ matchTreeMenuClass) {
// TODO: Make this async
KorAP.API.getMatchInfo = KorAP.API.getMatchInfo || function () {
diff --git a/dev/js/src/util.js b/dev/js/src/util.js
index d183c36..b3bb423 100644
--- a/dev/js/src/util.js
+++ b/dev/js/src/util.js
@@ -10,6 +10,11 @@
};
};
+var _quoteRE = new RegExp("([\"\\\\])", 'g');
+String.prototype.quote = function () {
+ return this.replace(_quoteRE, '\\$1');
+};
+
// Add toggleClass method similar to jquery
HTMLElement.prototype.toggleClass = function (c1, c2) {
var cl = this.classList;
diff --git a/dev/js/src/vc.js b/dev/js/src/vc.js
index 48c5694..65ac5ca 100644
--- a/dev/js/src/vc.js
+++ b/dev/js/src/vc.js
@@ -45,14 +45,6 @@
// KorAP._validGroupOpRE = new RegExp("^(?:and|or)$");
// KorAP._quote = new RegExp("([\"\\\\])", 'g');
- // Localization values
- var loc = (KorAP.Locale = KorAP.Locale || {} );
- /*
- loc.AND = loc.AND || 'and';
- loc.OR = loc.OR || 'or';
- loc.DEL = loc.DEL || '×';
- loc.EMPTY = loc.EMPTY || '⋯'
- */
/**
* Virtual Collection
@@ -93,7 +85,7 @@
else {
// Add unspecified object
- obj._root = KorAP.UnspecifiedDoc.create(obj);
+ obj._root = unspecDocClass.create(obj);
};
// Init element and update
diff --git a/dev/js/src/vc/doc.js b/dev/js/src/vc/doc.js
index 61c6439..700f410 100644
--- a/dev/js/src/vc/doc.js
+++ b/dev/js/src/vc/doc.js
@@ -133,7 +133,7 @@
// Wrap a new operation around the doc element
wrap : function (op) {
var parent = this.parent();
- var group = KorAP.DocGroup.create(parent);
+ var group = require('vc/docgroup').create(parent);
group.operation(op);
group.append(this);
group.append();
@@ -353,7 +353,7 @@
return string + '/' + this.value() + '/';
break;
case "string":
- return string + '"' + this.value().replace(KorAP._quote, '\\$1') + '"';
+ return string + '"' + this.value().quote() + '"';
break;
};
diff --git a/dev/js/src/vc/operators.js b/dev/js/src/vc/operators.js
index 312f75d..9b0ebd1 100644
--- a/dev/js/src/vc/operators.js
+++ b/dev/js/src/vc/operators.js
@@ -50,19 +50,19 @@
// Add doc with 'and' relation
- var _and = function () {
+ KorAP._and = function () {
return _add(this, 'and');
};
// Add doc with 'or' relation
- var _or = function () {
+ KorAP._or = function () {
return _add(this, 'or');
};
// Remove doc or docGroup
- var _delete = function () {
+ KorAP._delete = function () {
var ref = this.parentNode.refTo;
if (ref.parent().ldType() !== null) {
return ref.parent().delOperand(ref).update();
@@ -98,7 +98,7 @@
if (this._and === true) {
var andE = document.createElement('span');
andE.setAttribute('class', 'and');
- andE.addEventListener('click', _and, false);
+ andE.addEventListener('click', KorAP._and, false);
andE.appendChild(
document.createTextNode(loc.AND)
);
@@ -109,7 +109,7 @@
if (this._or === true) {
var orE = document.createElement('span');
orE.setAttribute('class', 'or');
- orE.addEventListener('click', _or, false);
+ orE.addEventListener('click', KorAP._or, false);
orE.appendChild(document.createTextNode(loc.OR));
op.appendChild(orE);
};
@@ -119,7 +119,7 @@
var delE = document.createElement('span');
delE.setAttribute('class', 'delete');
delE.appendChild(document.createTextNode(loc.DEL));
- delE.addEventListener('click', _delete, false);
+ delE.addEventListener('click', KorAP._delete, false);
op.appendChild(delE);
};
diff --git a/dev/js/src/vc/rewrite.js b/dev/js/src/vc/rewrite.js
index 79ba4b3..f0dfe34 100644
--- a/dev/js/src/vc/rewrite.js
+++ b/dev/js/src/vc/rewrite.js
@@ -4,7 +4,6 @@
define(['vc/jsonld', 'util'], function (jsonldClass) {
var _validRewriteOpRE = new RegExp("^(?:injec|modifica)tion$");
- var _quote = new RegExp("([\"\\\\])", 'g');
return {
// Construction method
@@ -87,12 +86,12 @@
this._scope === null ?
'object' :
'"' +
- this.scope().replace(_quote, '\\$1') +
+ this.scope().quote() +
'"'
);
str += ' by ' +
'"' +
- this.src().replace(_quote, '\\$1') +
+ this.src().quote() +
'"';
return str;
}