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/14 11:15:24 UTC

[myfaces-tobago] 01/02: fix: message layout for input group, date and shuttle

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 499ce5f4cfed0aefee9e2f2503b9dd1be639c1ce
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Thu Oct 14 12:40:10 2021 +0200

    fix: message layout for input group, date and shuttle
    
    * add an integration test
---
 .../500-message-layout/message-layout.test.js      | 92 ++++++++++++++++++++++
 .../500-message-layout/message-layout.xhtml        | 64 +++++++++++++++
 tobago-theme/src/main/scss/_tobago.scss            |  6 ++
 3 files changed, 162 insertions(+)

diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4800-labelLayout/500-message-layout/message-layout.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4800-labelLayout/500-message-layout/message-layout.test.js
new file mode 100644
index 0000000..0a9d230
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4800-labelLayout/500-message-layout/message-layout.test.js
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+import {JasmineTestTool} from "/tobago/test/tobago-test-tool.js";
+import {elementByIdFn, querySelectorAllFn, querySelectorFn} from "/script/tobago-test.js";
+
+it("Input", function (done) {
+  const alertsFn = querySelectorAllFn(".tobago-messages .alert");
+  const submitFn = elementByIdFn("page:mainForm:submit");
+  const compareFn = elementByIdFn("page:mainForm:inCompare");
+  const labelFn = querySelectorFn("#page\\:mainForm\\:in label");
+  const inputFn = querySelectorFn("#page\\:mainForm\\:in input");
+  const popoverFn = querySelectorFn("#page\\:mainForm\\:in tobago-popover");
+
+  const test = new JasmineTestTool(done);
+  test.setup(() => alertsFn().length > 0, null, "click", submitFn);
+  test.do(() => expect(getFullWidth(compareFn())).toBeCloseTo(
+      getFullWidth(labelFn()) + getFullWidth(inputFn()) + getFullWidth(popoverFn())
+  ));
+  test.start();
+});
+
+it("Input Group", function (done) {
+  const alertsFn = querySelectorAllFn(".tobago-messages .alert");
+  const submitFn = elementByIdFn("page:mainForm:submit");
+  const compareFn = elementByIdFn("page:mainForm:inputGroupCompare");
+  const labelFn = querySelectorFn("#page\\:mainForm\\:inputGroup label");
+  const inputFn = querySelectorFn("#page\\:mainForm\\:inputGroup .input-group");
+  const popoverFn = querySelectorFn("#page\\:mainForm\\:inputGroup tobago-popover");
+
+  const test = new JasmineTestTool(done);
+  test.setup(() => alertsFn().length > 0, null, "click", submitFn);
+  test.do(() => expect(getFullWidth(compareFn())).toBeCloseTo(
+      getFullWidth(labelFn()) + getFullWidth(inputFn()) + getFullWidth(popoverFn())
+  ));
+  test.start();
+});
+
+it("Date", function (done) {
+  const alertsFn = querySelectorAllFn(".tobago-messages .alert");
+  const submitFn = elementByIdFn("page:mainForm:submit");
+  const compareFn = elementByIdFn("page:mainForm:dateCompare");
+  const labelFn = querySelectorFn("#page\\:mainForm\\:date label");
+  const inputFn = querySelectorFn("#page\\:mainForm\\:date input");
+  const popoverFn = querySelectorFn("#page\\:mainForm\\:date tobago-popover");
+
+  const test = new JasmineTestTool(done);
+  test.setup(() => alertsFn().length > 0, null, "click", submitFn);
+  test.do(() => expect(getFullWidth(compareFn())).toBeCloseTo(
+      getFullWidth(labelFn()) + getFullWidth(inputFn()) + getFullWidth(popoverFn())
+  ));
+  test.start();
+});
+
+it("Shuttle", function (done) {
+  const alertsFn = querySelectorAllFn(".tobago-messages .alert");
+  const submitFn = elementByIdFn("page:mainForm:submit");
+  const compareFn = elementByIdFn("page:mainForm:shuttleCompare");
+  const labelFn = querySelectorFn("#page\\:mainForm\\:shuttle label");
+  const inputFn = querySelectorFn("#page\\:mainForm\\:shuttle .tobago-selectManyShuttle");
+  const popoverFn = querySelectorFn("#page\\:mainForm\\:shuttle tobago-popover");
+
+  const test = new JasmineTestTool(done);
+  test.setup(() => alertsFn().length > 0, null, "click", submitFn);
+  test.do(() => expect(getFullWidth(compareFn())).toBeCloseTo(
+      getFullWidth(labelFn()) + getFullWidth(inputFn()) + getFullWidth(popoverFn())
+  ));
+  test.start();
+});
+
+function getFullWidth(element) {
+  const computedStyle = getComputedStyle(element);
+  const marginLeft = parseFloat(computedStyle.marginLeft);
+  const width = parseFloat(computedStyle.width);
+  const marginRight = parseFloat(computedStyle.marginRight);
+  return marginLeft + width + marginRight;
+}
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
new file mode 100644
index 0000000..2a49f0b
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4800-labelLayout/500-message-layout/message-layout.xhtml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+
+<ui:composition template="/main.xhtml"
+                xmlns="http://www.w3.org/1999/xhtml"
+                xmlns:tc="http://myfaces.apache.org/tobago/component"
+                xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
+                xmlns:f="http://xmlns.jcp.org/jsf/core">
+  <ui:param name="title" value="messages"/>
+  <tc:button id="submit" label="Submit"/>
+
+  <tc:panel>
+    <tc:style width="1000px"/>
+
+    <tc:section label="Input">
+      <tc:in id="inCompare" label="Input"/>
+      <tc:in id="in" label="Input" required="true"/>
+    </tc:section>
+
+    <tc:section label="Input Group">
+      <tc:in id="inputGroupCompare" label="Input Group">
+        <f:facet name="before">https://example.com/</f:facet>
+        <f:facet name="after"><tc:button label="OK" omit="true"/></f:facet>
+      </tc:in>
+      <tc:in id="inputGroup" label="Input Group" required="true">
+        <f:facet name="before">https://example.com/</f:facet>
+        <f:facet name="after"><tc:button label="OK" omit="true"/></f:facet>
+      </tc:in>
+    </tc:section>
+
+    <tc:section label="Date">
+      <tc:date id="dateCompare" label="Date"/>
+      <tc:date id="date" label="Date" required="true"/>
+    </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>
+      <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>
+    </tc:section>
+  </tc:panel>
+</ui:composition>
diff --git a/tobago-theme/src/main/scss/_tobago.scss b/tobago-theme/src/main/scss/_tobago.scss
index f82523c..7be5af5 100644
--- a/tobago-theme/src/main/scss/_tobago.scss
+++ b/tobago-theme/src/main/scss/_tobago.scss
@@ -421,6 +421,12 @@ tobago-flex-layout {
     }
   }
 
+  > .tobago-messages-container {
+    .tobago-input-group-outer, .tobago-selectManyShuttle {
+      flex: 1 0 0px;
+    }
+  }
+
   > .form-check {
     /* .form-check has a margin-bottom which will be normally ignored, except in a label layout
    this results in different hights for form-check components with label and itemLabel */