Merge branch 'wosch' of ssh://git.indexdata.com:222/home/git/private/mkws into wosch
authorWolfram Schneider <wosch@indexdata.dk>
Thu, 22 Aug 2013 11:02:51 +0000 (11:02 +0000)
committerWolfram Schneider <wosch@indexdata.dk>
Thu, 22 Aug 2013 11:02:51 +0000 (11:02 +0000)
15 files changed:
Makefile
examples/htdocs/index-wolfram.html
test/Makefile [new file with mode: 0644]
test/README.txt
test/js/mkws-jasmine-run.js
test/spec/SampleSpecs.js [deleted file]
test/spec/jquery.spec.js [new file with mode: 0644]
test/spec/jsdom.spec.js [new file with mode: 0644]
test/spec/mkws-config.js
test/spec/mkws-index-jsdom.spec.js [new file with mode: 0644]
test/spec/mkws-index-simple.spec.js [new file with mode: 0644]
test/spec/mkws-true.js [deleted file]
test/spec/mkws_utils.js [new file with mode: 0644]
test/spec/sample.spec.js [new file with mode: 0644]
test/spec/true.spec.js [new file with mode: 0644]

index 1b1fe3b..26c0ca4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,10 @@
 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 ]"
index d057734..fccb853 100644 (file)
@@ -1,3 +1,5 @@
+<?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" />
diff --git a/test/Makefile b/test/Makefile
new file mode 100644 (file)
index 0000000..f769737
--- /dev/null
@@ -0,0 +1,18 @@
+# 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 ]"
index ff2215f..8fbfea9 100644 (file)
@@ -1,15 +1,26 @@
 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
index 3b9b29e..1aec289 100644 (file)
@@ -7,12 +7,12 @@
 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 {
@@ -27,7 +27,7 @@ function mkws_jasmine_init(delay) {
         var htmlReporter = new jasmine.HtmlReporter();
         jasmineEnv.addReporter(htmlReporter);
 
-        jasmineEnv.specFilter = function(spec) {
+        jasmineEnv.specFilter = function (spec) {
             return htmlReporter.specFilter(spec);
         };
 
@@ -36,4 +36,3 @@ function mkws_jasmine_init(delay) {
 };
 
 /* EOF */
-
diff --git a/test/spec/SampleSpecs.js b/test/spec/SampleSpecs.js
deleted file mode 100644 (file)
index f9c001b..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-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');
-  });
-});
diff --git a/test/spec/jquery.spec.js b/test/spec/jquery.spec.js
new file mode 100644 (file)
index 0000000..2f3baa8
--- /dev/null
@@ -0,0 +1,32 @@
+/* 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/);
+    });
+});
diff --git a/test/spec/jsdom.spec.js b/test/spec/jsdom.spec.js
new file mode 100644 (file)
index 0000000..725d052
--- /dev/null
@@ -0,0 +1,33 @@
+/* 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();
+    });
+});
index 7563e82..e5189c0 100644 (file)
@@ -1,45 +1,50 @@
-
-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);
+    });
 });
diff --git a/test/spec/mkws-index-jsdom.spec.js b/test/spec/mkws-index-jsdom.spec.js
new file mode 100644 (file)
index 0000000..8106441
--- /dev/null
@@ -0,0 +1,57 @@
+/* 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);
diff --git a/test/spec/mkws-index-simple.spec.js b/test/spec/mkws-index-simple.spec.js
new file mode 100644 (file)
index 0000000..50ebd65
--- /dev/null
@@ -0,0 +1,52 @@
+/* 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);
diff --git a/test/spec/mkws-true.js b/test/spec/mkws-true.js
deleted file mode 100644 (file)
index 798e876..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-
-describe("A suite", function() {
-  it("contains spec with an expectation", function() {
-    expect(true).toBe(true);
-  });
-});
diff --git a/test/spec/mkws_utils.js b/test/spec/mkws_utils.js
new file mode 100644 (file)
index 0000000..e837fa1
--- /dev/null
@@ -0,0 +1,43 @@
+/* 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
+};
diff --git a/test/spec/sample.spec.js b/test/spec/sample.spec.js
new file mode 100644 (file)
index 0000000..8979206
--- /dev/null
@@ -0,0 +1,31 @@
+/* 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');
+    });
+});
diff --git a/test/spec/true.spec.js b/test/spec/true.spec.js
new file mode 100644 (file)
index 0000000..b515c06
--- /dev/null
@@ -0,0 +1,10 @@
+/* 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);
+    });
+});