From e8d7971531b6d36f644fc0b0480a68dd8b56041c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannis=20Mo=C3=9Fhammer?= Date: Mon, 17 Jun 2013 17:18:35 +0200 Subject: [PATCH] Add History Api test Add CasperJS Tests for History API (~80%). Also provides a few resources like the generic.html site that can be used for more setups refs #4303 refs #4315 --- test/frontend/cases/historyApiTest.js | 57 +++++++++++++++++++ test/frontend/cases/static-page-test.js | 1 - .../static/fragments/testFragment1.html | 6 ++ .../static/fragments/testFragment2.html | 6 ++ .../static/fragments/testFragment3.html | 6 ++ test/frontend/static/generic.html | 39 +++++++++++++ test/frontend/static/moduleMock.js | 4 ++ test/frontend/test.xml | 1 + 8 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 test/frontend/cases/historyApiTest.js create mode 100644 test/frontend/static/fragments/testFragment1.html create mode 100644 test/frontend/static/fragments/testFragment2.html create mode 100644 test/frontend/static/fragments/testFragment3.html create mode 100644 test/frontend/static/generic.html create mode 100644 test/frontend/static/moduleMock.js create mode 100644 test/frontend/test.xml diff --git a/test/frontend/cases/historyApiTest.js b/test/frontend/cases/historyApiTest.js new file mode 100644 index 000000000..bb99a1c4c --- /dev/null +++ b/test/frontend/cases/historyApiTest.js @@ -0,0 +1,57 @@ + +var i2w = require('./i2w-config'); +var casper = i2w.getTestEnv(); + +casper.start("http://localhost:12999/generic.html"); + +casper.then(function() { + casper.page.evaluate(i2w.setupRequireJs, {icinga: true}); +}); + + +casper.then(function() { + this.test.assertTitle("Icinga test page"); + casper.page.evaluate(function() { + requirejs(["icinga/icinga"], function(icinga) { + icinga.loadUrl("/fragments/testFragment1.html"); + }); + }); + /*this.waitFor(function() { + return document.querySelectorAll("#icinga-main a") ; + }, */ + casper.waitForSelector("div#icinga-main a", onFirstLink); +}); + +var onFirstLink = function() { + var links = casper.page.evaluate(function() { + return document.querySelectorAll("div#icinga-main a"); + }); + // assert no reload + this.test.assertTitle("Icinga test page"); + this.test.assertUrlMatch(/.*testFragment1.html/); + this.test.assertEquals(links.length, 2); + casper.clickLabel('Fragment 2'); + casper.waitForText('Fragment 1', onSecondLink); +}; + +var onSecondLink = function() { + var links = casper.page.evaluate(function() { + return document.querySelectorAll("div#icinga-main a"); + }); + this.test.assertTitle("Icinga test page"); + this.test.assertUrlMatch(/.*testFragment2.html/); + this.test.assertEquals(links.length, 2); + casper.page.evaluate(function() { + requirejs(["icinga/icinga"], function(icinga) { + icinga.loadUrl("/fragments/testFragment3.html?this=is_a_param", "icinga-detail"); + console.log(document.location.href); + }); + }); + console.log(casper.page.evaluate(function() { + return document.location.href; + })); +}; + +casper.run(function() { + this.test.done(); +}); diff --git a/test/frontend/cases/static-page-test.js b/test/frontend/cases/static-page-test.js index f37a2a214..39f94081f 100644 --- a/test/frontend/cases/static-page-test.js +++ b/test/frontend/cases/static-page-test.js @@ -11,7 +11,6 @@ casper.start("http://localhost:12999/empty.html"); casper.then(function() { - casper.log(this.test); this.test.assertTitle("Just an empty page"); }); diff --git a/test/frontend/static/fragments/testFragment1.html b/test/frontend/static/fragments/testFragment1.html new file mode 100644 index 000000000..926a2c392 --- /dev/null +++ b/test/frontend/static/fragments/testFragment1.html @@ -0,0 +1,6 @@ +
+

Test fragment

+ Fragment 2 + Fragment 3 + +
diff --git a/test/frontend/static/fragments/testFragment2.html b/test/frontend/static/fragments/testFragment2.html new file mode 100644 index 000000000..4db44e053 --- /dev/null +++ b/test/frontend/static/fragments/testFragment2.html @@ -0,0 +1,6 @@ +
+

Test fragment 2

+ Fragment 1 + Fragment 3 + +
diff --git a/test/frontend/static/fragments/testFragment3.html b/test/frontend/static/fragments/testFragment3.html new file mode 100644 index 000000000..e773f5eff --- /dev/null +++ b/test/frontend/static/fragments/testFragment3.html @@ -0,0 +1,6 @@ +
+

Test fragment 3

+ Fragment 1 + Fragment 2 + +
diff --git a/test/frontend/static/generic.html b/test/frontend/static/generic.html new file mode 100644 index 000000000..d1e8c301a --- /dev/null +++ b/test/frontend/static/generic.html @@ -0,0 +1,39 @@ + + + + + + + + + + + Icinga test page + + + + + + + + + + + + + +
+
+
+ +
+ + + diff --git a/test/frontend/static/moduleMock.js b/test/frontend/static/moduleMock.js new file mode 100644 index 000000000..aa9c4079f --- /dev/null +++ b/test/frontend/static/moduleMock.js @@ -0,0 +1,4 @@ +define([], function() { + "use strict"; + return {}; +}); diff --git a/test/frontend/test.xml b/test/frontend/test.xml new file mode 100644 index 000000000..68ba1bc3a --- /dev/null +++ b/test/frontend/test.xml @@ -0,0 +1 @@ +Page title is: "i4cinga-web test [Jenkins]" \ No newline at end of file