You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2020/03/25 21:28:32 UTC
[myfaces-tobago] branch master updated (032ff58 -> 886a6f0)
This is an automated email from the ASF dual-hosted git repository.
hnoeth pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git.
from 032ff58 add outline markup for buttons
new e721320 jasmine framework: put result container on top of the page
new 886a6f0 jasmine framework: test tools
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../20-component/010-input/10-in/In.test.js | 53 +++-----
.../030-select/30-selectOneRadio/Radio.test.js | 142 ++++++++++-----------
.../src/main/webapp/script/jasmine-3.5.0/boot.js | 3 +-
.../src/main/webapp/script/tobago-test.js | 14 +-
.../tobago-example-demo/src/main/webapp/test.xhtml | 1 +
.../resources/tobago/test/tobago-test-tool.js | 94 ++++++++++++++
6 files changed, 194 insertions(+), 113 deletions(-)
[myfaces-tobago] 01/02: jasmine framework: put result container on
top of the page
Posted by hn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
hnoeth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
commit e721320a8409c1db03025e065f90a5f1116cf820
Author: Henning Nöth <hn...@apache.org>
AuthorDate: Wed Mar 25 20:17:01 2020 +0100
jasmine framework: put result container on top of the page
Issue: TOBAGO-2022
---
.../tobago-example-demo/src/main/webapp/script/jasmine-3.5.0/boot.js | 2 +-
tobago-example/tobago-example-demo/src/main/webapp/test.xhtml | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/script/jasmine-3.5.0/boot.js b/tobago-example/tobago-example-demo/src/main/webapp/script/jasmine-3.5.0/boot.js
index 2d68462..b438fb8 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/script/jasmine-3.5.0/boot.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/script/jasmine-3.5.0/boot.js
@@ -76,7 +76,7 @@
env: env,
navigateWithNewParam: function(key, value) { return queryString.navigateWithNewParam(key, value); },
addToExistingQueryString: function(key, value) { return queryString.fullStringWithNewParam(key, value); },
- getContainer: function() { return document.body; },
+ getContainer: function() { return document.getElementById("jasmine-container"); },
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
timer: new jasmine.Timer(),
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/test.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/test.xhtml
index 4b1c807..e50ea57 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/test.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/test.xhtml
@@ -35,6 +35,7 @@
<div id="qunit"></div>
<div id="qunit-fixture"></div>
+ <div id="jasmine-container"></div>
<tc:button label="Close Test" link="#{param['base']}.xhtml"/>
[myfaces-tobago] 02/02: jasmine framework: test tools
Posted by hn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
hnoeth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
commit 886a6f0bffe523e718df24ed680cf6a95494f269
Author: Henning Nöth <hn...@apache.org>
AuthorDate: Wed Mar 25 22:26:08 2020 +0100
jasmine framework: test tools
* jasmine: set DEFAULT_TIMEOUT_INTERVAL to 2 minutes
* use querySelectorFn() and querySelectorAllFn() instead of testFrameQuerySelectorFn() and testFrameQuerySelectorAllFn(). If migration from QUnit to Jasmine is complete, these old testFrame*() methods should be deleted
* migrate: In.test.js, Radio.test.js
Issue: TOBAGO-2022
---
.../20-component/010-input/10-in/In.test.js | 53 +++-----
.../030-select/30-selectOneRadio/Radio.test.js | 142 ++++++++++-----------
.../src/main/webapp/script/jasmine-3.5.0/boot.js | 1 +
.../src/main/webapp/script/tobago-test.js | 14 +-
.../resources/tobago/test/tobago-test-tool.js | 94 ++++++++++++++
5 files changed, 192 insertions(+), 112 deletions(-)
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/010-input/10-in/In.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/010-input/10-in/In.test.js
index 16a31ad..d551113 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/010-input/10-in/In.test.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/010-input/10-in/In.test.js
@@ -15,46 +15,29 @@
* limitations under the License.
*/
-import {testFrameQuerySelectorFn} from "/script/tobago-test.js";
-import {TobagoTestTool} from "/tobago/test/tobago-test-tool.js";
+import {querySelectorFn, testFrameQuerySelectorFn} from "/script/tobago-test.js";
+import {JasmineTestTool} from "/tobago/test/tobago-test-tool.js";
-QUnit.test("inputfield with label", function (assert) {
+it("inputfield with label", function (done) {
let labelFn = testFrameQuerySelectorFn("#page\\:mainForm\\:iNormal > label");
let inputFieldFn = testFrameQuerySelectorFn("#page\\:mainForm\\:iNormal\\:\\:field");
- let TTT = new TobagoTestTool(assert);
- TTT.asserts(2, function () {
- assert.equal(labelFn().textContent, "Input");
- assert.equal(inputFieldFn().value, "Some Text");
- });
- TTT.action(function () {
- inputFieldFn().value = "abc";
- });
- TTT.asserts(1, function () {
- assert.equal(inputFieldFn().value, "abc");
- });
- TTT.startTest();
+ const test = new JasmineTestTool(done);
+ test.do(() => expect(labelFn().textContent).toBe("Input"));
+ test.do(() => expect(inputFieldFn().value).toBe("Some Text"));
+ test.do(() => inputFieldFn().value = "abc");
+ test.do(() => expect(inputFieldFn().value).toBe("abc"));
+ test.start();
});
-QUnit.test("ajax change event", function (assert) {
- let inputFieldFn = testFrameQuerySelectorFn("#page\\:mainForm\\:inputAjax\\:\\:field");
- let outputFieldFn = testFrameQuerySelectorFn("#page\\:mainForm\\:outputAjax span");
+it("ajax change event", function (done) {
+ let inputFieldFn = querySelectorFn("#page\\:mainForm\\:inputAjax\\:\\:field");
+ let outputFieldFn = querySelectorFn("#page\\:mainForm\\:outputAjax span");
- let TTT = new TobagoTestTool(assert);
- TTT.asserts(2, function () {
- assert.equal(inputFieldFn().value, "");
- assert.equal(outputFieldFn().textContent, "");
- });
- TTT.action(function () {
- inputFieldFn().value = "qwe";
- inputFieldFn().dispatchEvent(new Event("change", {bubbles: true}));
- });
- TTT.waitForResponse();
- TTT.asserts(1, function () {
- assert.equal(inputFieldFn().value, "qwe");
- });
- TTT.asserts(1, function () {
- assert.equal(outputFieldFn().textContent, "qwe");
- });
- TTT.startTest();
+ const test = new JasmineTestTool(done);
+ test.do(() => inputFieldFn().value = "some input text");
+ test.do(() => inputFieldFn().dispatchEvent(new Event("change", {bubbles: true})));
+ test.wait(() => outputFieldFn() && outputFieldFn().textContent === "some input text");
+ test.do(() => expect(outputFieldFn().textContent).toBe("some input text"));
+ test.start();
});
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/030-select/30-selectOneRadio/Radio.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/030-select/30-selectOneRadio/Radio.test.js
index 00e7a39..891b604 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/030-select/30-selectOneRadio/Radio.test.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/030-select/30-selectOneRadio/Radio.test.js
@@ -15,91 +15,81 @@
* limitations under the License.
*/
-import {testFrameQuerySelectorAllFn, testFrameQuerySelectorFn} from "/script/tobago-test.js";
-import {TobagoTestTool} from "/tobago/test/tobago-test-tool.js";
+import {querySelectorAllFn, querySelectorFn} from "/script/tobago-test.js";
+import {JasmineTestTool} from "/tobago/test/tobago-test-tool.js";
-QUnit.test("submit: Addition (2 + 4)", function (assert) {
- let number1Fn = testFrameQuerySelectorAllFn("#page\\:mainForm\\:selectNum1 input");
- let number2Fn = testFrameQuerySelectorAllFn("#page\\:mainForm\\:selectNum2 input");
- let submitAddFn = testFrameQuerySelectorFn("#page\\:mainForm\\:submitAdd");
- let outputFn = testFrameQuerySelectorFn("#page\\:mainForm\\:resultOutput span");
+it("submit: Addition (2 + 4)", function (done) {
+ let number1Fn = querySelectorAllFn("#page\\:mainForm\\:selectNum1 input");
+ let number2Fn = querySelectorAllFn("#page\\:mainForm\\:selectNum2 input");
+ let submitAddFn = querySelectorFn("#page\\:mainForm\\:submitAdd");
+ let outputFn = querySelectorFn("#page\\:mainForm\\:resultOutput span");
- let TTT = new TobagoTestTool(assert);
- TTT.action(function () {
- number1Fn().item(0).checked = false;
- number1Fn().item(1).checked = true; // Select 2
- number1Fn().item(2).checked = false;
- number2Fn().item(0).checked = false;
- number2Fn().item(1).checked = false;
- number2Fn().item(2).checked = true; // Select 4
- submitAddFn().dispatchEvent(new Event("click", {bubbles: true}));
- });
- TTT.waitForResponse();
- TTT.asserts(1, function () {
- assert.equal(outputFn().textContent, "6");
- });
- TTT.startTest();
+ const test = new JasmineTestTool(done);
+ test.do(() => number1Fn().item(0).checked = false);
+ test.do(() => number1Fn().item(1).checked = true); // Select 2
+ test.do(() => number1Fn().item(2).checked = false);
+ test.do(() => number2Fn().item(0).checked = false);
+ test.do(() => number2Fn().item(1).checked = false);
+ test.do(() => number2Fn().item(2).checked = true); // Select 4
+ test.do(() => submitAddFn().dispatchEvent(new Event("click", {bubbles: true})));
+ test.wait(() => outputFn() && outputFn().textContent === "6");
+ test.do(() => expect(outputFn().textContent).toBe("6"));
+ test.start();
});
-QUnit.test("submit: Subtraction (4 - 1)", function (assert) {
- let number1Fn = testFrameQuerySelectorAllFn("#page\\:mainForm\\:selectNum1 input");
- let number2Fn = testFrameQuerySelectorAllFn("#page\\:mainForm\\:selectNum2 input");
- let submitSubFn = testFrameQuerySelectorFn("#page\\:mainForm\\:submitSub");
- let outputFn = testFrameQuerySelectorFn("#page\\:mainForm\\:resultOutput span");
+it("submit: Subtraction (4 - 1)", function (done) {
+ let number1Fn = querySelectorAllFn("#page\\:mainForm\\:selectNum1 input");
+ let number2Fn = querySelectorAllFn("#page\\:mainForm\\:selectNum2 input");
+ let submitSubFn = querySelectorFn("#page\\:mainForm\\:submitSub");
+ let outputFn = querySelectorFn("#page\\:mainForm\\:resultOutput span");
- let TTT = new TobagoTestTool(assert);
- TTT.action(function () {
- number1Fn().item(0).checked = false;
- number1Fn().item(1).checked = false;
- number1Fn().item(2).checked = true; // Select 4
- number2Fn().item(0).checked = true; // Select 1
- number2Fn().item(1).checked = false;
- number2Fn().item(2).checked = false;
- submitSubFn().dispatchEvent(new Event("click", {bubbles: true}));
- });
- TTT.waitForResponse();
- TTT.asserts(1, function () {
- assert.equal(outputFn().textContent, "3");
- });
- TTT.startTest();
+ const test = new JasmineTestTool(done);
+ test.do(() => number1Fn().item(0).checked = false);
+ test.do(() => number1Fn().item(1).checked = false);
+ test.do(() => number1Fn().item(2).checked = true); // Select 4
+ test.do(() => number2Fn().item(0).checked = true); // Select 1
+ test.do(() => number2Fn().item(1).checked = false);
+ test.do(() => number2Fn().item(2).checked = false);
+ test.do(() => submitSubFn().dispatchEvent(new Event("click", {bubbles: true})));
+ test.wait(() => outputFn() && outputFn().textContent === "3");
+ test.do(() => expect(outputFn().textContent).toBe("3"));
+ test.start();
});
-QUnit.test("ajax: select Mars", function (assert) {
- let planetFn = testFrameQuerySelectorAllFn("#page\\:mainForm\\:selectPlanet input");
- let moonsFn = testFrameQuerySelectorAllFn("#page\\:mainForm\\:moonradio label.form-check-label");
+it("ajax: select Mars", function (done) {
+ let planetFn = querySelectorAllFn("#page\\:mainForm\\:selectPlanet input");
+ let moonsFn = querySelectorAllFn("#page\\:mainForm\\:moonradio label.form-check-label");
- let TTT = new TobagoTestTool(assert);
- TTT.action(function () {
- planetFn().item(0).checked = false;
- planetFn().item(2).checked = false;
- planetFn().item(1).checked = true; // Mars.
- planetFn().item(1).dispatchEvent(new Event("change", {bubbles: true}));
- });
- TTT.waitForResponse();
- TTT.asserts(2, function () {
- assert.equal(moonsFn().item(0).textContent, "Phobos");
- assert.equal(moonsFn().item(1).textContent, "Deimos");
- });
- TTT.startTest();
+ const test = new JasmineTestTool(done);
+ test.do(() => planetFn().item(0).checked = false);
+ test.do(() => planetFn().item(2).checked = false);
+ test.do(() => planetFn().item(1).checked = true); // Mars.
+ test.do(() => planetFn().item(1).dispatchEvent(new Event("change", {bubbles: true})));
+ test.wait(() => moonsFn()
+ && moonsFn().item(0).textContent === "Phobos" && moonsFn().item(1).textContent === "Deimos");
+ test.do(() => expect(moonsFn().item(0).textContent).toBe("Phobos"));
+ test.do(() => expect(moonsFn().item(1).textContent).toBe("Deimos"));
+ test.start();
});
-QUnit.test("ajax: select Jupiter", function (assert) {
- let planetFn = testFrameQuerySelectorAllFn("#page\\:mainForm\\:selectPlanet input");
- let moonsFn = testFrameQuerySelectorAllFn("#page\\:mainForm\\:moonradio label.form-check-label");
+it("ajax: select Jupiter", function (done) {
+ let planetFn = querySelectorAllFn("#page\\:mainForm\\:selectPlanet input");
+ let moonsFn = querySelectorAllFn("#page\\:mainForm\\:moonradio label.form-check-label");
- let TTT = new TobagoTestTool(assert);
- TTT.action(function () {
- planetFn().item(0).checked = false;
- planetFn().item(1).checked = false;
- planetFn().item(2).checked = true; // Jupiter.
- planetFn().item(2).dispatchEvent(new Event("change", {bubbles: true}));
- });
- TTT.waitForResponse();
- TTT.asserts(4, function () {
- assert.equal(moonsFn().item(0).textContent, "Europa");
- assert.equal(moonsFn().item(1).textContent, "Ganymed");
- assert.equal(moonsFn().item(2).textContent, "Io");
- assert.equal(moonsFn().item(3).textContent, "Kallisto");
- });
- TTT.startTest();
+ const test = new JasmineTestTool(done);
+ test.do(() => planetFn().item(0).checked = false);
+ test.do(() => planetFn().item(1).checked = false);
+ test.do(() => planetFn().item(2).checked = true); // Jupiter.
+ test.do(() => planetFn().item(2).dispatchEvent(new Event("change", {bubbles: true})));
+ test.wait(() => moonsFn() &&
+ moonsFn().item(0).textContent === "Europa"
+ && moonsFn().item(1).textContent === "Ganymed"
+ && moonsFn().item(2).textContent === "Io"
+ && moonsFn().item(3).textContent === "Kallisto"
+ );
+ test.do(() => expect(moonsFn().item(0).textContent).toBe("Europa"));
+ test.do(() => expect(moonsFn().item(1).textContent).toBe("Ganymed"));
+ test.do(() => expect(moonsFn().item(2).textContent).toBe("Io"));
+ test.do(() => expect(moonsFn().item(3).textContent).toBe("Kallisto"));
+ test.start()
});
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/script/jasmine-3.5.0/boot.js b/tobago-example/tobago-example-demo/src/main/webapp/script/jasmine-3.5.0/boot.js
index b438fb8..76fc879 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/script/jasmine-3.5.0/boot.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/script/jasmine-3.5.0/boot.js
@@ -16,6 +16,7 @@
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
*/
window.jasmine = jasmineRequire.core(jasmineRequire);
+ jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000;
/**
* Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/script/tobago-test.js b/tobago-example/tobago-example-demo/src/main/webapp/script/tobago-test.js
index 991ccb3..d6d01a6 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/script/tobago-test.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/script/tobago-test.js
@@ -15,6 +15,18 @@
* limitations under the License.
*/
+function querySelectorFn(expression) {
+ return function () {
+ return document.getElementById("page:testframe").contentWindow.document.querySelector(expression);
+ }
+}
+
+function querySelectorAllFn(expression) {
+ return function () {
+ return document.getElementById("page:testframe").contentWindow.document.querySelectorAll(expression);
+ }
+}
+
function testFrameQuerySelectorFn(expression) {
return function () {
return document.getElementById("page:testframe").contentWindow.document.querySelector(expression);
@@ -27,7 +39,7 @@ function testFrameQuerySelectorAllFn(expression) {
}
}
-export {testFrameQuerySelectorFn, testFrameQuerySelectorAllFn};
+export {querySelectorFn, querySelectorAllFn, testFrameQuerySelectorFn, testFrameQuerySelectorAllFn};
QUnit.test("wait for test", function (assert) {
let done = assert.async();
diff --git a/tobago-tool/tobago-tool-test/src/main/resources/META-INF/resources/tobago/test/tobago-test-tool.js b/tobago-tool/tobago-tool-test/src/main/resources/META-INF/resources/tobago/test/tobago-test-tool.js
index a2c8601..52e7fff 100644
--- a/tobago-tool/tobago-tool-test/src/main/resources/META-INF/resources/tobago/test/tobago-test-tool.js
+++ b/tobago-tool/tobago-tool-test/src/main/resources/META-INF/resources/tobago/test/tobago-test-tool.js
@@ -225,3 +225,97 @@ TobagoTestTool.prototype = {
};
export {TobagoTestTool};
+
+class JasmineTestTool {
+
+ steps = [];
+ cycleTiming = 50;
+ done;
+ timeout;
+ lastStepExecution;
+
+ constructor(done, timeout) {
+ this.done = done; //done function from Jasmine; must called if all Steps done or timeout
+ this.timeout = timeout ? timeout : 20000; //timeout for a single step
+ }
+
+ do(fn) {
+ this.steps.push({
+ type: "do",
+ func: fn,
+ done: false
+ });
+ }
+
+ wait(fn) {
+ this.steps.push({
+ type: "wait",
+ func: fn,
+ done: false
+ });
+ }
+
+ start() {
+ this.resetTimeout();
+ this.cycle();
+ }
+
+ cycle() {
+ let nextStep = this.getNextStep();
+
+ if (this.isFinished()) {
+ this.done();
+ } else if (this.isTimeout()) {
+ fail("Timeout!");
+ this.done();
+ } else if (this.isStepValid(nextStep)) {
+ if (nextStep.type === "do") {
+ nextStep.func();
+ nextStep.done = true;
+ this.resetTimeout();
+ window.setTimeout(this.cycle.bind(this), this.cycleTiming);
+ } else if (nextStep.type === "wait") {
+ if (nextStep.func()) {
+ nextStep.done = true;
+ this.resetTimeout();
+ }
+ window.setTimeout(this.cycle.bind(this), this.cycleTiming);
+ }
+ } else {
+ fail("an unexpected error has occurred!");
+ this.done();
+ }
+ }
+
+ isFinished() {
+ for (let step of this.steps) {
+ if (!step.done) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ getNextStep() {
+ for (let step of this.steps) {
+ if (!step.done) {
+ return step;
+ }
+ }
+ return null;
+ }
+
+ isStepValid(step) {
+ return step && (step.type === "do" || step.type === "wait");
+ }
+
+ isTimeout() {
+ return Date.now() > (this.lastStepExecution + this.timeout);
+ }
+
+ resetTimeout() {
+ this.lastStepExecution = Date.now();
+ }
+}
+
+export {JasmineTestTool};