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 ]"
+<?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" />
--- /dev/null
+# Copyright (c) 2013 IndexData ApS. http://indexdata.com
+
+all: check
+
+clean distclean:
+
+check:
+ jasmine-node ./spec
+
+test: check
+
+jsbeautifier:
+ for i in ./spec/*.js ./js/*.js; do \
+ jsbeautifier -j $$i > $@.tmp && mv -f $@.tmp $$i; \
+ done
+
+help:
+ @echo "make [ all | clean | check | jsbeautifier ]"
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
function mkws_jasmine_init(delay) {
var currentWindowOnload = window.onload;
- window.onload = function() {
+ window.onload = function () {
if (currentWindowOnload) {
currentWindowOnload();
}
if (delay) {
- setTimeout(function() {
+ setTimeout(function () {
execJasmine()
}, delay);
} else {
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
- jasmineEnv.specFilter = function(spec) {
+ jasmineEnv.specFilter = function (spec) {
return htmlReporter.specFilter(spec);
};
};
/* EOF */
-
+++ /dev/null
-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
+ *
+ * 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();
+ });
+});
-
-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);
- });
+/* 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:\/\/)/)
- });
+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("usesessions false", function () {
+ expect(usesessions).toBe(false);
+ });
- it("my_paz is defined", function() {
- expect(my_paz).not.toBe(undefined);
- });
+ 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);
- });
+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");
+
+/*
+ * 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
-
-describe("A suite", function() {
- it("contains spec with an expectation", function() {
- expect(true).toBe(true);
- });
-});
--- /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);
+ });
+});