working test for examples/htdocs/index-full.html
[mkws-moved-to-github.git] / test / spec / mkws-index-full.spec.js
1 /* Copyright (c) 2013 IndexData ApS. http://indexdata.com
2  *
3  * jQuery test with DOM/windows object
4  *
5  */
6
7 var file = '../examples/htdocs/index-full.html'
8
9 var jsdom = require('jsdom').jsdom;
10 var myWindow = jsdom().createWindow();
11 var $ = jQuery = require('jquery').create(myWindow);
12
13 var fs = require("fs");
14 var index_full = fs.readFileSync(file, "utf-8");
15
16 var mkws_tags_required = ["mkwsSearch", "mkwsResults"];
17 var mkws_tags_optional = ["mkwsSwitch", "mkwsLang", "mkwsTargets"];
18 var mkws_tags_optional2 = ["mkwsMOTD", "mkwsStat", "footer"];
19
20 /*
21  * combine arrays, return a flat list
22  * [["a","b"], ["c"], "d"] => ["a", "b", "c", "d"]
23  *
24  */
25 function flat_list (list) {
26   var data = [];
27
28   for(var i = 0; i < list.length; i++) {
29       if (typeof list[i] == 'object') {
30         for(var j = 0; j < list[i].length; j++) {
31           data.push(list[i][j]);
32         }
33
34       } else {
35         data.push(list[i]);
36       }
37   }
38
39   return data;
40 }
41
42
43 describe("index-full.html test", function() {
44   it("html test", function() {
45     expect(index_full).toBeDefined();
46
47     expect(index_full).toMatch(/<html.*?>/); // forgotten doctype?
48     expect(index_full).toMatch(/<head.*?>/);
49     expect(index_full).toMatch(/<body.*?>/);
50     expect(index_full).toMatch(/<\/html.*?>/);
51     expect(index_full).toMatch(/<\/head.*?>/);
52     expect(index_full).toMatch(/<\/body.*?>/);
53
54     expect(index_full).toMatch(/<meta .*?charset=utf-8/i);
55     expect(index_full).toMatch(/<title>.+<\/title>/i);
56     expect(index_full).toMatch(/<link .*?type="text\/css" href=".*?\/mkwsStyle.css"/);
57
58     var tags = flat_list([mkws_tags_required, mkws_tags_optional, mkws_tags_optional2]);
59
60     for(var i = 0, data = ""; i < tags.length; i++) {
61       data = '<div id="' + tags[i] + '">';
62       // console.log(data)
63       expect(index_full).toMatch(data);
64     }
65   });
66 });