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 18:32:37 UTC

[myfaces-tobago] branch master updated (55eaa48 -> 329bb4a)

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 55eaa48  fix: action with target
     new 2e41090  test: behavior
     new a79c280  fix: tobago-test-tool
     new e4cbeb5  test: buttonLink
     new 329bb4a  test: message-layout

The 4 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  | 167 ++++-----
 .../900-test/4000-button-link/Button_Link.xhtml    |   2 +-
 .../500-message-layout/message-layout.xhtml        |  17 +-
 .../900-test/6500-behavior/Behavior.test.js        | 394 ++++++++++-----------
 .../resources/tobago/test/tobago-test-tool.js      |  16 +
 5 files changed, 297 insertions(+), 299 deletions(-)

[myfaces-tobago] 04/04: test: message-layout

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 329bb4ab4fd1691d1f2f3d78b86841d9152699af
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Wed Oct 20 20:05:35 2021 +0200

    test: message-layout
    
    * use static values for shuttle
---
 .../500-message-layout/message-layout.xhtml             | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4800-labelLayout/500-message-layout/message-layout.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4800-labelLayout/500-message-layout/message-layout.xhtml
index 2a49f0b..4ef29d9 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4800-labelLayout/500-message-layout/message-layout.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4800-labelLayout/500-message-layout/message-layout.xhtml
@@ -50,14 +50,17 @@
     </tc:section>
 
     <tc:section label="Shuttle">
-      <tc:selectManyShuttle id="shuttleCompare" label="Shuttle" value="#{selectManyShuttleController.selectedPlanets}">
-        <tc:selectItems value="#{selectManyShuttleController.planets}"
-                        var="planet" itemLabel="#{planet.name}" itemValue="#{planet}"/>
+      <tc:selectManyShuttle id="shuttleCompare" label="Shuttle">
+        <tc:selectItem itemLabel="Alpha"/>
+        <tc:selectItem itemLabel="Beta"/>
+        <tc:selectItem itemLabel="Gamma"/>
+        <tc:selectItem itemLabel="Delta"/>
       </tc:selectManyShuttle>
-      <tc:selectManyShuttle id="shuttle" label="Shuttle" value="#{selectManyShuttleController.selectedPlanets}"
-                            required="true">
-        <tc:selectItems value="#{selectManyShuttleController.planets}"
-                        var="planet" itemLabel="#{planet.name}" itemValue="#{planet}"/>
+      <tc:selectManyShuttle id="shuttle" label="Shuttle" required="true">
+        <tc:selectItem itemLabel="Alpha"/>
+        <tc:selectItem itemLabel="Beta"/>
+        <tc:selectItem itemLabel="Gamma"/>
+        <tc:selectItem itemLabel="Delta"/>
       </tc:selectManyShuttle>
     </tc:section>
   </tc:panel>

[myfaces-tobago] 01/04: test: behavior

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 2e4109052c45737925ffa76a46de55d86a975a4c
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Wed Oct 20 16:21:29 2021 +0200

    test: behavior
    
    * reimplemented
---
 .../900-test/6500-behavior/Behavior.test.js        | 394 ++++++++++-----------
 1 file changed, 184 insertions(+), 210 deletions(-)

diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/6500-behavior/Behavior.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/6500-behavior/Behavior.test.js
index 2e8c3eb..f47ba77 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/6500-behavior/Behavior.test.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/6500-behavior/Behavior.test.js
@@ -16,248 +16,222 @@
  */
 
 import {JasmineTestTool} from "/tobago/test/tobago-test-tool.js";
