1 /* Copyright (c) 2013 IndexData ApS. http://indexdata.com
3 * jQuery test with DOM/windows object
8 var fs = require("fs");
9 var utils = require("./mkws_utils.js");
12 * simple test with string matching of the HTML page
16 function html_check (file, tags_array, ignore_doctype) {
17 var html = fs.readFileSync(file, "utf-8");
18 var tags = utils.flat_list(tags_array);
20 describe("index-full.html string test for " + file, function() {
21 it("html test", function() {
22 expect(html).toBeDefined();
24 // forgotten doctype declaration
25 if (!ignore_doctype) {
26 expect(html).toMatch(/<html.*?>/);
27 expect(html).toMatch(/<\/html.*?>/);
29 expect(html).toMatch(/<head.*?>/);
30 expect(html).toMatch(/<body.*?>/);
31 expect(html).toMatch(/<\/head.*?>/);
32 expect(html).toMatch(/<\/body.*?>/);
34 expect(html).toMatch(/<meta .*?charset=utf-8/i);
35 expect(html).toMatch(/<title>.+<\/title>/i);
36 expect(html).toMatch(/<link .*?type="text\/css" href=".*?\/?mkwsStyle.css"/);
39 for(var i = 0, data = ""; i < tags.length; i++) {
40 data = '<div id="' + tags[i] + '">';
42 expect(html).toMatch(data);
50 * parse HTML data to DOM, and run jQuery request on it
54 function jsdom_check (file, tags_array, ignore_doctype) {
55 var html = fs.readFileSync(file, "utf-8");
56 var tags = utils.flat_list(tags_array);
58 describe("index-full.html jsdom + jquery for " + file, function() {
59 var window = require('jsdom').jsdom(html, null, {
61 FetchExternalResources: false,
62 ProcessExternalResources: false,
63 MutationEvents: false,
67 /* apply jquery to the window */
68 var $ = jQuery = require('jquery').create(window);
71 it("html jquery test", function() {
72 expect(html).toBeDefined();
74 expect($("body").length == 0).toEqual(false);
75 expect($("body").length == 1).toEqual(true);
76 expect($("head").length == 1).toEqual(true);
78 for(var i = 0; i < tags.length; i++) {
79 expect($("#" + tags[i]).length == 1).toEqual(true);
83 it("html jquery fail test", function() {
84 expect(html).toBeDefined();
86 expect($("body_does_not_exists").length == 1).toEqual(false);
87 expect($("#body_does_not_exists").length == 1).toEqual(false);
92 html_check('../examples/htdocs/index-full.html', [utils.tags.required, utils.tags.optional, utils.tags.optional2]);
93 html_check('../examples/htdocs/index-mobile.html', [utils.tags.required, utils.tags.optional]);
94 html_check('../examples/htdocs/index-popup.html', [], true);
95 html_check('../examples/htdocs/index-jquery.html', []);
96 html_check('../examples/htdocs/index-mike.html', [utils.tags.required, utils.tags.optional], true);
98 jsdom_check('../examples/htdocs/index-full.html', [utils.tags.required, utils.tags.optional, utils.tags.optional2]);
99 jsdom_check('../examples/htdocs/index-mobile.html', [utils.tags.required, utils.tags.optional]);
100 jsdom_check('../examples/htdocs/index-popup.html', [], true);
101 jsdom_check('../examples/htdocs/index-jquery.html', []);
102 jsdom_check('../examples/htdocs/index-mike.html', [utils.tags.required, utils.tags.optional], true);