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 2021/10/20 17:03:26 UTC

[myfaces-tobago] branch tobago-5.x updated (ed58007 -> 560785e)

This is an automated email from the ASF dual-hosted git repository.

hnoeth pushed a change to branch tobago-5.x
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git.


    from ed58007  test: behavior
     new 6503cc3  fix: tobago-test-tool
     new 6a8e7ba  test: buttonLink
     new 560785e  test: buttonLink

The 3 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:
 .../900-test/4000-button-link/Button_Link.test.js  | 165 +++++++++++----------
 .../900-test/4000-button-link/Button_Link.xhtml    |   2 +-
 .../resources/tobago/test/tobago-test-tool.js      |  16 ++
 3 files changed, 101 insertions(+), 82 deletions(-)

[myfaces-tobago] 01/03: fix: tobago-test-tool

Posted by hn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hnoeth pushed a commit to branch tobago-5.x
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit 6503cc391b3f39f21b4f4e3babb61f7986128109
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Wed Oct 20 18:26:38 2021 +0200

    fix: tobago-test-tool
    
    * use click() for links
---
 .../META-INF/resources/tobago/test/tobago-test-tool.js   | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

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 0c7a56c..c550dfc 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
@@ -85,6 +85,14 @@ class JasmineTestTool {
     let eventFn;
     if (typeof eventElement !== "function") {
       eventFn = () => fail("'eventElement' must be a function but was: " + eventElement);
+    } else if (eventType === "click") {
+      eventFn = () => {
+        if (eventElement().getAttribute("href")) {
+          eventElement().click(); //links are only executed with 'click()'
+        } else {
+          eventElement().dispatchEvent(new Event(eventType, {bubbles: true}))
+        }
+      }
     } else {
       eventFn = () => eventElement().dispatchEvent(new Event(eventType, {bubbles: true}));
     }
@@ -109,6 +117,14 @@ class JasmineTestTool {
     let eventFn;
     if (typeof element !== "function") {
       eventFn = () => fail("'element' must be a function but was: " + element);
+    } else if (type === "click") {
+      eventFn = () => {
+        if (element().getAttribute("href")) {
+          element().click(); //links are only executed with 'click()'
+        } else {
+          element().dispatchEvent(new Event(type, {bubbles: true}))
+        }
+      }
     } else {
       eventFn = () => element().dispatchEvent(new Event(type, {bubbles: true}));
     }

[myfaces-tobago] 02/03: test: buttonLink

Posted by hn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hnoeth pushed a commit to branch tobago-5.x
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit 6a8e7baf12a5cc07d2dbc3f270396359c7996138
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Wed Oct 20 18:29:42 2021 +0200

    test: buttonLink
    
    * reimplemented
---
 .../900-test/4000-button-link/Button_Link.test.js  | 160 +++++++++++----------
 1 file changed, 84 insertions(+), 76 deletions(-)

diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4000-button-link/Button_Link.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4000-button-link/Button_Link.test.js
index 2868cc2..c4ec7d2 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4000-button-link/Button_Link.test.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4000-button-link/Button_Link.test.js
@@ -16,107 +16,115 @@
  */
 
 import {JasmineTestTool} from "/tobago/test/tobago-test-tool.js";
+import {elementByIdFn} from "/script/tobago-test.js";
 
-it("not implemented yet", function (done) {
-  let test = new JasmineTestTool(done);
-  test.do(() => fail("must be fixed first"));
-  test.start();
+it("Standard Action Button", function (done) {
+  const commandFn = elementByIdFn("page:mainForm:standardButtonAction");
+  const destinationSectionFn = elementByIdFn("page:actionSection");
+  testStandardCommands(done, commandFn, destinationSectionFn);
 });
-/*
-import {querySelectorFn} from "/script/tobago-test.js";
-import {TobagoTestTool} from "/tobago/test/tobago-test-tool.js";
 
-QUnit.test("Standard Action Button", function (assert) {
-  let commandFn = querySelectorFn("#page\\:mainForm\\:standardButtonAction");
-  let destinationSectionFn = querySelectorFn("#page\\:actionSection");
-  testStandardCommands(commandFn, destinationSectionFn, assert);
+it("Standard Link Button", function (done) {
+  const commandFn = elementByIdFn("page:mainForm:standardButtonLink");
+  const destinationSectionFn = elementByIdFn("page:linkSection");
+  testStandardCommands(done, commandFn, destinationSectionFn);
 });
 
-QUnit.test("Standard Link Button", function (assert) {
-  let commandFn = querySelectorFn("#page\\:mainForm\\:standardButtonLink");
-  let destinationSectionFn = querySelectorFn("#page\\:linkSection");
-  testStandardCommands(commandFn, destinationSectionFn, assert);
+it("Standard Action Link", function (done) {
+  const commandFn = elementByIdFn("page:mainForm:standardLinkAction");
+  const destinationSectionFn = elementByIdFn("page:actionSection");
+  testStandardCommands(done, commandFn, destinationSectionFn);
 });
 
-QUnit.test("Standard Action Link", function (assert) {
-  let commandFn = querySelectorFn("#page\\:mainForm\\:standardLinkAction");
-  let destinationSectionFn = querySelectorFn("#page\\:actionSection");
-  testStandardCommands(commandFn, destinationSectionFn, assert);
+it("Standard Link Link", function (done) {
+  const commandFn = elementByIdFn("page:mainForm:standardLinkLink");
+  const destinationSectionFn = elementByIdFn("page:linkSection");
+  testStandardCommands(done, commandFn, destinationSectionFn);
 });
 
-QUnit.test("Standard Link Link", function (assert) {
-  let commandFn = querySelectorFn("#page\\:mainForm\\:standardLinkLink");
-  let destinationSectionFn = querySelectorFn("#page\\:linkSection");
-  testStandardCommands(commandFn, destinationSectionFn, assert);
-});
+function testStandardCommands(done, commandFn, destinationSectionFn) {
+  const backFn = elementByIdFn("page:back");
 
-function testStandardCommands(commandFn, destinationSectionFn, assert) {
-  let backFn = querySelectorFn("#page\\:back");
-
-  let TTT = new TobagoTestTool(assert);
-  TTT.action(function () {
-    commandFn().dispatchEvent(new Event("click", {bubbles: true}));
-  });
-  TTT.waitForResponse();
-  TTT.asserts(1, function () {
-    assert.ok(destinationSectionFn() !== null);
-  });
-  TTT.action(function () {
-    backFn().dispatchEvent(new Event("click", {bubbles: true}));
-  });
-  TTT.waitForResponse();
-  TTT.asserts(1, function () {
-    assert.ok(commandFn() !== null);
-  });
-  TTT.startTest();
+  const test = new JasmineTestTool(done);
+  test.event("click", commandFn, () => destinationSectionFn() !== null);
+  test.do(() => expect(destinationSectionFn()).not.toBeNull());
+  test.event("click", backFn, () => commandFn() !== null);
+  test.do(() => expect(commandFn()).not.toBeNull());
+  test.start();
 }
 
-QUnit.test("Target Action Button", function (assert) {
-  let commandFn = querySelectorFn("#page\\:mainForm\\:targetButtonAction");
-  testTargetCommands(commandFn, "accessed by action", assert);
+it("Target Action Button", function (done) {
+  const actionFn = elementByIdFn("page:mainForm:targetButtonAction");
+  const linkFn = elementByIdFn("page:mainForm:targetButtonLink");
+  const expectedValue = "accessed by action";
+
+  const test = new JasmineTestTool(done);
+  test.setup(() => getTargetFrameInput() !== null && getTargetFrameInput().value !== expectedValue,
+      null, "click", linkFn);
+  test.event("click", actionFn,
+      () => getTargetFrameInput() !== null && getTargetFrameInput().value === expectedValue);
+  test.do(() => expect(getTargetFrameInput().value).toBe(expectedValue));
+  test.start();
 });
 
-QUnit.test("Target Link Button", function (assert) {
-  let commandFn = querySelectorFn("#page\\:mainForm\\:targetButtonLink");
-  testTargetCommands(commandFn, "accessed by link", assert);
+it("Target Link Button", function (done) {
+  const actionFn = elementByIdFn("page:mainForm:targetButtonAction");
+  const linkFn = elementByIdFn("page:mainForm:targetButtonLink");
+  const expectedValue = "accessed by link";
+
+  const test = new JasmineTestTool(done);
+  test.setup(() => getTargetFrameInput() !== null && getTargetFrameInput().value !== expectedValue,
+      null, "click", actionFn);
+  test.event("click", linkFn,
+      () => getTargetFrameInput() !== null && getTargetFrameInput().value === expectedValue);
+  test.do(() => expect(getTargetFrameInput().value).toBe(expectedValue));
+  test.start();
 });
 
-QUnit.test("Target Action Link", function (assert) {
-  let commandFn = querySelectorFn("#page\\:mainForm\\:targetLinkAction");
-  testTargetCommands(commandFn, "accessed by action", assert);
+it("Target Action Link", function (done) {
+  const actionFn = elementByIdFn("page:mainForm:targetLinkAction");
+  const linkFn = elementByIdFn("page:mainForm:targetLinkLink");
+  const expectedValue = "accessed by action";
+
+  const test = new JasmineTestTool(done);
+  test.setup(() => getTargetFrameInput() !== null && getTargetFrameInput().value !== expectedValue,
+      null, "click", linkFn);
+  test.event("click", actionFn,
+      () => getTargetFrameInput() !== null && getTargetFrameInput().value === expectedValue);
+  test.do(() => expect(getTargetFrameInput().value).toBe(expectedValue));
+  test.start();
 });
 
-QUnit.test("Target Link Link", function (assert) {
-  let commandFn = querySelectorFn("#page\\:mainForm\\:targetLinkLink");
-  testTargetCommands(commandFn, "accessed by link", assert);
+it("Target Link Link", function (done) {
+  const actionFn = elementByIdFn("page:mainForm:targetLinkAction");
+  const linkFn = elementByIdFn("page:mainForm:targetLinkLink");
+  const expectedValue = "accessed by link";
+
+  const test = new JasmineTestTool(done);
+  test.setup(() => getTargetFrameInput() !== null && getTargetFrameInput().value !== expectedValue,
+      null, "click", actionFn);
+  test.event("click", linkFn,
+      () => getTargetFrameInput() !== null && getTargetFrameInput().value === expectedValue);
+  test.do(() => expect(getTargetFrameInput().value).toBe(expectedValue));
+  test.start();
 });
 
-QUnit.test("Style must not be a dropdown item", function (assert) {
+function getTargetFrameInput() {
+  return elementByIdFn("page:mainForm:targetFrame")().contentWindow
+      .document.getElementById("textInput");
+}
+
+
+/*it("Style must not be a dropdown item", function (done) {
   assert.expect(3);
 
-  let dropdownMenuFn = querySelectorFn("#page\\:mainForm\\:dropdownWithStyle .dropdown-menu");
-  let styleAsItemFn = querySelectorFn("#page\\:mainForm\\:dropdownWithStyle .dropdown-menu .dropdown-item > style");
-  let buttonFn = querySelectorFn("#page\\:mainForm\\:dropdownWithStyle > .tobago-button");
+  const dropdownMenuFn = querySelectorFn("#page\\:mainForm\\:dropdownWithStyle .dropdown-menu");
+  const styleAsItemFn = querySelectorFn("#page\\:mainForm\\:dropdownWithStyle .dropdown-menu .dropdown-item > style");
+  const buttonFn = querySelectorFn("#page\\:mainForm\\:dropdownWithStyle > .tobago-button");
 
   assert.ok(dropdownMenuFn() !== null);
   assert.equal(styleAsItemFn(), null);
   assert.equal(buttonFn().offsetWidth, 200);
-});
+});*/
 
-function testTargetCommands(commandFn, expectedText, assert) {
-  let TTT = new TobagoTestTool(assert);
-  TTT.action(function () {
-    commandFn().dispatchEvent(new Event("click", {bubbles: true}));
-  });
-  TTT.waitMs(2000); //TobagoTestTools.waitForResponse() didn't recognize responses on a target frame, so we just wait
-  TTT.asserts(1, function () {
-    assert.equal(getTargetFrameTestInputValue(), expectedText);
-  });
-  TTT.startTest();
-}
 
-function getTargetFrameTestInputValue() {
-  return querySelectorFn("#page\\:mainForm\\:targetFrame")().contentWindow
-      .document.querySelector("#textInput").value;
-}
-*/

[myfaces-tobago] 03/03: test: buttonLink

Posted by hn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hnoeth pushed a commit to branch tobago-5.x
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit 560785e7d62784acd6566fca058c7e3d494b4c25
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Wed Oct 20 19:02:24 2021 +0200

    test: buttonLink
    
    * reimplemented
    * adjust xhtml
---
 .../900-test/4000-button-link/Button_Link.test.js     | 19 +++++++------------
 .../900-test/4000-button-link/Button_Link.xhtml       |  2 +-
 2 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4000-button-link/Button_Link.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4000-button-link/Button_Link.test.js
index c4ec7d2..5fa95fa 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4000-button-link/Button_Link.test.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4000-button-link/Button_Link.test.js
@@ -16,7 +16,7 @@
  */
 
 import {JasmineTestTool} from "/tobago/test/tobago-test-tool.js";
-import {elementByIdFn} from "/script/tobago-test.js";
+import {elementByIdFn, querySelectorFn} from "/script/tobago-test.js";
 
 it("Standard Action Button", function (done) {
   const commandFn = elementByIdFn("page:mainForm:standardButtonAction");
@@ -114,17 +114,12 @@ function getTargetFrameInput() {
       .document.getElementById("textInput");
 }
 
-
-/*it("Style must not be a dropdown item", function (done) {
-  assert.expect(3);
-
+it("Style must not be a dropdown item", function (done) {
   const dropdownMenuFn = querySelectorFn("#page\\:mainForm\\:dropdownWithStyle .dropdown-menu");
   const styleAsItemFn = querySelectorFn("#page\\:mainForm\\:dropdownWithStyle .dropdown-menu .dropdown-item > style");
-  const buttonFn = querySelectorFn("#page\\:mainForm\\:dropdownWithStyle > .tobago-button");
-
-  assert.ok(dropdownMenuFn() !== null);
-  assert.equal(styleAsItemFn(), null);
-  assert.equal(buttonFn().offsetWidth, 200);
-});*/
-
+  const buttonFn = elementByIdFn("page:mainForm:dropdownWithStyle::command");
 
+  expect(dropdownMenuFn()).not.toBeNull();
+  expect(styleAsItemFn()).toBeNull();
+  expect(buttonFn().offsetWidth).toEqual(200);
+});
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4000-button-link/Button_Link.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4000-button-link/Button_Link.xhtml
index c66c9d2..61945eb 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4000-button-link/Button_Link.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4000-button-link/Button_Link.xhtml
@@ -88,7 +88,7 @@
 
   <tc:section label="Dropdown menu with tc:style">
     <tc:button id="dropdownWithStyle" label="200px Button" omit="true">
-      <tc:style width="200px"/>
+      <tc:style width="200px" selector="#page\:mainForm\:dropdownWithStyle\:\:command"/>
       <tc:link label="1" omit="true"/>
       <tc:link label="1" omit="true"/>
     </tc:button>