clean distclean all pz2api-git-checkout:
${MAKE} -C./tools/htdocs $@
+check-js:
+ ${MAKE} -C./test check
+
check: distclean all
help:
- @echo "make [ all | clean | pz2api-git-checkout ]"
+ @echo "make [ all | clean | pz2api-git-checkout | check-js ]"
--- /dev/null
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>MKWS demo: jQuery popup plugin with jasmine</title>
+
+ <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
+ <link rel="stylesheet" type="text/css" href="http://mkws.indexdata.com/mkwsStyle.css" />
+
+ <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
+ <script type="text/javascript" src="http://mkws.indexdata.com/libjs-pz2/pz2api.1.js"></script>
+ <script type="text/javascript" src="../../tools/htdocs/mkws.js"></script>
+ <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
+
+ <link rel="shortcut icon" type="image/png" href="../../../jasmine/lib/jasmine-1.3.1/jasmine_favicon.png">
+ <link rel="stylesheet" type="text/css" href="../../../jasmine/lib/jasmine-1.3.1/jasmine.css">
+ <script type="text/javascript" src="../../../jasmine/lib/jasmine-1.3.1/jasmine.js"></script>
+ <script type="text/javascript" src="../../../jasmine/lib/jasmine-1.3.1/jasmine-html.js"></script>
+
+ <script type="text/javascript" src="../../test/spec/true.spec.js"></script>
+ <script type="text/javascript" src="../../test/spec/mkws-config.js"></script>
+ <script type="text/javascript" src="../../test/spec/mkws-pazpar2.js"></script>
+
+ <script type="text/javascript" src="../../test/js/mkws-jasmine-run.js"></script>
+ <script type="text/javascript"> mkws_jasmine_init(500); </script>
+ </head>
+
+ <body>
+ <script type="text/javascript">
+ jQuery.pazpar2({
+ "layout": "popup", /* "table" [default], "div", "popup" */
+ "id_button": "input#mkwsButton", /* submit button id in search field */
+ "id_popup": "#mkwsPopup", /* internal id of popup window */
+ "width": 880, /* popup width, should be at least 800 */
+ "height": 760 /* popup height, should be at least 600 */
+ });
+ </script>
+
+ <pre>
+An embryonic MasterKey Widget Set
+=================================
+
+This directory contains an embryonic MasterKey Widget Set, based
+initially on "jsdemo" though now far removed from those beginnnings.
+[...]
+ </pre>
+ </body>
+</html>
--- /dev/null
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>MKWS demo: Wolfram's playground</title>
+ <link rel="stylesheet" type="text/css" href="../../tools/htdocs/mkwsStyle.css" />
+ <script type="text/javascript">
+ var mkws_config = {
+ /*
+ service_proxy_url : "/service-proxy/",
+ service_proxy_auth : "/service-proxy-auth/",
+ */
+ };
+ </script>
+ <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
+ <script type="text/javascript" src="http://mkws.indexdata.com/libjs-pz2/pz2api.1.js"></script>
+ <script type="text/javascript" src="../../tools/htdocs/mkws.js"></script>
+ <style type="text/css">
+ #mkwsTermlists div.facet {
+ float:left;
+ width: 30%;
+ margin: 0.3em;
+ }
+ #mkwsStat {
+ text-align: right;
+ }
+ </style>
+
+ <!-- SECTION jasmine -->
+ <link rel="shortcut icon" type="image/png" href="../../../jasmine/lib/jasmine-1.3.1/jasmine_favicon.png">
+ <link rel="stylesheet" type="text/css" href="../../../jasmine/lib/jasmine-1.3.1/jasmine.css">
+ <script type="text/javascript" src="../../../jasmine/lib/jasmine-1.3.1/jasmine.js"></script>
+ <script type="text/javascript" src="../../../jasmine/lib/jasmine-1.3.1/jasmine-html.js"></script>
+
+ <!-- include MKWS spec files ... -->
+ <script type="text/javascript" src="../../test/spec/true.spec.js"></script>
+ <script type="text/javascript" src="../../test/spec/mkws-config.js"></script>
+ <script type="text/javascript" src="../../test/spec/mkws-pazpar2.js"></script>
+
+ <!-- init and run jasmine -->
+ <script type="text/javascript" src="../../test/js/mkws-jasmine-run.js"></script>
+ <script type="text/javascript">
+ mkws_jasmine_init(500);
+ </script>
+ <!-- EOF jasmine -->
+
+ </head>
+ <body>
+ <table width="100%" border="0">
+ <tr>
+ <td>
+ <div id="mkwsSwitch"></div>
+ <div id="mkwsLang"></div>
+ <div id="mkwsSearch"></div>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <div style="height:500px; overflow: auto">
+ <div id="mkwsPager"></div>
+ <div id="mkwsNavi"></div>
+ <div id="mkwsRecords"></div>
+ <div id="mkwsTargets"></div>
+ <div id="mkwsRanking"></div>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <div style="height:300px; overflow: hidden">
+ <div id="mkwsTermlists"></div>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <div id="mkwsStat"></div>
+ </td>
+ </tr>
+ </table>
+
+ </body>
+</html>
+<?xml version="1.0"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MKWS demo: Wolfram's playground</title>
- <link rel="stylesheet" type="text/css" href="mkwsStyle.css" />
+ <link rel="stylesheet" type="text/css" href="../../tools/htdocs/mkwsStyle.css" />
<script type="text/javascript">
var mkws_config = {
+ /*
service_proxy_url : "/service-proxy/",
service_proxy_auth : "/service-proxy-auth/",
- language_Arabic: {
- "Authors": "الكتاب",
- "Subjects": "المواضيع",
- "Sources": "مصادر",
- "Termlists": "العضو الأجل",
- "Next": "التالي",
- "Prev": "السابق",
- "Search": "بحث",
- "Sort by": "الترتيب حسب",
- "and show": "وعرض",
- "per page": "في كل صفحة",
- "Displaying": "عرض",
- "to": "إلى",
- "of": "من",
- "found": "أسس",
- "Title": "لقب",
- "Author": "الكاتب",
- "Date": "تاريخ",
- "Subject": "موضوع",
- "Location": "موقع",
- "Records": "أهداف",
- "Targets": "السجلات"
- }
+ */
};
</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
- <script type="text/javascript" src="libjs-pz2/pz2api.1.js"></script>
- <script type="text/javascript" src="mkws.js"></script>
+ <script type="text/javascript" src="http://mkws.indexdata.com/libjs-pz2/pz2api.1.js"></script>
+ <script type="text/javascript" src="../../tools/htdocs/mkws.js"></script>
<style type="text/css">
#mkwsTermlists div.facet {
float:left;
<table width="100%" border="0">
<tr>
<td>
+ <div id="mkwsSwitch"></div>
<div id="mkwsLang"></div>
<div id="mkwsSearch"></div>
</td>
--- /dev/null
+# Copyright (c) 2013 IndexData ApS. http://indexdata.com
+
+all: check
+
+clean:
+
+distclean:
+ rm -rf node_modules
+
+
+check:
+ jasmine-node ./spec
+
+test: check
+
+jsbeautifier jsb indent:
+ for i in ./spec/*.js ./js/*.js; do \
+ jsbeautifier -j $$i > $@.tmp && mv -f $@.tmp $$i; \
+ done
+
+node-modules: node_modules
+node_modules:
+ npm install jquery jsdom request jasmine-node
+
+help:
+ @echo "make [ all | clean | check | jsbeautifier | node-modules ]"
--- /dev/null
+Jasmine / jasmine-node test frame works
+---------------------------------------
+
+This directory contains the MasterKey Widget Set (MKWS) Test framework.
+
+
+to run the tests, run:
+
+$ make check
+jasmine-node ./spec
+.......................................
+
+Finished in 2.024 seconds
+39 tests, 194 assertions, 0 failures, 0 skipped
+
+
+To get a basic help, run:
+$ make help
+
+
+File system hierarchy
+--------------------------------------
+./spec contains *spec.js files
+./js jasmine runtime JS lib
+
+README.txt this file
+
+
+Documentation
+---------------------------------------
+http://pivotal.github.io/jasmine/
+https://github.com/pivotal/jasmine
+
+
+Installation
+-------------------------------------
+1. install node.js, see http://nodejs.org/
+2. install node modules with npm: make node-modules
+
+--
+Copyright (c) 2013 IndexData ApS. http://indexdata.com
+Sep 2013, Wolfram
--- /dev/null
+/*
+ * init and run jasmine
+ *
+ * a given delay starts the test N miliseconds later
+ */
+
+function mkws_jasmine_init(delay) {
+ var currentWindowOnload = window.onload;
+
+ window.onload = function () {
+ if (currentWindowOnload) {
+ currentWindowOnload();
+ }
+ if (delay) {
+ setTimeout(function () {
+ execJasmine()
+ }, delay);
+ } else {
+ execJasmine();
+ }
+ };
+
+ function execJasmine() {
+
+ var jasmineEnv = jasmine.getEnv();
+ jasmineEnv.updateInterval = 1000;
+ var htmlReporter = new jasmine.HtmlReporter();
+ jasmineEnv.addReporter(htmlReporter);
+
+ jasmineEnv.specFilter = function (spec) {
+ return htmlReporter.specFilter(spec);
+ };
+
+ jasmineEnv.execute();
+ }
+};
+
+/* EOF */
--- /dev/null
+/* Copyright (c) 2013 IndexData ApS. http://indexdata.com
+ *
+ * async check
+ *
+ */
+describe("Asynchronous check", function () {
+ it("contains spec with an expectation", function () {
+ expect(true).toBe(true);
+ });
+
+ // Asynchronous part
+ it("simple check", function () {
+ var max_time = 1;
+ var timer = 0;
+
+ function found(time, none) {
+ setTimeout(function () {
+ timer = time;
+ }, time * 1000);
+ expect(time >= 0).toBeTruthy();
+ }
+
+ runs(function () {
+ // check hit counter after N seconds
+ found(0, true);
+ found(0.2);
+ found(0.4);
+ found(0.5);
+ found(0.7);
+ found(max_time);
+ });
+
+ waitsFor(function () {
+ // console.log("waits for ... " + timer);
+ return timer == max_time ? true : false;
+ }, "The Value should be N seconds", max_time * 1000);
+
+ runs(function () {
+ expect(timer).toEqual(max_time);
+ });
+ });
+
+
+ it("double async check", function () {
+ var max_time = 0.5;
+ var timer = 0;
+
+ function found(time, none) {
+ setTimeout(function () {
+ timer = time;
+ }, time * 1000);
+ expect(time >= 0).toBeTruthy();
+ }
+
+ runs(function () {
+ found(0);
+ found(0.2);
+ found(max_time - 0.1);
+ });
+
+ waitsFor(function () {
+ return timer == max_time - 0.1 ? true : false;
+ }, "The Value should be N seconds", max_time * 1000);
+
+ runs(function () {
+ expect(timer <= max_time).toBeTruthy();
+ });
+
+ timer = 0;
+ runs(function () {
+ found(0.1);
+ found(max_time);
+ });
+
+ waitsFor(function () {
+ // console.log("waits for ... " + timer);
+ return timer == max_time ? true : false;
+ }, "The Value should be N seconds", max_time * 1000);
+
+ runs(function () {
+ expect(timer <= max_time).toBeTruthy();
+ });
+ });
+
+});
--- /dev/null
+/* Copyright (c) 2013 IndexData ApS. http://indexdata.com
+ *
+ * jQuery test
+ *
+ */
+
+describe("jQuery suite simple", function () {
+ var $ = require('jquery');
+
+ it("jQuery append test", function () {
+ $("body").append("<h1>test passes h1</h1>");
+ expect($("body").html()).toMatch(/<h1>/);
+ $("<p>this is a paragraph</p>").appendTo("h1");
+ expect($("body").html()).toMatch(/this is a paragraph/);
+ });
+
+ it("$ append test", function () {
+ $("<h2>test passes h2</h2>").appendTo("body");
+ expect($("body").html()).toMatch(/<h2>/);
+
+ $("<p>this is a second paragraph</p>").appendTo("h1");
+ expect($("body").html()).toMatch(/this is a paragraph/);
+ });
+
+ it("more jquery tests", function () {
+ // other tests
+ expect($("h2").html()).toMatch(/test passes h2/);
+ expect($("h1").html()).toMatch(/test passes h1/);
+ expect($("h1").html()).not.toMatch(/^$/);
+ expect($("h1").html()).not.toMatch(/foobar/);
+ });
+});
--- /dev/null
+/* Copyright (c) 2013 IndexData ApS. http://indexdata.com
+ *
+ * jQuery test with DOM/windows object
+ *
+ */
+
+describe("jQuery suite", function () {
+ var jsdom = require('jsdom').jsdom;
+ var myWindow = jsdom().createWindow();
+
+ var $ = require('jquery');
+ var jq = require('jquery').create();
+ var jQuery = require('jquery').create(myWindow);
+
+ it("jQuery append test", function () {
+ jQuery("<h1>test passes h1</h1>").appendTo("body");
+ expect(jQuery("body").html()).toMatch(/<h1>/);
+ });
+
+ it("$ append test", function () {
+ $("<h2>test passes h2</h2>").appendTo("body");
+ expect($("body").html()).toMatch(/<h2>/);
+ });
+
+ it("jq append test", function () {
+ jq("<h2>test passes h2</h2>").appendTo("body");
+ expect(jq("body").html()).toMatch(/<h2>/);
+ });
+
+ it("window test", function () {
+ expect(myWindow).toBeDefined();
+ });
+});
--- /dev/null
+/* Copyright (c) 2013 IndexData ApS. http://indexdata.com
+ *
+ * check mkws_config = {} object in browser
+ *
+ */
+
+describe("Check mkws_config object", function () {
+ it("mkws_config exists", function () {
+ expect(mkws_config).not.toBe(undefined);
+ });
+
+ it("mkws_config service proxy config", function () {
+ expect(mkws_config.service_proxy_url).toBe(undefined);
+ });
+
+ it("mkws_config locale check German", function () {
+ expect(mkws.locale_lang.de.Authors).toMatch(/^Autoren$/);
+ expect(mkws.locale_lang.de.Location).toMatch(/^Ort$/);
+ });
+ it("mkws_config locale check Danish", function () {
+ expect(mkws.locale_lang.da.Authors).toMatch(/^Forfattere$/);
+ expect(mkws.locale_lang.da.Location).toMatch(/^Lokation$/);
+ });
+
+ it("mkws_config service proxy enabled", function () {
+ expect(mkws_config.use_service_proxy).toBe(true);
+ });
+
+});
+
+
+describe("Check pazpar2 config", function () {
+ it("pazpar2path is a path or an full URL", function () {
+ expect(mkws.pazpar2path).toMatch(/^(\/|http:\/\/)/)
+ });
+
+ it("usesessions false", function () {
+ expect(mkws.usesessions).toBe(false);
+ });
+
+ it("my_paz is defined", function () {
+ expect(mkws.my_paz).not.toBe(undefined);
+ });
+});
+
+describe("Check pazpar2 runtime", function () {
+ it("pazpar2 was successfully initialize", function () {
+ expect(mkws_config.error).toBe(undefined);
+ });
+});
--- /dev/null
+/* Copyright (c) 2013 IndexData ApS. http://indexdata.com
+ *
+ * jQuery test with DOM/windows object
+ *
+ */
+
+
+var fs = require("fs");
+var utils = require("./mkws_utils.js");
+
+/*
+ * parse HTML data to DOM, and run jQuery request on it
+ *
+ */
+
+function jsdom_check(file, tags_array, ignore_doctype) {
+ var html = fs.readFileSync(file, "utf-8");
+ var tags = utils.flat_list(tags_array);
+
+ describe("index-full.html jsdom + jquery for " + file, function () {
+ var window = require('jsdom').jsdom(html, null, {
+ FetchExternalResources: false,
+ ProcessExternalResources: false,
+ MutationEvents: false,
+ QuerySelector: false
+ }).createWindow();
+
+ /* apply jquery to the window */
+ var $ = require('jquery').create(window);
+
+
+ it("html jquery test", function () {
+ expect(html).toBeDefined();
+
+ expect($("body").length == 0).toEqual(false);
+ expect($("body").length == 1).toEqual(true);
+ expect($("head").length == 1).toEqual(true);
+
+ for (var i = 0; i < tags.length; i++) {
+ expect($("#" + tags[i]).length == 1).toEqual(true);
+ }
+ });
+
+ it("html jquery fail test", function () {
+ expect(html).toBeDefined();
+
+ expect($("body_does_not_exists").length == 1).toEqual(false);
+ expect($("#body_does_not_exists").length == 1).toEqual(false);
+ });
+ });
+}
+
+/*
+jsdom_check('../examples/htdocs/index-full.html', [utils.tags.required, utils.tags.optional, utils.tags.optional2]);
+jsdom_check('../examples/htdocs/index-mobile.html', [utils.tags.required, utils.tags.optional]);
+jsdom_check('../examples/htdocs/index-popup.html', [], true);
+jsdom_check('../examples/htdocs/index-jquery.html', []);
+jsdom_check('../examples/htdocs/index-mike.html', [utils.tags.required, utils.tags.optional], true);
+*/
--- /dev/null
+/* Copyright (c) 2013 IndexData ApS. http://indexdata.com
+ *
+ * jQuery test with DOM/windows object
+ *
+ */
+
+
+var fs = require("fs");
+var utils = require("./mkws_utils.js");
+
+/*
+ * parse HTML data to DOM, and run jQuery request on it
+ *
+ */
+
+function jsdom_check(file, tags_array, ignore_doctype) {
+ var html = fs.readFileSync(file, "utf-8");
+ var tags = utils.flat_list(tags_array);
+
+ describe("index-full.html jsdom + jquery for " + file, function () {
+ var window = require('jsdom').jsdom(html, null, {
+ FetchExternalResources: false,
+ ProcessExternalResources: false,
+ MutationEvents: false,
+ QuerySelector: false
+ }).createWindow();
+
+ /* apply jquery to the window */
+ var $ = require('jquery').create(window);
+
+
+ it("html jquery test", function () {
+ expect(html).toBeDefined();
+
+ expect($("body").length == 0).toEqual(false);
+ expect($("body").length == 1).toEqual(true);
+ expect($("head").length == 1).toEqual(true);
+
+ for (var i = 0; i < tags.length; i++) {
+ expect($("#" + tags[i]).length == 1).toEqual(true);
+ }
+ });
+
+ it("html jquery fail test", function () {
+ expect(html).toBeDefined();
+
+ expect($("body_does_not_exists").length == 1).toEqual(false);
+ expect($("#body_does_not_exists").length == 1).toEqual(false);
+ });
+ });
+}
+
+jsdom_check('../examples/htdocs/index-full.html', [utils.tags.required, utils.tags.optional, utils.tags.optional2]);
+jsdom_check('../examples/htdocs/index-mobile.html', [utils.tags.required, utils.tags.optional]);
+jsdom_check('../examples/htdocs/index-popup.html', [], true);
+jsdom_check('../examples/htdocs/index-jquery.html', []);
+jsdom_check('../examples/htdocs/index-mike.html', [utils.tags.required, utils.tags.optional], true);
--- /dev/null
+/* Copyright (c) 2013 IndexData ApS. http://indexdata.com
+ *
+ * jQuery test with DOM/windows object
+ *
+ */
+
+
+var fs = require("fs");
+var utils = require("./mkws_utils.js");
+
+/*
+ * simple test with string matching of the HTML page
+ *
+ */
+
+function html_check(file, tags_array, ignore_doctype) {
+ var html = fs.readFileSync(file, "utf-8");
+ var tags = utils.flat_list(tags_array);
+
+ describe("index-full.html string test for " + file, function () {
+ it("html test", function () {
+ expect(html).toBeDefined();
+
+ // forgotten doctype declaration
+ if (!ignore_doctype) {
+ expect(html).toMatch(/<html.*?>/);
+ expect(html).toMatch(/<\/html.*?>/);
+ }
+ expect(html).toMatch(/<head.*?>/);
+ expect(html).toMatch(/<body.*?>/);
+ expect(html).toMatch(/<\/head.*?>/);
+ expect(html).toMatch(/<\/body.*?>/);
+
+ expect(html).toMatch(/<meta .*?charset=utf-8/i);
+ expect(html).toMatch(/<title>.+<\/title>/i);
+ expect(html).toMatch(/<link .*?type="text\/css" href=".*?\/?mkwsStyle.css"/);
+
+
+ for (var i = 0, data = ""; i < tags.length; i++) {
+ data = '<div id="' + tags[i] + '">';
+ // console.log(data)
+ expect(html).toMatch(data);
+ }
+ });
+ });
+}
+
+html_check('../examples/htdocs/index-full.html', [utils.tags.required, utils.tags.optional, utils.tags.optional2]);
+html_check('../examples/htdocs/index-mobile.html', [utils.tags.required, utils.tags.optional]);
+html_check('../examples/htdocs/index-popup.html', [], true);
+html_check('../examples/htdocs/index-jquery.html', []);
+html_check('../examples/htdocs/index-mike.html', [utils.tags.required, utils.tags.optional], true);
--- /dev/null
+/* Copyright (c) 2013 IndexData ApS. http://indexdata.com
+ *
+ * perform papzpar2 / pz2.js search & retrieve request in the browser
+ *
+ */
+
+var debug = mkws.debug;
+
+var get_hit_counter = function () {
+ // not yet here
+ if ($("#mkwsPager").length == 0) return -1;
+
+ var found = $("#mkwsPager").text();
+ var re = /\([A-Za-z]+:\s+([0-9]+)\)/;
+ re.exec(found);
+ var hits = -1;
+
+ if (RegExp.$1) {
+ hits = parseInt(RegExp.$1);
+ expect(hits).toBeGreaterThan(0);
+ }
+
+ //debug("Hits: " + hits);
+ return hits;
+ }
+
+describe("Check pazpar2 search", function () {
+ it("pazpar2 was successfully initialize", function () {
+ expect(mkws_config.error).toBe(undefined);
+ });
+
+ it("validate HTML id's", function () {
+ expect($("input#mkwsQuery").length).toBe(1);
+ expect($("input#mkwsButton").length).toBe(1);
+
+ expect($("#mkwsNext").length).not.toBe(1);
+ expect($("#mkwsPrev").length).not.toBe(1);
+ });
+
+ it("run search query", function () {
+ var search_query = "freebsd"; // short hit counter with some paging
+ $("input#mkwsQuery").val(search_query);
+ debug("set search query: " + search_query)
+ expect($("input#mkwsQuery").val()).toMatch("^" + search_query + "$");
+
+ // wait for service proxy auth
+ waitsFor(function () {
+ return mkws.service_proxy_auth;
+ }, "SP auth done", 10 * 1000);
+
+ runs(function () {
+ debug("Click on submit button");
+ var click = $("input#mkwsButton").trigger("click");
+ expect(click.length).toBe(1);
+ })
+ });
+});
+
+
+/*
+ * This part runs in background. It should be rewritten with
+ * async jasmine functions
+ *
+ */
+describe("Check pazpar2 navigation", function () {
+ // Asynchronous part
+ it("check running search next/prev", function () {
+ expect($("#mkwsPager").length).toBe(1);
+
+ function my_click(id, time) {
+ setTimeout(function () {
+ debug("trigger click on id: " + id);
+ var click = $(id).trigger("click");
+
+ debug("next/prev: " + id + " click is success: " + click.length);
+ expect(click.length).toBe(1);
+ }, time * 1000);
+ }
+
+ waitsFor(function () {
+ return $("div#mkwsPager div:nth-child(2) a").length >= 2 ? true : false;
+ }, "Expect next link 2", 10 * 1000);
+
+ runs(function () {
+ // click next/prev after N seconds
+ my_click("#mkwsNext", 0);
+ });
+
+ waitsFor(function () {
+ return $("div#mkwsPager div:nth-child(2) a").length >= 3 ? true : false;
+ }, "Expect next link 3", 5 * 1000);
+
+ runs(function () {
+ // click next/prev after N seconds
+ my_click("#mkwsNext", 0);
+ my_click("#mkwsPrev", 0.2);
+ });
+ });
+});
+
+describe("Check pazpar2 hit counter", function () {
+ it("check running search hit counter", function () {
+ var max_time = 16; // in seconds
+ var expected_hits = 80; // at least expected hit counter
+ var hits = 0;
+
+ waitsFor(function () {
+ hits = get_hit_counter();
+
+ return hits > expected_hits;
+ }, "Expect " + expected_hits + " hits", max_time * 1000);
+
+
+ runs(function () {
+ debug("mkws pager found records: '" + hits + "'");
+ expect($("#mkwsPager").length).toBe(1);
+ expect(hits).toBeGreaterThan(expected_hits);
+ });
+ });
+});
+
+describe("Check Termlist", function () {
+ it("found Termlist", function () {
+ var termlist = $("div#mkwsTermlists");
+ debug("Termlist success: " + termlist.length);
+ expect(termlist.length).toBe(1);
+
+ waitsFor(function () {
+ return $("div#mkwsFacetSources").length == 1 ? true : false;
+ }, "check for facet sources", 2 * 1000);
+
+
+ // everything displayed?
+ runs(function () {
+ var sources = $("div#mkwsFacetSources");
+ debug("Termlist sources success: " + sources.length);
+ expect(sources.length).toBe(1);
+
+ var subjects = $("div#mkwsFacetSubjects");
+ expect(subjects.length).toBe(1);
+
+ var authors = $("div#mkwsFacetAuthors");
+ expect(authors.length).toBe(1);
+ });
+
+ waitsFor(function () {
+ return $("div#mkwsFacetAuthors div.term").length >= 2 ? true : false;
+ }, "At least one author link displayed", 2 * 1000);
+
+ runs(function () {
+ expect($("div#mkwsFacetAuthors div.term").length).toBeGreaterThan(1);
+ });
+ });
+
+ it("limit search to first author", function () {
+ var hits_all_targets = get_hit_counter();
+
+ var click = $("div#mkwsFacetAuthors div.term:nth-child(2) a").trigger("click");
+ debug("limit author click is success: " + click.length);
+ expect(click.length).toBe(1);
+
+ waitsFor(function () {
+ return get_hit_counter() < hits_all_targets ? true : false;
+ }, "Limited author search for less than " + hits_all_targets + " hits", 8 * 1000);
+
+ runs(function () {
+ var hits_single_target = get_hit_counter();
+ debug("get less hits for authors: " + hits_all_targets + " > " + hits_single_target);
+ expect(hits_all_targets).toBeGreaterThan(hits_single_target);
+ });
+ });
+
+ it("limit search to first source", function () {
+ var hits_all_targets = get_hit_counter();
+ var source_number = 2; // 2=first source
+ var source_name = $("div#mkwsFacetSources div.term:nth-child(" + source_number + ") a").text();
+ // do not click on wikipedia link - no author or subject facets possible
+ if (source_name.match(/wikipedia/i)) {
+ source_number++;
+ }
+
+ var click = $("div#mkwsFacetSources div.term:nth-child(" + source_number + ") a").trigger("click");
+ debug("limit source click " + (source_number - 1) + " is success: " + click.length);
+ expect(click.length).toBe(1);
+
+ waitsFor(function () {
+ if ($("div#mkwsNavi").length && $("div#mkwsNavi").text().match(/^Source/)) {
+ return true;
+ } else {
+ return false;
+ }
+ }, "Search for source in navi bar", 1000);
+
+ waitsFor(function () {
+ return get_hit_counter() < hits_all_targets ? true : false;
+ }, "Limited source earch for less than " + hits_all_targets + " hits", 9 * 1000);
+
+ runs(function () {
+ var hits_single_target = get_hit_counter();
+ debug("get less hits for sources: " + hits_all_targets + " > " + hits_single_target);
+ expect(hits_all_targets).toBeGreaterThan(hits_single_target);
+ });
+ });
+});
+
+describe("Show record", function () {
+ var record_number = 1; // the Nth record in hit list
+ it("show record author", function () {
+ var click = $("div#mkwsRecords div.record:nth-child(" + record_number + ") :nth-child(2)").trigger("click");
+ debug("show click is success: " + click.length);
+ expect(click.length).toBe(1);
+
+ // wait until the record pops up
+ waitsFor(function () {
+ var show = $("div#mkwsRecords div.record:nth-child(" + record_number + ") div");
+ return show != null && show.length ? true : false;
+ }, "wait some miliseconds to show up a record", 2 * 1000);
+
+ runs(function () {
+ debug("show record pop up");
+ expect($("div#mkwsRecords div.record:nth-child(" + record_number + ") div")).not.toBe(null);
+ });
+ });
+
+ it("extract URL", function () {
+ var url = $("div#mkwsRecords div.record:nth-child(" + record_number + ") div table tbody tr td a").text();
+ debug("extracted URL from record: " + url);
+
+ expect(url).not.toBe(null);
+ expect(url).toMatch(/^http:\/\/[a-z0-9]+\.[0-9a-z].*\//i);
+ });
+});
+
+describe("Check switch menu Records/Targets", function () {
+ it("check mkwsSwitch", function () {
+ expect($("div#mkwsSwitch").length).toBe(1);
+
+ // expect 2 clickable links
+ expect($("div#mkwsSwitch a").length).toBe(2);
+ });
+
+ it("switch to target view", function () {
+ var click = $("a#mkwsSwitch_targets").trigger("click");
+ debug("target click is success: " + click.length);
+ expect(click.length).toBe(1);
+
+ // now the target table must be visible
+ expect($("div#mkwsBytarget").is(":visible")).toBe(true);
+ expect($("div#mkwsRecords").is(":visible")).toBe(false);
+
+ // wait a half second, to show the target view
+ var time = (new Date).getTime();
+ waitsFor(function () {
+ return (new Date).getTime() - time > 700 ? true : false;
+ }, "wait some miliseconds", 1 * 1000);
+
+ // look for table header
+ runs(function () {
+ expect($("div#mkwsBytarget").html()).toMatch(/Target ID/);
+ });
+ });
+
+ it("switch back to record view", function () {
+ var click = $("a#mkwsSwitch_records").trigger("click");
+ debug("record click is success: " + click.length);
+ expect(click.length).toBe(1);
+
+ // now the target table must be visible
+ expect($("div#mkwsBytarget").is(":visible")).toBe(false);
+ expect($("div#mkwsRecords").is(":visible")).toBe(true);
+ });
+});
+
+describe("Check status client counter", function () {
+ function get_time() {
+ var date = new Date();
+ return date.getTime();
+ }
+ var time = get_time();
+
+ it("check status clients", function () {
+ waitsFor(function () {
+ var clients = $("div#mkwsStat span.clients");
+ if (clients.length == 1 && clients.text() == "0/1") {
+ return true;
+ } else {
+ return false;
+ }
+
+ }, "wait for status", 4 * 1000);
+
+ runs(function () {
+ var clients = $("div#mkwsStat span.clients");
+ debug("span.clients: " + clients.text());
+ expect(clients.text()).toEqual("0/1");
+ });
+
+ });
+
+});
+
+/* dummy EOF */
+describe("All tests are done", function () {
+ it(">>> hooray <<<", function () {});
+});
--- /dev/null
+/* Copyright (c) 2013 IndexData ApS. http://indexdata.com
+ *
+ * helper functions for other test *.spec.js files
+ *
+ */
+
+/*
+ * combine arrays, return a flat list
+ * [["a","b"], ["c"], "d"] => ["a", "b", "c", "d"]
+ *
+ */
+var flat_list = function (list) {
+ var data = [];
+
+ for (var i = 0; i < list.length; i++) {
+ if (typeof list[i] == 'object') {
+ for (var j = 0; j < list[i].length; j++) {
+ data.push(list[i][j]);
+ }
+
+ } else {
+ data.push(list[i]);
+ }
+ }
+
+ return data;
+ };
+
+/*
+ * list of div id to check
+ *
+ */
+var tags = {
+ required: ["mkwsSearch", "mkwsResults"],
+ optional: ["mkwsLang", "mkwsTargets"],
+ optional2: ["mkwsMOTD", "mkwsStat", "footer"]
+};
+
+// node.js exports
+module.exports = {
+ flat_list: flat_list,
+ tags: tags
+};
--- /dev/null
+/* Copyright (c) 2013 IndexData ApS. http://indexdata.com
+ *
+ * jQuery sample from system documentation
+ *
+ */
+
+describe('jasmine-node', function () {
+
+ it('should pass', function () {
+ expect(1 + 2).toEqual(3);
+ });
+
+ it('shows asynchronous test', function () {
+ setTimeout(function () {
+ expect('second').toEqual('second');
+ asyncSpecDone();
+ }, 1);
+ expect('first').toEqual('first');
+ asyncSpecWait();
+ });
+
+ it('shows asynchronous test node-style', function (done) {
+ setTimeout(function () {
+ expect('second').toEqual('second');
+ // If you call done() with an argument, it will fail the spec
+ // so you can use it as a handler for many async node calls
+ done();
+ }, 1);
+ expect('first').toEqual('first');
+ });
+});
--- /dev/null
+/* Copyright (c) 2013 IndexData ApS. http://indexdata.com
+ *
+ * dummy test
+ *
+ */
+describe("A suite", function () {
+ it("contains spec with an expectation", function () {
+ expect(true).toBe(true);
+ });
+});
"use strict"; // HTML5: disable for debug >= 2
+// Set up namespace and some state.
+var mkws = {};
+
+if (!mkws_config)
+ var mkws_config = {}; // for the guys who forgot to define mkws_config...
+
+// Wrapper for jQuery
+(function ($) {
+
/*
* global config object: mkws_config
*
* including this JS file
*/
-if (!mkws_config)
- var mkws_config = {}; // for the guys who forgot to define mkws_config...
-
if (typeof mkws_config.use_service_proxy === 'undefined')
mkws_config.use_service_proxy = true;
-// global debug flag
-var mkws_debug;
-
var pazpar2_url = mkws_config.pazpar2_url ? mkws_config.pazpar2_url : "/pazpar2/search.pz2";
var service_proxy_url = mkws_config.service_proxy_url ? mkws_config.service_proxy_url : "http://mkws.indexdata.com/service-proxy/";
-var pazpar2path = mkws_config.use_service_proxy ? service_proxy_url : pazpar2_url;
-var usesessions = mkws_config.use_service_proxy ? false : true;
-
+mkws.pazpar2path = mkws_config.use_service_proxy ? service_proxy_url : pazpar2_url;
+mkws.usesessions = mkws_config.use_service_proxy ? false : true;
-var mkws_locale_lang = {
+mkws.locale_lang = {
"de": {
"Authors": "Autoren",
"Subjects": "Schlagwörter",
}
};
+// keep time state for debugging
+mkws.debug_time = {
+ "start": $.now(),
+ "last": $.now()
+};
+mkws.debug = function (string) {
+ if (!mkws.debug)
+ return;
+
+ if (typeof console === "undefined" || typeof console.log === "undefined") { /* ARGH!!! old IE */
+ return;
+ }
+
+ var now = $.now();
+ var timestamp = (now - mkws.debug_time.start)/1000 + " (+" + (now - mkws.debug_time.last)/1000 + ") "
+ mkws.debug_time.last = now;
+
+ // you need to disable use strict at the top of the file!!!
+ if (mkws.debug >= 3) {
+ console.log(timestamp + arguments.callee.caller);
+ } else if (mkws.debug >= 2) {
+ console.log(timestamp + ">>> called from function " + arguments.callee.caller.name + ' <<<');
+ }
+ console.log(timestamp + string);
+}
+var debug = mkws.debug; // local alias
for (var key in mkws_config) {
if (mkws_config.hasOwnProperty(key)) {
if (key.match(/^language_/)) {
var lang = key.replace(/^language_/, "");
// Copy custom languages into list
- mkws_locale_lang[lang] = mkws_config[key];
+ mkws.locale_lang[lang] = mkws_config[key];
}
}
}
// autoInit is set to true on default
var my_paz = new pz2( { "onshow": my_onshow,
"showtime": 500, //each timer (show, stat, term, bytarget) can be specified this way
- "pazpar2path": pazpar2path,
+ "pazpar2path": mkws.pazpar2path,
"oninit": my_oninit,
"onstat": my_onstat,
"onterm": my_onterm,
"termlist": "xtargets,subject,author",
"onbytarget": my_onbytarget,
- "usesessions" : usesessions,
+ "usesessions" : mkws.usesessions,
"showResponseType": '', // or "json" (for debugging?)
"onrecord": my_onrecord } );
+
+mkws.my_paz = my_paz; // export
+
// some state vars
var curPage = 1;
var recPerPage = 20;
html.push('<div class="record" id="mkwsRecdiv_'+hit.recid+'" >'
+'<span>'+ (i + 1 + recPerPage * (curPage - 1)) +'. </span>'
+'<a href="#" id="mkwsRec_'+hit.recid
- +'" onclick="showDetails(this.id);return false;"><b>'
+ +'" onclick="mkws.showDetails(this.id);return false;"><b>'
+ hit["md-title"] +' </b></a>');
if (hit["md-title-remainder"] !== undefined) {
html.push('<span>' + hit["md-title-remainder"] + ' </span>');
if (!cclIndex) {
// Special case: target selection
acc.push('target_id='+data[i].id+' ');
- action = 'limitTarget(this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
+ action = 'mkws.limitTarget(this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
} else {
- action = 'limitQuery(\'' + cclIndex + '\', this.firstChild.nodeValue)';
+ action = 'mkws.limitQuery(\'' + cclIndex + '\', this.firstChild.nodeValue)';
}
acc.push('onclick="' + action + ';return false;">' + data[i].name + '</a>'
+ ' <span>' + data[i].freq + '</span>');
resetPage();
loadSelect();
triggerSearch();
- switchView('records'); // In case it's configured to start off as hidden
+ mkws.switchView('records'); // In case it's configured to start off as hidden
submitted = true;
return false;
}
}
// limit the query after clicking the facet
-function limitQuery (field, value)
+mkws.limitQuery = function (field, value)
{
document.mkwsSearchForm.mkwsQuery.value += ' and ' + field + '="' + value + '"';
onFormSubmitEventHandler();
}
// limit by target functions
-function limitTarget (id, name)
+mkws.limitTarget = function (id, name)
{
var navi = document.getElementById('mkwsNavi');
navi.innerHTML =
- 'Source: <a class="crossout" href="#" onclick="delimitTarget();return false;">'
+ 'Source: <a class="crossout" href="#" onclick="mkws.delimitTarget();return false;">'
+ name + '</a>';
curFilter = 'pz:id=' + id;
resetPage();
return false;
}
-function delimitTarget ()
+mkws.delimitTarget = function ()
{
var navi = document.getElementById('mkwsNavi');
navi.innerHTML = '';
var prev = '<span id="mkwsPrev"><< ' + M('Prev') + '</span><b> | </b>';
if (curPage > 1)
- prev = '<a href="#" id="mkwsPrev" onclick="pagerPrev();">'
+ prev = '<a href="#" id="mkwsPrev" onclick="mkws.pagerPrev();">'
+'<< ' + M('Prev') + '</a><b> | </b>';
var middle = '';
if(i == curPage)
numLabel = '<b>' + i + '</b>';
- middle += '<a href="#" onclick="showPage(' + i + ')"> '
+ middle += '<a href="#" onclick="mkws.showPage(' + i + ')"> '
+ numLabel + ' </a>';
}
var next = '<b> | </b><span id="mkwsNext">' + M('Next') + ' >></span>';
if (pages - curPage > 0)
- next = '<b> | </b><a href="#" id="mkwsNext" onclick="pagerNext()">'
+ next = '<b> | </b><a href="#" id="mkwsNext" onclick="mkws.pagerNext()">'
+ M('Next') + ' >></a>';
var predots = '';
+ prev + predots + middle + postdots + next + '</div>';
}
-function showPage (pageNum)
+mkws.showPage = function (pageNum)
{
curPage = pageNum;
my_paz.showPage( curPage - 1 );
// simple paging functions
-function pagerNext() {
+mkws.pagerNext = function () {
if ( totalRec - recPerPage*curPage > 0) {
my_paz.showNext();
curPage++;
}
}
-function pagerPrev() {
+mkws.pagerPrev = function () {
if ( my_paz.showPrev() != false )
curPage--;
}
// switching view between targets and records
-function switchView(view) {
+mkws.switchView = function(view) {
+ debug("switchView: " + view);
+
var targets = document.getElementById('mkwsTargets');
var results = document.getElementById('mkwsResults') ||
document.getElementById('mkwsRecords');
}
// detailed record drawing
-function showDetails (prefixRecId) {
+mkws.showDetails = function (prefixRecId) {
var recId = prefixRecId.replace('mkwsRec_', '');
var oldRecId = curDetRecId;
curDetRecId = recId;
/* set global debug flag early */
if (typeof config.debug !== 'undefined') {
- mkws_debug = config.debug;
+ mkws.debug = config.debug;
} else if (typeof mkws_config_default.debug !== 'undefined') {
- mkws_debug = mkws_config_default.debug;
+ mkws.debug = mkws_config_default.debug;
}
/* override standard config values by function parameters */
function mkws_set_lang(mkws_config) {
var lang = $.parseQuerystring().lang || mkws_config.lang || "";
- if (!lang || !mkws_locale_lang[lang]) {
+ if (!lang || !mkws.locale_lang[lang]) {
mkws_config.lang = ""
} else {
mkws_config.lang = lang;
function mkws_html_switch(config) {
debug("HTML switch");
- $("#mkwsSwitch").html($("<a/>", {
- href: '#',
- onclick: "switchView(\'records\')",
- text: M("Records")
- }));
+ $("#mkwsSwitch").append($('<a href="#" id="mkwsSwitch_records" onclick="mkws.switchView(\'records\')">' + M("Records") + '</a>'));
$("#mkwsSwitch").append($("<span/>", { text: " | " }));
- $("#mkwsSwitch").append($("<a/>", {
- href: '#',
- onclick: "switchView(\'targets\')",
- text: M("Targets")
- }));
+ $("#mkwsSwitch").append($('<a href="#" id="mkwsSwitch_targets" onclick="mkws.switchView(\'targets\')">' + M("Targets") + '</a>'));
debug("HTML targets");
$("#mkwsTargets").html('\
alert("HTTP call for authentication failed: " + err)
return;
});
+
request.get(null, function(data) {
if (!$.isXMLDoc(data)) {
alert("service proxy auth response document is not valid XML document, give up!");
alert("service proxy auth repsonse status: " + status.text() + ", give up!");
return;
}
+
+ debug("Service proxy auth successfully done");
+ mkws.service_proxy_auth = true;
});
}
hash[lang_display[i]] = 1;
}
- for (var k in mkws_locale_lang) {
+ for (var k in mkws.locale_lang) {
if (hash[k] == 1 || lang_display.length == 0)
list.push(k);
}
function M(word) {
var lang = mkws_config.lang;
- if (!lang || !mkws_locale_lang[lang])
+ if (!lang || !mkws.locale_lang[lang])
return word;
- return mkws_locale_lang[lang][word] ? mkws_locale_lang[lang][word] : word;
+ return mkws.locale_lang[lang][word] ? mkws.locale_lang[lang][word] : word;
}
/*
});
};
-function debug(string) {
- if (!mkws_debug)
- return;
- if (typeof console === "undefined" || typeof console.log === "undefined") { /* ARGH!!! old IE */
- return;
- }
- // you need to disable use strict at the top of the file!!!
- if (mkws_debug >= 3) {
- console.log(arguments.callee.caller);
- } else if (mkws_debug >= 2) {
- console.log(">>> called from function " + arguments.callee.caller.name + ' <<<');
+
+/* magic */
+$(document).ready(function() {
+ try {
+ mkws_html_all(mkws_config)
}
- console.log(string);
-}
+ catch (e) {
+ mkws_config.error = e.message;
+ // alert(e.message);
+ }
+});
-/* magic */
-$(document).ready(function() { mkws_html_all(mkws_config) });
+})(jQuery);