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 2025/04/29 08:29:37 UTC

(myfaces-tobago) branch tobago-5.x updated: test(Select[One|Many]List): remove filter text

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


The following commit(s) were added to refs/heads/tobago-5.x by this push:
     new 104a7c2874 test(Select[One|Many]List): remove filter text
104a7c2874 is described below

commit 104a7c287408485886d3db64952007dc6e7eb3b0
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Tue Apr 29 09:10:18 2025 +0200

    test(Select[One|Many]List): remove filter text
    
    Value of the filter element must be removed when leaving the component.
---
 .../leave-component/Leave_component.test.js        | 59 ++++++++++++++++++++++
 .../leave-component/Leave_component.xhtml          | 31 ++++++++++++
 2 files changed, 90 insertions(+)

diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/2098-selectOneList/leave-component/Leave_component.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/2098-selectOneList/leave-component/Leave_component.test.js
new file mode 100644
index 0000000000..d76bfb67d0
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/2098-selectOneList/leave-component/Leave_component.test.js
@@ -0,0 +1,59 @@
+/*
+ * 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 {activeElementFn, elementByIdFn, querySelectorAllFn, querySelectorFn} from "/script/tobago-test.js";
+
+it("Open dropdown, filter, leave component", function (done) {
+  const selectOneList = elementByIdFn("page:mainForm:selectOneList");
+  const selectField = elementByIdFn("page:mainForm:selectOneList::selectField");
+  const filterInput = elementByIdFn("page:mainForm:selectOneList::filter");
+  const dropdownMenu = querySelectorFn(".tobago-dropdown-menu[name='page:mainForm:selectOneList']");
+  const hiddenSelectItems = querySelectorAllFn(".tobago-dropdown-menu[name='page:mainForm:selectOneList'] .tobago-select-item.d-none");
+  const submitButton = elementByIdFn("page:mainForm:submit");
+
+  const test = new JasmineTestTool(done);
+  test.setup(() => activeElementFn() === submitButton(), null, "focus", submitButton);
+  test.do(() => expect(activeElementFn()).toBe(submitButton()));
+  test.do(() => expect(selectOneList().classList).not.toContain("tobago-focus"));
+  test.do(() => expect(filterInput().value).toBe(""));
+  test.do(() => expect(dropdownMenu().classList).not.toContain("show"));
+  test.do(() => expect(hiddenSelectItems().length).toBe(0));
+
+  test.event("click", selectField, () => dropdownMenu().classList.contains("show"));
+  test.do(() => expect(activeElementFn()).toBe(filterInput()));
+  test.do(() => expect(selectOneList().classList).toContain("tobago-focus"));
+  test.do(() => expect(filterInput().value).toBe(""));
+  test.do(() => expect(dropdownMenu().classList).toContain("show"));
+  test.do(() => expect(hiddenSelectItems().length).toBe(0));
+
+  test.do(() => filterInput().value = 'a');
+  test.event("input", filterInput, () => hiddenSelectItems().length > 0);
+  test.do(() => expect(activeElementFn()).toBe(filterInput()));
+  test.do(() => expect(selectOneList().classList).toContain("tobago-focus"));
+  test.do(() => expect(filterInput().value).toBe("a"));
+  test.do(() => expect(dropdownMenu().classList).toContain("show"));
+  test.do(() => expect(hiddenSelectItems().length).toBe(5));
+
+  test.event("focus", submitButton, () => hiddenSelectItems().length === 0);
+  test.do(() => expect(activeElementFn()).toBe(submitButton()));
+  test.do(() => expect(selectOneList().classList).not.toContain("tobago-focus"));
+  test.do(() => expect(filterInput().value).toBe(""));
+  test.do(() => expect(dropdownMenu().classList).not.toContain("show"));
+  test.do(() => expect(hiddenSelectItems().length).toBe(0));
+  test.start();
+});
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/2098-selectOneList/leave-component/Leave_component.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/2098-selectOneList/leave-component/Leave_component.xhtml
new file mode 100644
index 0000000000..d15a60bd2a
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/2098-selectOneList/leave-component/Leave_component.xhtml
@@ -0,0 +1,31 @@
+<?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:f="http://xmlns.jcp.org/jsf/core"
+                xmlns:tc="http://myfaces.apache.org/tobago/component"
+                xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
+
+  <tc:selectOneList id="selectOneList" label="Filter (contains)" filter="contains">
+    <tc:selectItems value="#{selectOneListController.planets}"
+                    var="planet" itemLabel="#{planet.name}" itemValue="#{planet}"/>
+  </tc:selectOneList>
+  <tc:button id="submit" label="Submit"/>
+</ui:composition>