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 2023/07/25 12:05:01 UTC
[myfaces-tobago] branch main updated: test: default command
This is an automated email from the ASF dual-hosted git repository.
hnoeth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
The following commit(s) were added to refs/heads/main by this push:
new 57df38b3fa test: default command
57df38b3fa is described below
commit 57df38b3fa7aca70c6f712ab804e18a792733f5f
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Tue Jul 25 13:59:05 2023 +0200
test: default command
---
.../040-command/10-default/Default_Command.test.js | 62 ++++++++++++++++++++++
.../040-command/10-default/Default_Command.xhtml | 24 +++++----
2 files changed, 75 insertions(+), 11 deletions(-)
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/040-command/10-default/Default_Command.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/040-command/10-default/Default_Command.test.js
new file mode 100644
index 0000000000..775102e7c2
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/040-command/10-default/Default_Command.test.js
@@ -0,0 +1,62 @@
+/*
+ * 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, querySelectorFn} from "/script/tobago-test.js";
+
+it("Basics", function (done) {
+ const inputFn = elementByIdFn("page:mainForm:basics:binput::field");
+ const outputFn = querySelectorFn("#page\\:mainForm\\:basics\\:boutput .form-control-plaintext");
+ const submitFn = elementByIdFn("page:mainForm:basics:bsubmit");
+
+ const test = new JasmineTestTool(done);
+ test.setup(() => outputFn().textContent === "", () => inputFn().value = "", "click", submitFn);
+ test.do(() => inputFn().value = "Tobago");
+ test.event("click", submitFn, () => outputFn().textContent.trim() === "Tobago");
+ test.do(() => expect(outputFn().textContent.trim()).toBe("Tobago"));
+ test.start();
+});
+
+it("Multiple default buttons", function (done) {
+ const inputAFn = elementByIdFn("page:mainForm:outerform:forma:inputA::field");
+ const outputAFn = querySelectorFn("#page\\:mainForm\\:outerform\\:forma\\:outputA .form-control-plaintext");
+ const submitAFn = elementByIdFn("page:mainForm:outerform:forma:submitA");
+ const inputBFn = elementByIdFn("page:mainForm:outerform:formb:inputB::field");
+ const outputBFn = querySelectorFn("#page\\:mainForm\\:outerform\\:formb\\:outputB .form-control-plaintext");
+ const submitBFn = elementByIdFn("page:mainForm:outerform:submitB");
+
+ const test = new JasmineTestTool(done);
+ test.setup(() => outputAFn().textContent === "" && outputBFn().textContent === "",
+ () => {
+ inputAFn().value = "";
+ inputBFn().value = "";
+ }, "click", submitBFn);
+
+ test.do(() => inputAFn().value = "a");
+ test.do(() => inputBFn().value = "b");
+ test.event("click", submitAFn, () => outputAFn().textContent.trim() === "a");
+ test.do(() => expect(outputAFn().textContent.trim()).toBe("a"));
+ test.do(() => expect(outputBFn().textContent.trim()).toBe(""));
+
+ test.do(() => inputAFn().value = "c");
+ test.do(() => inputBFn().value = "d");
+ test.event("click", submitBFn, () => outputAFn().textContent.trim() === "c" && outputBFn().textContent.trim() === "d");
+ test.do(() => expect(outputAFn().textContent.trim()).toBe("c"));
+ test.do(() => expect(outputBFn().textContent.trim()).toBe("d"));
+
+ test.start();
+});
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/040-command/10-default/Default_Command.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/040-command/10-default/Default_Command.xhtml
index de1223cfab..8580b48f68 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/040-command/10-default/Default_Command.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/040-command/10-default/Default_Command.xhtml
@@ -38,10 +38,10 @@
<tc:section label="Basics">
<p>After writing some text into the textfield, the user can press 'ENTER' to activate the submit-button.</p>
- <tc:form>
- <tc:in id="i1" label="Textfield" placeholder="add some text..." value="#{defaultCommandController.value1}"/>
- <tc:out id="o2" label="Value Textfield" value="#{defaultCommandController.value1}"/>
- <tc:button id="submit1" label="Submit 1" defaultCommand="true"
+ <tc:form id="basics">
+ <tc:in id="binput" label="Textfield" placeholder="add some text..." value="#{defaultCommandController.value1}"/>
+ <tc:out id="boutput" label="Value Textfield" value="#{defaultCommandController.value1}"/>
+ <tc:button id="bsubmit" label="Submit" defaultCommand="true"
actionListener="#{defaultCommandController.click}"/>
</tc:form>
</tc:section>
@@ -56,19 +56,21 @@
Therefor only the 'Textfield A'-value will be submitted.</p>
<p>If the cursor is in 'Textfield B' and the enter key is pressed, the 'Submit B'-button is activated.
This will submit the 'Textfield A'-value as well as the 'Textfield B'-value.</p>
- <tc:form>
+ <tc:form id="outerform">
<tc:box>
- <tc:form>
- <tc:in id="i2" label="Textfield A" placeholder="add some text..." value="#{defaultCommandController.value2}"/>
- <tc:out id="o3" label="Value Textfield A" value="#{defaultCommandController.value2}"/>
+ <tc:form id="forma">
+ <tc:in id="inputA" label="Textfield A" placeholder="add some text..."
+ value="#{defaultCommandController.value2}"/>
+ <tc:out id="outputA" label="Value Textfield A" value="#{defaultCommandController.value2}"/>
<tc:button id="submitA" label="Submit A" defaultCommand="true"
actionListener="#{defaultCommandController.click}"/>
</tc:form>
</tc:box>
<tc:box>
- <tc:form>
- <tc:in id="i3" label="Textfield B" placeholder="add some text..." value="#{defaultCommandController.value3}"/>
- <tc:out id="o4" label="Value Textfield B" value="#{defaultCommandController.value3}"/>
+ <tc:form id="formb">
+ <tc:in id="inputB" label="Textfield B" placeholder="add some text..."
+ value="#{defaultCommandController.value3}"/>
+ <tc:out id="outputB" label="Value Textfield B" value="#{defaultCommandController.value3}"/>
</tc:form>
</tc:box>
<tc:button id="submitB" label="Submit B" defaultCommand="true"