Author: jjamrich
Date: 2011-08-03 17:38:23 -0400 (Wed, 03 Aug 2011)
New Revision: 22590
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richEditor/
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richEditor/RichEditorComponentAttribute.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richEditor/TestRichEditor.java
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichEditorBean.java
modules/tests/metamer/trunk/application/src/main/webapp/components/richEditor/simple.xhtml
Log:
Add selenium tests for rich:editor
Add requiredMessage attribute to Metamer page with default validation message,
and add selenium test for rich:editor attribute verify
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichEditorBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichEditorBean.java 2011-08-03
14:15:33 UTC (rev 22589)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichEditorBean.java 2011-08-03
21:38:23 UTC (rev 22590)
@@ -57,6 +57,7 @@
attributes = Attributes.getComponentAttributesFromFacesConfig(UIEditor.class,
getClass());
attributes.setAttribute("rendered", Boolean.TRUE);
+ attributes.setAttribute("requiredMessage", "Editor's value
cannot be empty!");
attributes.remove("converter");
attributes.remove("converterMessage");
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richEditor/simple.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richEditor/simple.xhtml 2011-08-03
14:15:33 UTC (rev 22589)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richEditor/simple.xhtml 2011-08-03
21:38:23 UTC (rev 22590)
@@ -50,6 +50,7 @@
readonly="#{richEditorBean.attributes['readonly'].value}"
rendered="#{richEditorBean.attributes['rendered'].value}"
required="#{richEditorBean.attributes['required'].value}"
+
requiredMessage="#{richEditorBean.attributes['requiredMessage'].value}"
style="#{richEditorBean.attributes['style'].value}"
styleClass="#{richEditorBean.attributes['styleClass'].value}"
title="#{richEditorBean.attributes['title'].value}"
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richEditor/RichEditorComponentAttribute.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richEditor/RichEditorComponentAttribute.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richEditor/RichEditorComponentAttribute.java 2011-08-03
21:38:23 UTC (rev 22590)
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.ftest.richEditor;
+
+import org.richfaces.tests.metamer.ftest.AbstractComponentAttributes;
+
+/**
+ * Rich Editor attributes bean
+ *
+ * @author <a href="mailto:jjamrich@redhat.com">Jan Jamrich</a>
+ *
+ * @version $Revision$
+ */
+public class RichEditorComponentAttribute extends AbstractComponentAttributes {
+
+ public void setImmediate(Boolean immediate) {
+ setProperty("immediate", immediate);
+ }
+
+ public void setHeight(String height) {
+ setProperty("height", height);
+ }
+
+ public void setReadonly(Boolean readonly) {
+ setProperty("readonly", readonly);
+ }
+
+ public void setRendered(Boolean rendered) {
+ setProperty("rendered", rendered);
+ }
+
+ public void setRequired (Boolean required) {
+ setProperty("required", required);
+ }
+
+ public void setRequiredMessage(String requiredMessage) {
+ setProperty("requiredMessage", requiredMessage);
+ }
+
+ public void setStyle(String style) {
+ setProperty("style", style);
+ }
+
+ public void setStyleClass(String styleClass) {
+ setProperty("styleClass", styleClass);
+ }
+
+ public void setToolbar(String toolbar) {
+ setProperty("toolbar", toolbar);
+ }
+
+ public void setValue(String value) {
+ setProperty("value", value);
+ }
+
+ public void setWidth(String width) {
+ }
+
+}
Property changes on:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richEditor/RichEditorComponentAttribute.java
___________________________________________________________________
Added: svn:executable
+ *
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richEditor/TestRichEditor.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richEditor/TestRichEditor.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richEditor/TestRichEditor.java 2011-08-03
21:38:23 UTC (rev 22590)
@@ -0,0 +1,257 @@
+/**
+ *
+ */
+package org.richfaces.tests.metamer.ftest.richEditor;
+
+import static java.text.MessageFormat.format;
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import java.net.URL;
+
+import org.jboss.test.selenium.dom.Event;
+import org.jboss.test.selenium.encapsulated.FrameLocator;
+import org.jboss.test.selenium.locator.Attribute;
+import org.jboss.test.selenium.locator.AttributeLocator;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.jboss.test.selenium.utils.URLUtils;
+import org.jboss.test.selenium.waiting.selenium.SeleniumCondition;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Test case for basic functionality of rich:editor on page
faces/components/richEditor/simple.xhtml.
+ *
+ * @author <a href="mailto:jjamrich@redhat.com">Jan Jamrich</a>
+ * @version $Revision$
+ */
+public class TestRichEditor extends AbstractMetamerTest {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TestRichEditor.class);
+
+ private JQueryLocator editor = pjq("span[id$=:editor]");
+ private JQueryLocator editorTextArea = pjq("textarea[id$=:editor]");
+ private JQueryLocator editorArea = jq("body");
+ private JQueryLocator phaseListenerFormat = jq("div#phasesPanel
li:eq({0})");
+ private FrameLocator frameLocator = new FrameLocator("jquery=iframe");
+ private JQueryLocator hSubmit = pjq("input[id$=hButton]");
+ private JQueryLocator a4jSubmit = pjq("input[id$=a4jButton]");
+ private JQueryLocator validationMsgLoc = pjq("span.rf-msgs-sum");
+
+ private RichEditorComponentAttribute attributes = new
RichEditorComponentAttribute();
+
+ private String text1 = "text1";
+ private String text2 = "text2";
+
+ private String validationMsg1 = "Editor's value cannot be empty!";
+ private String validationMsg2 = "Some text in editor is required!";
+
+ private String phaseListenerLogFormat = "*3 value changed: <p>
{0}</p> -> <p> {1}</p>";
+
+ @Override
+ public URL getTestUrl() {
+ return URLUtils.buildUrl(contextPath,
"faces/components/richEditor/simple.xhtml");
+ }
+
+ @BeforeMethod
+ public void beforeTestMethod() {
+ waitModel.until(elementPresent.locator(editor));
+ }
+
+ /**
+ * Provide common steps needed to verify valueChangeListener.
+ * Accepts JQueryLocator for submit button - provide
+ * ability to verify JSF submit as well as Ajax submit.
+ * @param submitBtn
+ */
+ private void verifyValueChangeListener(JQueryLocator submitBtn){
+
+ typeTextToEditor(text1);
+ // and submit typed text
+ selenium.click(submitBtn);
+ waitModel.until(elementPresent.locator(editor));
+
+ typeTextToEditor(text2);
+ // and submit typed text
+ selenium.click(submitBtn);
+ waitModel.until(elementPresent.locator(phaseListenerFormat.format(3)));
+
+ String listenerText = selenium.getText(phaseListenerFormat.format(3));
+ assertEquals(listenerText, format(phaseListenerLogFormat, text1, text2),
+ "Value change listener was not invoked.");
+ }
+
+ /**
+ * Since editor component lives within iFrame element, additional steps are required
+ *
+ * This method selects appropriate iframe, do action, and return focus to PARENT
frame
+ * @param text
+ */
+ private void typeTextToEditor(String text){
+ selenium.selectFrame(frameLocator);
+ selenium.fireEvent(editorArea, Event.FOCUS);
+ selenium.typeKeys(editorArea, text);
+
+ // focus back to main window - parent of iframe
+ selenium.selectFrame(FrameLocator.PARENT);
+ }
+
+ @Test
+ public void testValueChangeListener(){
+ verifyValueChangeListener(hSubmit);
+
+ verifyValueChangeListener(a4jSubmit);
+ }
+
+ @Test
+ public void testHeight() {
+ // TODO jjamrich 2011-08-03: implement test when fixed problem with height
+ }
+
+ @Test
+ public void testImmediate() {
+ attributes.setImmediate(Boolean.TRUE);
+
+ // set first value
+ typeTextToEditor(text1);
+ // and submit typed text
+ selenium.click(hSubmit);
+ waitModel.until(elementPresent.locator(phaseListenerFormat.format(2)));
+
+ // then set second value
+ typeTextToEditor(text2);
+ // and submit typed text
+ selenium.click(hSubmit);
+ waitModel.until(elementPresent.locator(phaseListenerFormat.format(2)));
+
+ // for immediate=true is valueChangeListener output as 3rd record
+ String listenerText = selenium.getText(phaseListenerFormat.format(2));
+ assertEquals(listenerText, format(phaseListenerLogFormat, text1, text2),
+ "Value change listener was not invoked or not in expected order");
+ }
+
+ @Test
+ public void testOnBlur() {
+ testFireEvent(Event.BLUR, editorTextArea);
+ }
+
+ @Test
+ public void testOnChange() {
+ testFireEvent(Event.CHANGE, editorTextArea);
+ }
+
+ @Test
+ public void testOnFocus() {
+ testFireEvent(Event.FOCUS, editorTextArea);
+ }
+
+ @Test
+ public void testOnInit() {
+
+ }
+
+ @Test
+ public void testReadonly() {
+ attributes.setReadonly(Boolean.TRUE);
+ typeTextToEditor("test");
+
+ }
+
+ @Test
+ public void testRendered() {
+ attributes.setRendered(Boolean.FALSE);
+ assertFalse(selenium.isElementPresent(editor), "Editor is rendered even
rendered attribute set to false.");
+ }
+
+ @Test
+ public void testRequired() {
+ attributes.setRequired(Boolean.TRUE);
+ selenium.click(hSubmit);
+ waitGui.until(textEquals.locator(validationMsgLoc).text(validationMsg1));
+
+ fullPageRefresh();
+
+ selenium.click(a4jSubmit);
+ waitGui.until(textEquals.locator(validationMsgLoc).text(validationMsg1));
+ }
+
+ @Test
+ public void testRequiredMessage() {
+ attributes.setRequired(Boolean.TRUE);
+ attributes.setRequiredMessage(validationMsg2);
+ selenium.click(hSubmit);
+ waitGui.until(textEquals.locator(validationMsgLoc).text(validationMsg2));
+
+ attributes.setRequiredMessage(validationMsg1);
+ selenium.click(a4jSubmit);
+ waitGui.until(textEquals.locator(validationMsgLoc).text(validationMsg1));
+ }
+
+ @Test
+ public void testStyle() {
+
+ final AttributeLocator<?> styleAttr =
editor.getAttribute(Attribute.STYLE);
+ final String style = "background-color: yellow; font-size: 1.5em;";
+
+ attributes.setStyle(style);
+
+ waitModel.failWith("Attribute style should contain \"" + style +
"\"")
+ .until(new SeleniumCondition() {
+ @Override
+ public boolean isTrue() {
+ return selenium.getAttribute(styleAttr).contains(style);
+ }
+ });
+
+ }
+
+ @Test
+ public void testStyleClass() {
+
+ final String styleClass = "metamer-ftest-class";
+ attributes.setStyleClass(styleClass);
+
+ JQueryLocator elementWhichHasntThatClass = jq(editor.getRawLocator() +
":not(.{0})").format(styleClass);
+ waitModel.until(elementPresent.locator(editor));
+ assertTrue(selenium.isElementPresent(editor));
+ assertFalse(selenium.isElementPresent(elementWhichHasntThatClass));
+ }
+
+ @Test
+ public void testTitle() {
+ testTitle(editor);
+ }
+
+ @Test
+ public void testToolbar() {
+ // TODO jjamrich 2011-08-03: implement test when realize what this attr should do
:)
+ }
+
+ @Test
+ public void testValue() {
+
+ // write some value in editor and submit by normal way
+ typeTextToEditor(text1);
+ selenium.click(hSubmit);
+
+ // then set value from outside, and check this value in editor
+ attributes.setValue(text2);
+ selenium.selectFrame(frameLocator);
+ String found = selenium.getText(editorArea);
+ assertTrue(found!=null && found.contains(text2));
+
+ // focus back to main window - parent of iframe
+ selenium.selectFrame(FrameLocator.PARENT);
+ }
+
+ @Test
+ public void testWidth() {
+ // TODO jjamrich 2011-08-03: implement test when fixed problem with width
+ }
+
+}
Property changes on:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richEditor/TestRichEditor.java
___________________________________________________________________
Added: svn:executable
+ *