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:40 UTC

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

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>