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: Wolfram's playground</title>
+ <link rel="stylesheet" type="text/css" href="../../tools/htdocs/mkwsStyle.css" />
+ <script type="text/javascript">
+ var mkws_config = {
+ switch_menu: false,
+ /*
+ 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>
+<!-- <script>
+ $(document).ready(function() {
+ debug("document ready");
+ setTimeout(function () {
+ debug("start search");
+ $("input#mkwsQuery").val("freebsd");
+ $("input#mkwsButton").trigger("click");
+
+ function my_click (id, time) {
+ setTimeout(function () {
+ debug("trigger click on id: " + id);
+ $(id).trigger("click");
+ }, time*1000);
+ }
+
+ function found (time) {
+ setTimeout(function() {
+ var found = $("#mkwsPager").html().match(/found: ([0-9]+)/);
+ debug("mkws pager found records: " + (found != null ? found[0] : "unknown"));
+ }, time*1000);
+ }
+
+ my_click("#mkwsNext", 10);
+ my_click("#mkwsNext", 13);
+ my_click("#mkwsPrev", 15);
+
+ if ($("#mkwsPager").length) {
+ found(0);
+ found(5);
+ found(10);
+ found(15);
+ found(25);
+
+ } else {
+ debug("no mkws page found");
+ }
+ }, 3 * 1000);
+ });
+ </script>-->
+ </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;
--- /dev/null
+# Copyright (c) 2013 IndexData ApS. http://indexdata.com
+
+all: check
+
+clean distclean:
+
+check:
+ jasmine-node ./spec
+
+test: check
+
+jsbeautifier jsb:
+ for i in ./spec/*.js ./js/*.js; do \
+ jsbeautifier -j $$i > $@.tmp && mv -f $@.tmp $$i; \
+ done
+
+help:
+ @echo "make [ all | clean | check | jsbeautifier ]"
--- /dev/null
+Jasmine / jasmine-node test frame works
+---------------------------------------
+
+./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
+2. install node modules with npm
+
+npm install jquery
+npm install jsdom
+npm install request
+npm install jasmine-node
+
+
+--
+Aug 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
+ *
+ * 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(pazpar2path).toMatch(/^(\/|http:\/\/)/)
+ });
+
+ it("usesessions false", function () {
+ expect(usesessions).toBe(false);
+ });
+
+ it("my_paz is defined", function () {
+ expect(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
+ *
+ */
+
+// global state object
+var jasmine_state = {
+ time: 0
+};
+
+function my_click(id, time) {
+ setTimeout(function () {
+ debug("trigger click on id: " + id);
+ $(id).trigger("click");
+ }, time * 1000);
+}
+
+function found(time, none) {
+ setTimeout(function () {
+ jasmine_state.time = time;
+
+ var found = $("#mkwsPager").html().match(/found: ([0-9]+)/);
+
+ describe("pazpar2 hit count", function () {
+ if (none) {
+ it("no results yet", function () {
+ expect(found).toBe(null);
+ });
+ } else {
+ it("got results", function () {
+ expect(found[0]).toMatch(/^[0-9]+$/);
+ });
+ }
+ debug("mkws pager found records: " + (found != null ? found[0] : "unknown"));
+ debug("time state: " + jasmine_state.time);
+ });
+
+ }, time * 1000);
+}
+
+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 == 1).toBe(true);
+ expect($("input#mkwsButton").length == 1).toBe(true);
+
+ expect($("#mkwsNext").length == 1).toBe(false);
+ expect($("#mkwsPrev").length == 1).toBe(false);
+ });
+
+ it("run search query", function () {
+ $("input#mkwsQuery").val("freebsd");
+ expect($("input#mkwsQuery").val()).toMatch(/^freebsd$/);
+
+ setTimeout(function () {
+ $("input#mkwsButton").trigger("click");
+ }, 3 * 1000);
+ });
+
+
+ // Asynchronous part
+ it("check running search", function () {
+ var max_time = 10;
+
+ expect($("#mkwsPager").length == 1).toBe(true);
+
+ runs(function () {
+ // click next/prev after N seconds
+ my_click("#mkwsNext", 10);
+ my_click("#mkwsNext", 13);
+ my_click("#mkwsPrev", 15);
+
+ // check hit counter after N seconds
+ found(0, true);
+ found(5);
+ found(10);
+ found(15);
+ found(max_time);
+ });
+
+/*
+ waitsFor(function () {
+ return jasmine_state.time == max_time ? true : false;
+ }, "The Value should be 20 seconds", 30 * 1000); // (max_time + 1) * 1000);
+
+ runs(function () {
+ expect($("#mkwsPager").length == 1).toBe(true);
+ })
+ */
+
+/* runs(function () {
+ expect(jasmine_state.time).toEqual(max_time);
+ });
+ */
+ });
+});
--- /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: ["mkwsSwitch", "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);
+ });
+});
/* magic */
-$(document).ready(function() { mkws_html_all(mkws_config) });
+$(document).ready(function() {
+ try {
+ mkws_html_all(mkws_config)
+ }
+
+ catch (e) {
+ mkws_config.error = e.message;
+ // alert(e.message);
+ }
+});