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 2018/04/18 12:34:01 UTC

[myfaces-tobago] branch master updated: TOBAGO-1890 Entry of a suggest result is not shown if it contains a quote sign

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


The following commit(s) were added to refs/heads/master by this push:
     new 596e638  TOBAGO-1890 Entry of a suggest result is not shown if it contains a quote sign
596e638 is described below

commit 596e638f238faebbad5ac2eb423df56dad99f11d
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Wed Apr 18 14:33:10 2018 +0200

    TOBAGO-1890 Entry of a suggest result is not shown if it contains a quote sign
    
    * suggest should work with the last commit (TOBAGO-1892)
    * add a test for suggest results with quotation mark
---
 .../example/demo/SuggestQuotMarkController.java    |  64 ++++++++++
 .../1020-suggest-quotMark/suggest-quotMark.test.js | 129 +++++++++++++++++++++
 .../1020-suggest-quotMark/suggest-quotMark.xhtml   |  33 ++++++
 3 files changed, 226 insertions(+)

diff --git a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SuggestQuotMarkController.java b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SuggestQuotMarkController.java
new file mode 100644
index 0000000..95638d2
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SuggestQuotMarkController.java
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+
+package org.apache.myfaces.tobago.example.demo;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.enterprise.context.SessionScoped;
+import javax.inject.Named;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@SessionScoped
+@Named
+public class SuggestQuotMarkController implements Serializable {
+  private static final Logger LOG = LoggerFactory.getLogger(SuggestController.class);
+  private List<String> suggestions = new ArrayList<>(8);
+  private String query;
+
+  public SuggestQuotMarkController() {
+    suggestions.add("Mercury");
+    suggestions.add("Venus");
+    suggestions.add("Earth");
+    suggestions.add("Mars");
+    suggestions.add("Jupiter");
+    suggestions.add("Saturn");
+    suggestions.add("Uranus");
+    suggestions.add("Quotation\"Mark");
+  }
+
+  public String getQuery() {
+    return query;
+  }
+
+  public void setQuery(final String query) {
+    this.query = query;
+  }
+
+  public List<String> getSuggestions() {
+    final String substring = query != null ? query : "";
+    LOG.info("Creating items for substring: '" + substring + "'");
+    return suggestions.stream().filter(s -> StringUtils.containsIgnoreCase(s, substring)).collect(Collectors.toList());
+  }
+}
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/1020-suggest-quotMark/suggest-quotMark.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/1020-suggest-quotMark/suggest-quotMark.test.js
new file mode 100644
index 0000000..9860a8a
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/1020-suggest-quotMark/suggest-quotMark.test.js
@@ -0,0 +1,129 @@
+/*
+ * 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.
+ */
+
+QUnit.test("Basics: 'M'", function (assert) {
+  var inputString = "M";
+  var expectedLength = 3;
+
+  assert.expect(expectedLength + 1);
+  var done = assert.async();
+
+  var $in = jQueryFrame("#page\\:mainForm\\:input\\:\\:field");
+  var $suggestions = getSuggestions("#page\\:mainForm\\:input");
+
+  $in.val(inputString).trigger('input');
+
+  waitForAjax(function () {
+    $suggestions = jQueryFrame($suggestions.selector);
+    return $suggestions.length === expectedLength;
+  }, function () {
+    $suggestions = jQueryFrame($suggestions.selector);
+
+    assert.equal($suggestions.length, expectedLength);
+    for (i = 0; i < expectedLength; i++) {
+      assert.ok($suggestions.eq(i).find("strong").text().toUpperCase().indexOf(inputString.toUpperCase()) >= 0);
+    }
+
+    done();
+  });
+});
+
+QUnit.test("Basics: 'Ma'", function (assert) {
+  var inputString = "Ma";
+  var expectedLength = 2;
+
+  assert.expect(expectedLength + 1);
+  var done = assert.async();
+
+  var $in = jQueryFrame("#page\\:mainForm\\:input\\:\\:field");
+  var $suggestions = getSuggestions("#page\\:mainForm\\:input");
+
+  $in.val(inputString).trigger('input');
+
+  waitForAjax(function () {
+    $suggestions = jQueryFrame($suggestions.selector);
+    return $suggestions.length === expectedLength;
+  }, function () {
+    $suggestions = jQueryFrame($suggestions.selector);
+
+    assert.equal($suggestions.length, expectedLength);
+    for (i = 0; i < expectedLength; i++) {
+      assert.ok($suggestions.eq(i).find("strong").text().toUpperCase().indexOf(inputString.toUpperCase()) >= 0);
+    }
+
+    done();
+  });
+});
+
+QUnit.test("Basics: 'Mar'", function (assert) {
+  var inputString = "Mar";
+  var expectedLength = 2;
+
+  assert.expect(expectedLength + 1);
+  var done = assert.async();
+
+  var $in = jQueryFrame("#page\\:mainForm\\:input\\:\\:field");
+  var $suggestions = getSuggestions("#page\\:mainForm\\:input");
+
+  $in.val(inputString).trigger('input');
+
+  waitForAjax(function () {
+    $suggestions = jQueryFrame($suggestions.selector);
+    return $suggestions.length === expectedLength;
+  }, function () {
+    $suggestions = jQueryFrame($suggestions.selector);
+
+    assert.equal($suggestions.length, expectedLength);
+    for (i = 0; i < expectedLength; i++) {
+      assert.ok($suggestions.eq(i).find("strong").text().toUpperCase().indexOf(inputString.toUpperCase()) >= 0);
+    }
+
+    done();
+  });
+});
+
+QUnit.test("Basics: 'Mars'", function (assert) {
+  var inputString = "Mars";
+  var expectedLength = 1;
+
+  assert.expect(expectedLength + 1);
+  var done = assert.async();
+
+  var $in = jQueryFrame("#page\\:mainForm\\:input\\:\\:field");
+  var $suggestions = getSuggestions("#page\\:mainForm\\:input");
+
+  $in.val(inputString).trigger('input');
+
+  waitForAjax(function () {
+    $suggestions = jQueryFrame($suggestions.selector);
+    return $suggestions.length === expectedLength;
+  }, function () {
+    $suggestions = jQueryFrame($suggestions.selector);
+
+    assert.equal($suggestions.length, expectedLength);
+    for (i = 0; i < expectedLength; i++) {
+      assert.ok($suggestions.eq(i).find("strong").text().toUpperCase().indexOf(inputString.toUpperCase()) >= 0);
+    }
+
+    done();
+  });
+});
+
+function getSuggestions(id) {
+  return jQueryFrame(Tobago.Utils.escapeClientId(
+      jQueryFrame(id + " .tobago-suggest").attr("id") + "::popup") + " .tt-suggestion");
+}
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/1020-suggest-quotMark/suggest-quotMark.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/1020-suggest-quotMark/suggest-quotMark.xhtml
new file mode 100644
index 0000000..5452302
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/1020-suggest-quotMark/suggest-quotMark.xhtml
@@ -0,0 +1,33 @@
+<?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://java.sun.com/jsf/facelets">
+  <ui:param name="title" value="Test quotation mark in suggest results"/>
+  <tc:section label="Suggest">
+    <p>The suggest results contain an entry with a quotation mark.</p>
+    <tc:in id="input">
+      <tc:suggest totalCount="10" query="#{suggestQuotMarkController.query}">
+        <tc:selectItems value="#{suggestQuotMarkController.suggestions}" var="name" itemValue="#{name}"/>
+      </tc:suggest>
+    </tc:in>
+  </tc:section>
+</ui:composition>

-- 
To stop receiving notification emails like this one, please contact
hnoeth@apache.org.