fe0dbdfac41fa28bad0060264481f073d1483417
[mkws-moved-to-github.git] / test / spec-sp / mkws-index-jsdom.spec.js
1 /* Copyright (c) 2013 IndexData ApS. http://indexdata.com
2  *
3  * jQuery test with DOM/windows object
4  *
5  */
6
7
8 var fs = require("fs");
9 var utils = require("./mkws_utils.js");
10
11 /*
12  * parse HTML data to DOM, and run jQuery request on it
13  *
14  */
15
16 function jsdom_check(file, tags_array, ignore_doctype) {
17     var html = fs.readFileSync(file, "utf-8");
18     var tags = utils.flat_list(tags_array);
19
20     describe("local html file jsdom + jquery for " + file, function () {
21         var window = require('jsdom').jsdom(html, null, {
22             FetchExternalResources: false,
23             ProcessExternalResources: false,
24             MutationEvents: false,
25             QuerySelector: false
26         }).createWindow();
27
28         /* apply jquery to the window */
29         var $ = require('jQuery').create(window);
30
31
32         it("html jquery test", function () {
33             expect(html).toBeDefined();
34
35             expect($("body").length == 0).toEqual(false);
36             expect($("body").length == 1).toEqual(true);
37             expect($("head").length == 1).toEqual(true);
38
39             for (var i = 0; i < tags.length; i++) {
40                 expect($("#" + tags[i]).length == 1).toEqual(true);
41             }
42         });
43
44         it("html jquery fail test", function () {
45             expect(html).toBeDefined();
46
47             expect($("body_does_not_exists").length == 1).toEqual(false);
48             expect($("#body_does_not_exists").length == 1).toEqual(false);
49         });
50     });
51 }
52
53 jsdom_check('../examples/htdocs/language.html', [utils.tags.required, utils.tags.optional, utils.tags.optional2]);
54 jsdom_check('../examples/htdocs/mobile.html', [utils.tags.required, utils.tags.optional]);
55 jsdom_check('../examples/htdocs/index.html', [utils.tags.required, utils.tags.optional]);