Author: jjamrich
Date: 2012-01-18 10:21:52 -0500 (Wed, 18 Jan 2012)
New Revision: 23164
Added:
modules/tests/metamer/branches/contextMenu/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richContextMenu/TestRichContextMenu.java
Log:
RF-10197: Add basic event handlers tests
Basic event handlers such as click|dblclick, mouseover|out, keyup|keydown on
rich:contextMenu.
Removed (commented) tests not yet implemented
Added:
modules/tests/metamer/branches/contextMenu/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richContextMenu/TestRichContextMenu.java
===================================================================
---
modules/tests/metamer/branches/contextMenu/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richContextMenu/TestRichContextMenu.java
(rev 0)
+++
modules/tests/metamer/branches/contextMenu/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richContextMenu/TestRichContextMenu.java 2012-01-18
15:21:52 UTC (rev 23164)
@@ -0,0 +1,288 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.richContextMenu;
+
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardHttp;
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static
org.richfaces.tests.metamer.ftest.attributes.AttributeList.contextMenuAttributes;
+import static
org.richfaces.tests.metamer.ftest.richContextMenu.ContextMenuAttributes.attachTo;
+import static
org.richfaces.tests.metamer.ftest.richContextMenu.ContextMenuAttributes.dir;
+import static
org.richfaces.tests.metamer.ftest.richContextMenu.ContextMenuAttributes.disabled;
+import static
org.richfaces.tests.metamer.ftest.richContextMenu.ContextMenuAttributes.hideDelay;
+import static
org.richfaces.tests.metamer.ftest.richContextMenu.ContextMenuAttributes.showEvent;
+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.geometry.Point;
+import org.jboss.test.selenium.locator.Attribute;
+import org.jboss.test.selenium.locator.ElementLocator;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.jboss.test.selenium.waiting.EventFiredCondition;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.Test;
+
+/**
+ * Test for rich:contextMenu component at faces/components/richContextMenu/simple.xhtml
+ *
+ * @author <a href="mailto:jjamrich@redhat.com">Jan Jamrich</a>
+ * @version $Revision$
+ */
+public class TestRichContextMenu extends AbstractMetamerTest {
+
+ private static final Logger log =
LoggerFactory.getLogger(TestRichContextMenu.class);
+
+ private JQueryLocator menuElemFormat = pjq("div[id$=:{0}]");
+ private String menuElemId = "panelClick";
+ private JQueryLocator menuElem = menuElemFormat.format(menuElemId);
+ // contextMenu elem is always present (and selenium consider it as displayed and
visible as well)
+ private JQueryLocator contextMenu = jq("div[id$=:ctxmenu]");
+ private JQueryLocator ctxMenuItemFormat = jq("div.rf-ctx-itm:eq({0})");
+
+ // content display is triggered by action
+ private JQueryLocator contextMenuContent = jq("div.rf-ctx-lst");
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richContextMenu/simple.xhtml");
+ }
+
+ private void clickOnTarget(JQueryLocator target) {
+ // mouseDownRight doesn't work, so have to use left click for common cases
+ contextMenuAttributes.set(showEvent, "click");
+
+ Point position = selenium.getElementPosition(target);
+ selenium.clickAt(target, position.minus(new Point(0, 70)));
+ }
+
+ private void testFireContextMenuEvent(Event event, ElementLocator<?> element)
{
+ testFireContextMenuEvent(event, element, event.getEventName());
+ }
+
+ private void testFireContextMenuEvent(Event event, ElementLocator<?> element,
String attributeName) {
+ ElementLocator<?> eventInput = pjq("input[id$=on" + attributeName
+ "Input]");
+ String value = "metamerEvents += \"" + event.getEventName() +
" \"";
+
+ guardHttp(selenium).type(eventInput, value);
+
+ clickOnTarget(menuElem);
+
+ waitModel.until(isDisplayed.locator(contextMenuContent));
+
+ selenium.fireEvent(element, event);
+
+ waitGui.failWith("Attribute on" + attributeName + " does not work
correctly").until(
+ new EventFiredCondition(event));
+ }
+
+ @Test
+ public void testAttachTo() {
+ contextMenuAttributes.set(attachTo, "form:" + menuElemId);
+
+ // contextMenu element is present always. Check if is displayed
+ assertFalse(selenium.isVisible(contextMenuContent));
+ assertTrue(selenium.isDisplayed(contextMenuContent));
+ clickOnTarget(menuElem);
+ assertTrue(selenium.isVisible(contextMenuContent));
+ assertTrue(selenium.isDisplayed(contextMenuContent));
+ }
+
+ @Test
+ public void testDir() {
+ contextMenuAttributes.set(dir, "rtl");
+ log.debug(selenium.getAttribute(contextMenu.getAttribute(new
Attribute("dir"))));
+ }
+
+ // @Test
+ public void testDirection() {
+
+ }
+
+ @Test
+ public void testDisabled() {
+ assertTrue(selenium.isElementPresent(contextMenu));
+ assertTrue(selenium.isElementPresent(contextMenuContent));
+
+ contextMenuAttributes.set(disabled, true);
+
+ // contextMenu is present
+ assertTrue(selenium.isElementPresent(contextMenu));
+ // but content not, when disabled
+ assertFalse(selenium.isElementPresent(contextMenuContent));
+ }
+
+ @Test
+ public void testHideDelay() {
+ contextMenuAttributes.set(hideDelay, "500");
+ clickOnTarget(menuElem);
+ assertTrue(selenium.isVisible(contextMenuContent));
+ assertTrue(selenium.isDisplayed(contextMenuContent));
+
+ selenium.fireEvent(menuElem, Event.MOUSEUP);
+ waitModel.until(isNotDisplayed.locator(contextMenuContent));
+
+ assertFalse(selenium.isVisible(contextMenuContent));
+ assertFalse(selenium.isDisplayed(contextMenuContent));
+
+ }
+
+ // @Test
+ public void testHorizontalOffset() {
+
+ }
+
+ // @Test
+ public void testJointPoint() {
+
+ }
+
+ // @Test
+ public void testLang() {
+
+ }
+
+ // @Test
+ public void testMode() {
+
+ }
+
+ @Test
+ public void testOnclick() {
+ testFireContextMenuEvent(Event.CLICK, contextMenu);
+ }
+
+ @Test
+ public void testOndblclick() {
+ testFireContextMenuEvent(Event.DBLCLICK, contextMenu);
+ }
+
+ // @Test
+ public void testOngrouphide() {
+
+ }
+
+ // @Test
+ public void testOngroupshow() {
+
+ }
+
+ // @Test
+ public void testOnhide() {
+
+ }
+
+ @Test
+ public void testOnitemclick() {
+ testFireContextMenuEvent(Event.CLICK, ctxMenuItemFormat.format("0"),
"itemclick");
+ }
+
+ @Test
+ public void testOnkeydown() {
+ testFireContextMenuEvent(Event.KEYDOWN, contextMenu);
+ }
+
+ @Test
+ public void testOnkeypress() {
+ testFireContextMenuEvent(Event.KEYPRESS, contextMenu);
+ }
+
+ @Test
+ public void testOnkeyup() {
+ testFireContextMenuEvent(Event.KEYUP, contextMenu);
+ }
+
+ @Test
+ public void testOnmousedown() {
+ testFireContextMenuEvent(Event.MOUSEDOWN, contextMenu);
+ }
+
+ @Test
+ public void testOnmousemove() {
+ testFireContextMenuEvent(Event.MOUSEMOVE, contextMenu);
+ }
+
+ @Test
+ public void testOnmouseout() {
+ testFireContextMenuEvent(Event.MOUSEOUT, contextMenu);
+ }
+
+ @Test
+ public void testOnmouseover() {
+ testFireContextMenuEvent(Event.MOUSEOVER, contextMenu);
+ }
+
+ @Test
+ public void testOnmouseup() {
+ testFireContextMenuEvent(Event.MOUSEUP, contextMenu);
+ }
+
+ // @Test
+ public void testOnshow() {
+
+ }
+
+ // @Test
+ public void testPopupWidth() {
+
+ }
+
+ // @Test
+ public void testRendered() {
+
+ }
+
+ // @Test
+ public void testShowDelay() {
+
+ }
+
+ // @Test
+ public void testShowEvent() {
+
+ }
+
+ // @Test
+ public void testStyle() {
+
+ }
+
+ // @Test
+ public void testStyleClass() {
+
+ }
+
+ // @Test
+ public void testTitle() {
+
+ }
+
+ // @Test
+ public void testVerticalOffset() {
+
+ }
+
+}