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/04/17 20:40:29 UTC
[myfaces-tobago] branch master updated: add a isAjaxReady check to
JasmineTestTool
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
The following commit(s) were added to refs/heads/master by this push:
new 8dca90b add a isAjaxReady check to JasmineTestTool
8dca90b is described below
commit 8dca90bb9bcdd4f3164557e058a3d2a8fef15fac
Author: Henning Nöth <hn...@apache.org>
AuthorDate: Fri Apr 17 22:39:10 2020 +0200
add a isAjaxReady check to JasmineTestTool
---
.../resources/tobago/test/tobago-test-tool.js | 35 +++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
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 b5e12e8..a9185b3 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
@@ -232,6 +232,8 @@ export {TobagoTestTool};
class JasmineTestTool {
+ static ajaxReadyStateChangeEvent = "tobago.jtt.ajax.readyStateChange";
+ static ajaxReadyState;
steps = [];
done;
timeout;
@@ -240,6 +242,7 @@ class JasmineTestTool {
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
+ this.registerAjaxReadyStateListener();
}
do(fn) {
@@ -273,9 +276,10 @@ class JasmineTestTool {
nextStep.done = true;
this.resetTimeout();
window.setTimeout(this.cycle.bind(this), 0);
- } else if (!this.isDocumentReady()) {
+ } else if (!this.isDocumentReady() || !this.isAjaxReady()) {
window.setTimeout(this.cycle.bind(this), 50);
} else if (nextStep.type === "do") {
+ this.registerCustomXmlHttpRequest();
nextStep.func();
nextStep.done = true;
this.resetTimeout();
@@ -305,6 +309,35 @@ class JasmineTestTool {
return document.getElementById("page:testframe").contentWindow.document.readyState === "complete";
}
+ registerAjaxReadyStateListener() {
+ JasmineTestTool.ajaxReadyState = XMLHttpRequest.UNSENT;
+ window.removeEventListener(JasmineTestTool.ajaxReadyStateChangeEvent, JasmineTestTool.changeAjaxReadyState);
+ window.addEventListener(JasmineTestTool.ajaxReadyStateChangeEvent, JasmineTestTool.changeAjaxReadyState);
+ }
+
+ static changeAjaxReadyState(event) {
+ JasmineTestTool.ajaxReadyState = event.detail.readyState;
+ }
+
+ registerCustomXmlHttpRequest() {
+ class JasmineXMLHttpRequest extends XMLHttpRequest {
+ constructor() {
+ super();
+ this.addEventListener("readystatechange", function () {
+ window.dispatchEvent(new CustomEvent(JasmineTestTool.ajaxReadyStateChangeEvent,
+ {detail: {readyState: this.readyState}}));
+ });
+ }
+ }
+
+ document.getElementById("page:testframe").contentWindow.XMLHttpRequest = JasmineXMLHttpRequest;
+ }
+
+ isAjaxReady() {
+ return JasmineTestTool.ajaxReadyState === XMLHttpRequest.UNSENT
+ || JasmineTestTool.ajaxReadyState === XMLHttpRequest.DONE;
+ }
+
getNextStep() {
for (let step of this.steps) {
if (!step.done) {