-
-it("must be fixed first", function (done) {
-  let test = new JasmineTestTool(done);
-  test.do(() => fail("not implemented yet"));
+import {elementByIdFn, querySelectorAllFn, querySelectorFn} from "/script/tobago-test.js";
+
+it("Simple Event", function (done) {
+  const buttonFn = elementByIdFn("page:mainForm:simpleEvent");
+  const oldCounterValues = getCounterValues();
+
+  const test = new JasmineTestTool(done);
+  test.event("click", buttonFn, () => getCounterValues().action1 > oldCounterValues.action1)
+  test.do(() => expect(getCounterValues().buttonAction).toBe(oldCounterValues.buttonAction));
+  test.do(() => expect(getCounterValues().buttonActionListener).toBe(oldCounterValues.buttonActionListener));
+  test.do(() => expect(getCounterValues().action1).toBe(oldCounterValues.action1 + 1));
+  test.do(() => expect(getCounterValues().actionListener1).toBe(oldCounterValues.actionListener1 + 1));
+  test.do(() => expect(getCounterValues().ajaxListener1).toBe(oldCounterValues.ajaxListener1));
+  test.do(() => expect(getCounterValues().action2).toBe(oldCounterValues.action2));
+  test.do(() => expect(getCounterValues().actionListener2).toBe(oldCounterValues.actionListener2));
+  test.do(() => expect(getCounterValues().ajaxListener2).toBe(oldCounterValues.ajaxListener2));
+  test.do(() => expect(getCounterValues().action3).toBe(oldCounterValues.action3));
+  test.do(() => expect(getCounterValues().actionListener3).toBe(oldCounterValues.actionListener3));
+  test.do(() => expect(getCounterValues().ajaxListener3).toBe(oldCounterValues.ajaxListener3));
   test.start();
 });
 
-/*
-import {querySelectorAllFn, querySelectorFn} from "/script/tobago-test.js";
-import {TobagoTestTool} from "/tobago/test/tobago-test-tool.js";
-
-QUnit.test("Simple Event", function (assert) {
-  let buttonFn = querySelectorFn("#page\\:mainForm\\:simpleEvent");
-  let oldCounterValues = getCounterValues();
-
-  let TTT = new TobagoTestTool(assert);
-  TTT.action(function () {
-    buttonFn().dispatchEvent(new Event("click", {bubbles: true}));
-  });
-  TTT.waitForResponse();
-  TTT.asserts(11, function () {
-    compareCounterValues(assert, oldCounterValues, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0);
-  });
-  TTT.startTest();
-});
-
-QUnit.test("Simple Ajax", function (assert) {
-  let buttonFn = querySelectorFn("#page\\:mainForm\\:simpleAjax");
-  let oldCounterValues = getCounterValues();
-
-  let TTT = new TobagoTestTool(assert);
-  TTT.action(function () {
-    buttonFn().dispatchEvent(new Event("click", {bubbles: true}));
-  });
-  TTT.waitForResponse();
-  TTT.asserts(11, function () {
-    compareCounterValues(assert, oldCounterValues, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0);
-  });
-  TTT.startTest();
+it("Simple Ajax", function (done) {
+  const buttonFn = elementByIdFn("page:mainForm:simpleAjax");
+  const oldCounterValues = getCounterValues();
+
+  const test = new JasmineTestTool(done);
+  test.event("click", buttonFn, () => getCounterValues().ajaxListener1 > oldCounterValues.ajaxListener1)
+  test.do(() => expect(getCounterValues().buttonAction).toBe(oldCounterValues.buttonAction));
+  test.do(() => expect(getCounterValues().buttonActionListener).toBe(oldCounterValues.buttonActionListener));
+  test.do(() => expect(getCounterValues().action1).toBe(oldCounterValues.action1));
+  test.do(() => expect(getCounterValues().actionListener1).toBe(oldCounterValues.actionListener1));
+  test.do(() => expect(getCounterValues().ajaxListener1).toBe(oldCounterValues.ajaxListener1 + 1));
+  test.do(() => expect(getCounterValues().action2).toBe(oldCounterValues.action2));
+  test.do(() => expect(getCounterValues().actionListener2).toBe(oldCounterValues.actionListener2));
+  test.do(() => expect(getCounterValues().ajaxListener2).toBe(oldCounterValues.ajaxListener2));
+  test.do(() => expect(getCounterValues().action3).toBe(oldCounterValues.action3));
+  test.do(() => expect(getCounterValues().actionListener3).toBe(oldCounterValues.actionListener3));
+  test.do(() => expect(getCounterValues().ajaxListener3).toBe(oldCounterValues.ajaxListener3));
+  test.start();
 });
 
-QUnit.test("Simple EventAjax", function (assert) {
-  let buttonFn = querySelectorFn("#page\\:mainForm\\:simpleEventAjax");
-  let oldCounterValues = getCounterValues();
-
-  let TTT = new TobagoTestTool(assert);
-  TTT.action(function () {
-    buttonFn().dispatchEvent(new Event("click", {bubbles: true}));
-  });
-  TTT.waitForResponse();
-  TTT.asserts(11, function () {
-    compareCounterValues(assert, oldCounterValues, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0);
-  });
-  TTT.startTest();
+it("Simple EventAjax", function (done) {
+  const buttonFn = elementByIdFn("page:mainForm:simpleEventAjax");
+  const oldCounterValues = getCounterValues();
+
+  const test = new JasmineTestTool(done);
+  test.event("click", buttonFn, () => getCounterValues().ajaxListener1 > oldCounterValues.ajaxListener1)
+  test.do(() => expect(getCounterValues().buttonAction).toBe(oldCounterValues.buttonAction));
+  test.do(() => expect(getCounterValues().buttonActionListener).toBe(oldCounterValues.buttonActionListener));
+  test.do(() => expect(getCounterValues().action1).toBe(oldCounterValues.action1));
+  test.do(() => expect(getCounterValues().actionListener1).toBe(oldCounterValues.actionListener1));
+  test.do(() => expect(getCounterValues().ajaxListener1).toBe(oldCounterValues.ajaxListener1 + 1));
+  test.do(() => expect(getCounterValues().action2).toBe(oldCounterValues.action2));
+  test.do(() => expect(getCounterValues().actionListener2).toBe(oldCounterValues.actionListener2));
+  test.do(() => expect(getCounterValues().ajaxListener2).toBe(oldCounterValues.ajaxListener2));
+  test.do(() => expect(getCounterValues().action3).toBe(oldCounterValues.action3));
+  test.do(() => expect(getCounterValues().actionListener3).toBe(oldCounterValues.actionListener3));
+  test.do(() => expect(getCounterValues().ajaxListener3).toBe(oldCounterValues.ajaxListener3));
+  test.start();
 });
 
-QUnit.test("Advanced Button: Option 1", function (assert) {
+it("Advanced Button: Option 1", function (done) {
   const optionId = 0; //Event 1 + no Ajax enabled
-  let buttonFn = querySelectorFn("#page\\:mainForm\\:advancedButton");
-  testEventOption(assert, optionId, buttonFn, "dblclick", 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0);
+  const buttonFn = elementByIdFn("page:mainForm:advancedButton");
+  const expectedCounterValues = getCounterValues();
+  expectedCounterValues.action1++;
+  expectedCounterValues.actionListener1++;
+
+  testAdvancedButton(done, optionId, buttonFn, "dblclick", expectedCounterValues);
 });
 
-QUnit.test("Advanced Button: Option 2", function (assert) {
+it("Advanced Button: Option 2", function (done) {
   const optionId = 1; //Event 2 + Ajax 3 enabled
-  let buttonFn = querySelectorFn("#page\\:mainForm\\:advancedButton");
-  testAjaxOption(assert, optionId, buttonFn, "dblclick", 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1);
+  const buttonFn = elementByIdFn("page:mainForm:advancedButton");
+  const expectedCounterValues = getCounterValues();
+  expectedCounterValues.buttonAction++;
+  expectedCounterValues.buttonActionListener++;
+  expectedCounterValues.ajaxListener3++;
+
+  testAdvancedButton(done, optionId, buttonFn, "dblclick", expectedCounterValues);
 });
 
-QUnit.test("Advanced Button: Option 3", function (assert) {
+it("Advanced Button: Option 3", function (done) {
   const optionId = 2; //Event 3 + all Ajax enabled
-  let buttonFn = querySelectorFn("#page\\:mainForm\\:advancedButton");
-  testAjaxOption(assert, optionId, buttonFn, "click", 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1);
+  const buttonFn = elementByIdFn("page:mainForm:advancedButton");
+  const expectedCounterValues = getCounterValues();
+  expectedCounterValues.buttonAction++;
+  expectedCounterValues.buttonActionListener++;
+  expectedCounterValues.ajaxListener1++;
+  expectedCounterValues.ajaxListener2++;
+  expectedCounterValues.ajaxListener3++;
+
+  testAdvancedButton(done, optionId, buttonFn, "click", expectedCounterValues);
 });
 
-QUnit.test("Row: Option 1", function (assert) {
+it("Row: Option 1", function (done) {
   const optionId = 0; //Event 1 + no Ajax enabled
-  let rowFn = querySelectorFn("#page\\:mainForm\\:sheet\\:0\\:row");
-  testEventOption(assert, optionId, rowFn, "dblclick", 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0);
+  const rowFn = elementByIdFn("page:mainForm:sheet:0:row");
+  const expectedCounterValues = getCounterValues();
+  expectedCounterValues.action1++;
+  expectedCounterValues.actionListener1++;
+
+  testAdvancedButton(done, optionId, rowFn, "dblclick", expectedCounterValues);
 });
 
-QUnit.test("Row: Option 2", function (assert) {
+it("Row: Option 2", function (done) {
   const optionId = 1; //Event 2 + Ajax 3 enabled
-  let rowFn = querySelectorFn("#page\\:mainForm\\:sheet\\:0\\:row");
-  testAjaxOption(assert, optionId, rowFn, "dblclick", 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1);
-});
+  const rowFn = elementByIdFn("page:mainForm:sheet:0:row");
+  const expectedCounterValues = getCounterValues();
+  expectedCounterValues.action2++;
+  expectedCounterValues.actionListener2++;
+  expectedCounterValues.ajaxListener3++;
 
-QUnit.test("Row: Option 3", function (assert) {
-  const optionId = 2; //Event 3 + all Ajax enabled
-  let rowFn = querySelectorFn("#page\\:mainForm\\:sheet\\:0\\:row");
-  testAjaxOption(assert, optionId, rowFn, "click", 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1);
+  testAdvancedButton(done, optionId, rowFn, "dblclick", expectedCounterValues);
 });
 
-QUnit.test("Input: Click Event", function (assert) {
-  let inputFn = querySelectorFn("#page\\:mainForm\\:inputClick\\:\\:field");
-  testInputSection(assert, inputFn, "click");
+it("Row: Option 3", function (done) {
+  const optionId = 2; //Event 3 + all Ajax enabled
+  const rowFn = elementByIdFn("page:mainForm:sheet:0:row");
+  const expectedCounterValues = getCounterValues();
+  expectedCounterValues.ajaxListener1++;
+  expectedCounterValues.ajaxListener2++;
+  expectedCounterValues.action3++;
+  expectedCounterValues.actionListener3++;
+  expectedCounterValues.ajaxListener3++;
+
+  testAdvancedButton(done, optionId, rowFn, "click", expectedCounterValues);
 });
 
-function testEventOption(assert, optionId, componentFn, eventName,
-                         buttonActionPlus, buttonActionListenerPlus,
-                         action1Plus, actionListener1Plus, ajaxListener1Plus,
-                         action2Plus, actionListener2Plus, ajaxListener2Plus,
-                         action3Plus, actionListener3Plus, ajaxListener3Plus) {
-  let hideFn = querySelectorFn("#page\\:mainForm\\:hideOperationTextBox");
-  let operationOutFn = querySelectorFn("#page\\:mainForm\\:operationOut");
-  let oldCounterValues = getCounterValues();
-  let optionsFn = querySelectorAllFn("#page\\:mainForm\\:advancedSelector input[type='radio']");
-
-  let TTT = new TobagoTestTool(assert);
-  TTT.action(function () {
-    hideFn().dispatchEvent(new Event("click", {bubbles: true}));
-  });
-  TTT.waitForResponse();
-  TTT.asserts(1, function () {
-    assert.equal(operationOutFn(), null, "Content of operation test box must be hidden.");
-  });
-  TTT.action(function () {
-    optionsFn().item(0).checked = false;
-    optionsFn().item(1).checked = false;
-    optionsFn().item(2).checked = false;
-    optionsFn().item(optionId).checked = true;
-    optionsFn().item(optionId).dispatchEvent(new Event("change", {bubbles: true}));
-  });
-  TTT.waitForResponse();
-  TTT.action(function () {
-    componentFn().dispatchEvent(new Event(eventName));
-  });
-  TTT.waitForResponse();
-  TTT.asserts(12, function () {
-    assert.notEqual(operationOutFn(), null, "Content of operation test box must be shown.");
-
-    compareCounterValues(assert, oldCounterValues,
-        buttonActionPlus, buttonActionListenerPlus,
-        action1Plus, actionListener1Plus, ajaxListener1Plus,
-        action2Plus, actionListener2Plus, ajaxListener2Plus,
-        action3Plus, actionListener3Plus, ajaxListener3Plus);
-  });
-  TTT.startTest();
-}
-
-function testAjaxOption(assert, optionId, componentFn, eventName,
-                        buttonActionPlus, buttonActionListenerPlus,
-                        action1Plus, actionListener1Plus, ajaxListener1Plus,
-                        action2Plus, actionListener2Plus, ajaxListener2Plus,
-                        action3Plus, actionListener3Plus, ajaxListener3Plus) {
-  let hideFn = querySelectorFn("#page\\:mainForm\\:hideOperationTextBox");
-  let operationOutFn = querySelectorFn("#page\\:mainForm\\:operationOut");
-  let oldCounterValues = getCounterValues();
-  let optionsFn = querySelectorAllFn("#page\\:mainForm\\:advancedSelector input[type='radio']");
-
-  let TTT = new TobagoTestTool(assert);
-  TTT.action(function () {
-    hideFn().dispatchEvent(new Event("click", {bubbles: true}));
-  });
-  TTT.waitForResponse();
-  TTT.asserts(1, function () {
-    assert.equal(operationOutFn(), null, "Content of operation test box must be hidden.");
-  });
-  TTT.action(function () {
-    optionsFn().item(0).checked = false;
-    optionsFn().item(1).checked = false;
-    optionsFn().item(2).checked = false;
-    optionsFn().item(optionId).checked = true;
-    optionsFn().item(optionId).dispatchEvent(new Event("change", {bubbles: true}));
-  });
-  TTT.waitForResponse();
-  TTT.action(function () {
-    componentFn().dispatchEvent(new Event(eventName));
-  });
-  TTT.waitForResponse();
-  TTT.asserts(12, function () {
-    assert.notEqual(operationOutFn(), null, "Content of operation test box must be shown.");
+it("Input: Click Event", function (done) {
+  const inputFn = elementByIdFn("page:mainForm:inputClick::field");
+  const hideFn = querySelectorFn("#page\\:mainForm\\:hideOperationTextBox");
+  const operationOutFn = querySelectorFn("#page\\:mainForm\\:operationOut");
 
-    compareCounterValues(assert, oldCounterValues,
-        buttonActionPlus, buttonActionListenerPlus,
-        action1Plus, actionListener1Plus, ajaxListener1Plus,
-        action2Plus, actionListener2Plus, ajaxListener2Plus,
-        action3Plus, actionListener3Plus, ajaxListener3Plus);
-  });
-  TTT.startTest();
-}
+  const test = new JasmineTestTool(done);
+  test.setup(() => operationOutFn() === null, null, "click", hideFn);
+  test.do(() => expect(operationOutFn()).toBeNull());
+  test.event("click", inputFn, () => operationOutFn() !== null);
+  test.do(() => expect(operationOutFn()).not.toBeNull());
+  test.start();
+});
 
-function testInputSection(assert, inputFn, eventName) {
-  let hideFn = querySelectorFn("#page\\:mainForm\\:hideOperationTextBox");
-  let operationOutFn = querySelectorFn("#page\\:mainForm\\:operationOut");
+function testAdvancedButton(done, optionId, componentFn, eventType, expectedCounterValues) {
+  const hideFn = elementByIdFn("page:mainForm:hideOperationTextBox");
+  const operationOutFn = elementByIdFn("page:mainForm:operationOut");
+  const optionsFn = querySelectorAllFn("#page\\:mainForm\\:advancedSelector input[type='radio']");
+  const optionFn = elementByIdFn("page:mainForm:advancedSelector::" + optionId);
+
+  const test = new JasmineTestTool(done);
+  test.setup(() => operationOutFn() === null, null, "click", hideFn);
+  test.setup(() => optionsFn().item(optionId).checked,
+      () => {
+        optionsFn().item(0).checked = false;
+        optionsFn().item(1).checked = false;
+        optionsFn().item(2).checked = false;
+        optionsFn().item(optionId).checked = true;
+      }, "change", optionFn);
+  test.do(() => expect(operationOutFn()).toBeNull());
+  test.do(() => expect(optionFn().checked).toBeTrue());
+
+  test.event(eventType, componentFn, () => operationOutFn() !== null);
+  test.do(() => expect(operationOutFn()).not.toBeNull());
+  test.do(() => expect(getCounterValues().buttonAction).toBe(expectedCounterValues.buttonAction));
+  test.do(() => expect(getCounterValues().buttonActionListener).toBe(expectedCounterValues.buttonActionListener));
+  test.do(() => expect(getCounterValues().action1).toBe(expectedCounterValues.action1));
+  test.do(() => expect(getCounterValues().actionListener1).toBe(expectedCounterValues.actionListener1));
+  test.do(() => expect(getCounterValues().ajaxListener1).toBe(expectedCounterValues.ajaxListener1));
+  test.do(() => expect(getCounterValues().action2).toBe(expectedCounterValues.action2));
+  test.do(() => expect(getCounterValues().actionListener2).toBe(expectedCounterValues.actionListener2));
+  test.do(() => expect(getCounterValues().ajaxListener2).toBe(expectedCounterValues.ajaxListener2));
+  test.do(() => expect(getCounterValues().action3).toBe(expectedCounterValues.action3));
+  test.do(() => expect(getCounterValues().actionListener3).toBe(expectedCounterValues.actionListener3));
+  test.do(() => expect(getCounterValues().ajaxListener3).toBe(expectedCounterValues.ajaxListener3));
 
-  let TTT = new TobagoTestTool(assert);
-  TTT.action(function () {
-    hideFn().dispatchEvent(new Event("click", {bubbles: true}));
-  });
-  TTT.waitForResponse();
-  TTT.asserts(1, function () {
-    assert.ok(operationOutFn() === null, "Content of operation test box must be hidden.");
-  });
-  TTT.action(function () {
-    inputFn().dispatchEvent(new Event(eventName));
-  });
-  TTT.waitForResponse();
-  TTT.asserts(1, function () {
-    assert.notOk(operationOutFn() === null, "Content of operation test box must be shown.");
-  });
-  TTT.startTest();
+  test.start();
 }
 
 function getCounterValues() {
-  let buttonActionCounter = querySelectorFn("#page\\:mainForm\\:buttonActionCounter.tobago-out")().textContent;
-  let buttonActionListenerCounter = querySelectorFn("#page\\:mainForm\\:buttonActionListenerCounter.tobago-out")().textContent;
-
-  let actionCount1 = querySelectorFn("#page\\:mainForm\\:actionCounter1.tobago-out")().textContent;
-  let actionListenerCount1 = querySelectorFn("#page\\:mainForm\\:actionListenerCounter1.tobago-out")().textContent;
-  let ajaxListenerCount1 = querySelectorFn("#page\\:mainForm\\:ajaxListenerCounter1.tobago-out")().textContent;
-
-  let actionCount2 = querySelectorFn("#page\\:mainForm\\:actionCounter2.tobago-out")().textContent;
-  let actionListenerCount2 = querySelectorFn("#page\\:mainForm\\:actionListenerCounter2.tobago-out")().textContent;
-  let ajaxListenerCount2 = querySelectorFn("#page\\:mainForm\\:ajaxListenerCounter2.tobago-out")().textContent;
-
-  let actionCount3 = querySelectorFn("#page\\:mainForm\\:actionCounter3.tobago-out")().textContent;
-  let actionListenerCount3 = querySelectorFn("#page\\:mainForm\\:actionListenerCounter3.tobago-out")().textContent;
-  let ajaxListenerCount3 = querySelectorFn("#page\\:mainForm\\:ajaxListenerCounter3.tobago-out")().textContent;
-
-  return [buttonActionCounter, buttonActionListenerCounter,
-    actionCount1, actionListenerCount1, ajaxListenerCount1,
-    actionCount2, actionListenerCount2, ajaxListenerCount2,
-    actionCount3, actionListenerCount3, ajaxListenerCount3]
+  const buttonActionCounter = intValueFromOutput("#page\\:mainForm\\:buttonActionCounter");
+  const buttonActionListenerCounter = intValueFromOutput("#page\\:mainForm\\:buttonActionListenerCounter");
+  const actionCount1 = intValueFromOutput("#page\\:mainForm\\:actionCounter1");
+  const actionListenerCount1 = intValueFromOutput("#page\\:mainForm\\:actionListenerCounter1");
+  const ajaxListenerCount1 = intValueFromOutput("#page\\:mainForm\\:ajaxListenerCounter1");
+  const actionCount2 = intValueFromOutput("#page\\:mainForm\\:actionCounter2");
+  const actionListenerCount2 = intValueFromOutput("#page\\:mainForm\\:actionListenerCounter2");
+  const ajaxListenerCount2 = intValueFromOutput("#page\\:mainForm\\:ajaxListenerCounter2");
+  const actionCount3 = intValueFromOutput("#page\\:mainForm\\:actionCounter3");
+  const actionListenerCount3 = intValueFromOutput("#page\\:mainForm\\:actionListenerCounter3");
+  const ajaxListenerCount3 = intValueFromOutput("#page\\:mainForm\\:ajaxListenerCounter3");
+
+  return new CounterValues(buttonActionCounter, buttonActionListenerCounter,
+      actionCount1, actionListenerCount1, ajaxListenerCount1,
+      actionCount2, actionListenerCount2, ajaxListenerCount2,
+      actionCount3, actionListenerCount3, ajaxListenerCount3);
 }
 
-function compareCounterValues(assert, oldCounterValues,
-                              buttonActionPlus, buttonActionListenerPlus,
-                              action1Plus, actionListener1Plus, ajaxListener1Plus,
-                              action2Plus, actionListener2Plus, ajaxListener2Plus,
-                              action3Plus, actionListener3Plus, ajaxListener3Plus) {
-  let newCounterValues = getCounterValues();
+function intValueFromOutput(expression) {
+  return parseInt(querySelectorFn(expression + " .form-control-plaintext")().textContent);
+}
 
-  assert.equal(parseInt(newCounterValues[0]), parseInt(oldCounterValues[0]) + buttonActionPlus);
-  assert.equal(parseInt(newCounterValues[1]), parseInt(oldCounterValues[1]) + buttonActionListenerPlus);
-  assert.equal(parseInt(newCounterValues[2]), parseInt(oldCounterValues[2]) + action1Plus);
-  assert.equal(parseInt(newCounterValues[3]), parseInt(oldCounterValues[3]) + actionListener1Plus);
-  assert.equal(parseInt(newCounterValues[4]), parseInt(oldCounterValues[4]) + ajaxListener1Plus);
-  assert.equal(parseInt(newCounterValues[5]), parseInt(oldCounterValues[5]) + action2Plus);
-  assert.equal(parseInt(newCounterValues[6]), parseInt(oldCounterValues[6]) + actionListener2Plus);
-  assert.equal(parseInt(newCounterValues[7]), parseInt(oldCounterValues[7]) + ajaxListener2Plus);
-  assert.equal(parseInt(newCounterValues[8]), parseInt(oldCounterValues[8]) + action3Plus);
-  assert.equal(parseInt(newCounterValues[9]), parseInt(oldCounterValues[9]) + actionListener3Plus);
-  assert.equal(parseInt(newCounterValues[10]), parseInt(oldCounterValues[10]) + ajaxListener3Plus);
+class CounterValues {
+  constructor(buttonAction, buttonActionListener,
+              action1, actionListener1, ajaxListener1,
+              action2, actionListener2, ajaxListener2,
+              action3, actionListener3, ajaxListener3) {
+    this.buttonAction = buttonAction;
+    this.buttonActionListener = buttonActionListener;
+    this.action1 = action1;
+    this.actionListener1 = actionListener1;
+    this.ajaxListener1 = ajaxListener1;
+    this.action2 = action2;
+    this.actionListener2 = actionListener2;
+    this.ajaxListener2 = ajaxListener2;
+    this.action3 = action3;
+    this.actionListener3 = actionListener3;
+    this.ajaxListener3 = ajaxListener3;
+  }
 }
-*/

[myfaces-tobago] 02/04: 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 master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit a79c280754acf21516c6dc90ed71265392c371dc
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] 03/04: 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 master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

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

    test: buttonLink
    
    * reimplemented
    * adjust xhtml
---
 .../900-test/4000-button-link/Button_Link.test.js  | 167 +++++++++++----------
 .../900-test/4000-button-link/Button_Link.xhtml    |   2 +-
 2 files changed, 87 insertions(+), 82 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..dc29061 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,112 @@
  */
 
 import {JasmineTestTool} from "/tobago/test/tobago-test-tool.js";
+import {elementByIdFn, querySelectorFn} 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) {
-  assert.expect(3);
+function getTargetFrameInput() {
+  return elementByIdFn("page:mainForm:targetFrame")().contentWindow
+      .document.getElementById("textInput");
+}
 
-  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");
+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 = elementByIdFn("page:mainForm:dropdownWithStyle::command");
 
-  assert.ok(dropdownMenuFn() !== null);
-  assert.equal(styleAsItemFn(), null);
-  assert.equal(buttonFn().offsetWidth, 200);
+  const test = new JasmineTestTool(done);
+  test.do(() => expect(dropdownMenuFn()).not.toBeNull());
+  test.do(() => expect(styleAsItemFn()).toBeNull());
+  test.do(() => expect(buttonFn().offsetWidth).toEqual(200));
+  test.start();
 });
-
-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;
-}
-*/
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>