X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=test%2Fspec%2Fmkws-index-full.spec.js;h=52b974608615ec59290f26ee3872d0e44a0a3cd8;hb=fab2859e81ebbf4648a7133a34bd7f712c3416dc;hp=ff9f47ae19244b976816a1490502b2ea456937f8;hpb=56d5229e4595706d0b6b92bfe4d9ed0681ed72ff;p=mkws-moved-to-github.git diff --git a/test/spec/mkws-index-full.spec.js b/test/spec/mkws-index-full.spec.js index ff9f47a..52b9746 100644 --- a/test/spec/mkws-index-full.spec.js +++ b/test/spec/mkws-index-full.spec.js @@ -6,12 +6,8 @@ var file = '../examples/htdocs/index-full.html' -var jsdom = require('jsdom').jsdom; -var myWindow = jsdom().createWindow(); -var $ = jQuery = require('jquery').create(myWindow); - var fs = require("fs"); -var index_full = fs.readFileSync(file, "utf-8"); +var html = fs.readFileSync(file, "utf-8"); var mkws_tags_required = ["mkwsSearch", "mkwsResults"]; var mkws_tags_optional = ["mkwsSwitch", "mkwsLang", "mkwsTargets"]; @@ -39,28 +35,69 @@ function flat_list (list) { return data; } - -describe("index-full.html test", function() { +/* + * simple test with string matching of the HTML page + * + */ +describe("index-full.html string test", function() { it("html test", function() { - expect(index_full).toBeDefined(); + expect(html).toBeDefined(); - expect(index_full).toMatch(//); // forgotten doctype? - expect(index_full).toMatch(//); - expect(index_full).toMatch(//); - expect(index_full).toMatch(/<\/html.*?>/); - expect(index_full).toMatch(/<\/head.*?>/); - expect(index_full).toMatch(/<\/body.*?>/); + expect(html).toMatch(//); // forgotten doctype? + expect(html).toMatch(//); + expect(html).toMatch(//); + expect(html).toMatch(/<\/html.*?>/); + expect(html).toMatch(/<\/head.*?>/); + expect(html).toMatch(/<\/body.*?>/); - expect(index_full).toMatch(/.+<\/title>/i); - expect(index_full).toMatch(/.+<\/title>/i); + expect(html).toMatch(/'; // console.log(data) - expect(index_full).toMatch(data); + expect(html).toMatch(data); + } + }); +}); + + +/* + * parse HTML data to DOM, and run jQuery request on it + * + */ +describe("index-full.html jsdom + jquery", function() { + var window = require('jsdom').jsdom(html, null, { + FetchExternalResources: false, + ProcessExternalResources: false, + MutationEvents: false, + QuerySelector: false + }).createWindow(); + + /* apply jquery to the window */ + var $ = jQuery = 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); + + var tags = flat_list([mkws_tags_required, mkws_tags_optional, mkws_tags_optional2]); + 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); + }); });