From richfaces-svn-commits at lists.jboss.org Fri Nov 19 04:54:46 2010 Content-Type: multipart/mixed; boundary="===============3513693011945531321==" MIME-Version: 1.0 From: richfaces-svn-commits at lists.jboss.org To: richfaces-svn-commits at lists.jboss.org Subject: [richfaces-svn-commits] JBoss Rich Faces SVN: r20114 - in modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest: richCalendar and 1 other directory. Date: Fri, 19 Nov 2010 04:54:45 -0500 Message-ID: <201011190954.oAJ9sje6031388@svn01.web.mwc.hst.phx2.redhat.com> --===============3513693011945531321== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: ppitonak(a)redhat.com Date: 2010-11-19 04:54:45 -0500 (Fri, 19 Nov 2010) New Revision: 20114 Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tes= ts/metamer/ftest/richCalendar/ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tes= ts/metamer/ftest/richCalendar/AbstractCalendarTest.java modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tes= ts/metamer/ftest/richCalendar/TestRichCalendarAttributes.java modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tes= ts/metamer/ftest/richCalendar/TestRichCalendarBasic.java Log: https://jira.jboss.org/browse/RF-9178 * added 60 tests for rich:calendar Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces= /tests/metamer/ftest/richCalendar/AbstractCalendarTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/te= sts/metamer/ftest/richCalendar/AbstractCalendarTest.java = (rev 0) +++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/te= sts/metamer/ftest/richCalendar/AbstractCalendarTest.java 2010-11-19 09:54:4= 5 UTC (rev 20114) @@ -0,0 +1,89 @@ +/*************************************************************************= ****** + * JBoss, Home of Professional Open Source + * Copyright 2010, 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.richCalendar; + +import org.jboss.test.selenium.locator.JQueryLocator; +import org.richfaces.tests.metamer.ftest.AbstractMetamerTest; + +/** + * Abstract test case for calendar. + * = + * @author Pavol Pitonak + * @version $Revision$ + */ +public abstract class AbstractCalendarTest extends AbstractMetamerTest { + + public enum Month { + + January, February, March, April, May, June, July, August, Septembe= r, October, November, December; + + public Month previous() { + if (ordinal() =3D=3D 0) { + return December; + } + return Month.values()[ordinal() - 1]; + } + + public Month next() { + if (ordinal() =3D=3D 11) { + return January; + } + return Month.values()[ordinal() + 1]; + } + } + // basic parts + protected JQueryLocator calendar =3D pjq("span[id$=3Dcalendar]"); + protected JQueryLocator inputs =3D pjq("span[id$=3DcalendarPopup]"); + protected JQueryLocator input =3D pjq("input.rf-ca-inp"); + protected JQueryLocator image =3D pjq("img.rf-ca-btn"); + protected JQueryLocator button =3D pjq("button.rf-ca-btn"); + // popup + protected JQueryLocator popup =3D pjq("table[id$=3DcalendarContent]"); + protected JQueryLocator prevYearButton =3D pjq("td.rf-ca-tl:eq(0) > di= v"); + protected JQueryLocator nextYearButton =3D pjq("td.rf-ca-tl:eq(3) > di= v"); + protected JQueryLocator prevMonthButton =3D pjq("td.rf-ca-tl:eq(1) > d= iv"); + protected JQueryLocator nextMonthButton =3D pjq("td.rf-ca-tl:eq(2) > d= iv"); + protected JQueryLocator closeButton =3D pjq("td.rf-ca-tl:eq(4) > div"); + protected JQueryLocator monthLabel =3D pjq("td.rf-ca-month > div"); + // 0 =3D blank, 1 =3D Sun, 2 =3D Mon, 3 =3D Tue ... + protected JQueryLocator weekDayLabel =3D pjq("td.rf-ca-days:eq({0})"); + // week =3D 1..6, day =3D 0..6 + protected JQueryLocator cellWeekDay =3D pjq("tr[id$=3DcalendarWeekNum{= 0}] > td:eq({1})"); + // day =3D 0..41 + protected JQueryLocator cellDay =3D pjq("td.rf-ca-c:eq({0})"); + // 0..6 + protected JQueryLocator week =3D pjq("td.rf-ca-week:eq({0})"); + protected JQueryLocator cleanButton =3D pjq("td.rf-ca-tl-ftr:eq(1) > d= iv"); + protected JQueryLocator timeButton =3D pjq("td.rf-ca-tl-ftr:eq(2) > di= v"); + protected JQueryLocator todayButton =3D pjq("td.rf-ca-tl-ftr:eq(4) > d= iv"); + protected JQueryLocator applyButton =3D pjq("td.rf-ca-tl-ftr:eq(5) > d= iv"); + // time panel + protected JQueryLocator timePanel =3D pjq("table[id$=3DcalendarEditor]= "); + protected JQueryLocator hoursInput =3D pjq("input[id$=3DcalendarTimeHo= urs]"); + protected JQueryLocator hoursInputUp =3D pjq("div[id$=3DcalendarTimeHo= ursBtnUp]"); + protected JQueryLocator hoursInputDown =3D pjq("div[id$=3DcalendarTime= HoursBtnDown]"); + protected JQueryLocator minutesInput =3D pjq("input[id$=3DcalendarTime= Minutes]"); + protected JQueryLocator minutesInputUp =3D pjq("div[id$=3DcalendarTime= MinutesBtnUp]"); + protected JQueryLocator minutesInputDown =3D pjq("div[id$=3DcalendarTi= meMinutesBtnDown]"); + protected JQueryLocator okButton =3D pjq("td.rf-ca-time-layout-ok > di= v"); + protected JQueryLocator cancelButton =3D pjq("td.rf-ca-time-layout-can= cel > div"); +} Property changes on: modules/tests/metamer/trunk/ftest-source/src/main/java= /org/richfaces/tests/metamer/ftest/richCalendar/AbstractCalendarTest.java ___________________________________________________________________ Name: svn:keywords + Revision Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces= /tests/metamer/ftest/richCalendar/TestRichCalendarAttributes.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/te= sts/metamer/ftest/richCalendar/TestRichCalendarAttributes.java = (rev 0) +++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/te= sts/metamer/ftest/richCalendar/TestRichCalendarAttributes.java 2010-11-19 0= 9:54:45 UTC (rev 20114) @@ -0,0 +1,707 @@ +/*************************************************************************= ****** + * JBoss, Home of Professional Open Source + * Copyright 2010, 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.richCalendar; + +import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactor= y.guardNoRequest; +import static org.jboss.test.selenium.utils.URLUtils.buildUrl; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + +import java.net.URL; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +import org.jboss.test.selenium.dom.Event; +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.waiting.EventFiredCondition; +import org.richfaces.tests.metamer.ftest.annotations.IssueTracking; +import org.testng.annotations.Test; + +/** + * Test case for attributes of a calendar on page faces/components/richCal= endar/simple.xhtml. + * = + * @author Pavol Pitonak + * @version $Revision$ + */ +public class TestRichCalendarAttributes extends AbstractCalendarTest { + + @Override + public URL getTestUrl() { + return buildUrl(contextPath, "faces/components/richCalendar/simple= .xhtml"); + } + + @Test + public void testBoundaryDatesModeNull() { + selenium.click(input); + + String month =3D selenium.getText(monthLabel); + guardNoRequest(selenium).click(cellWeekDay.format(6, 6)); + String newMonth =3D selenium.getText(monthLabel); + assertEquals(newMonth, month, "Month should not change."); + + // the most top-left column might be 1st day of month + while (selenium.getText(cellWeekDay.format(1, 0)).equals("1")) { + selenium.click(prevMonthButton); + } + + guardNoRequest(selenium).click(cellWeekDay.format(1, 1)); + newMonth =3D selenium.getText(monthLabel); + assertEquals(newMonth, month, "Month should not change."); + } + + @Test + public void testBoundaryDatesModeInactive() { + JQueryLocator selectOption =3D pjq("input[name$=3DboundaryDatesMod= eInput][value=3Dinactive]"); + selenium.click(selectOption); + selenium.waitForPageToLoad(); + + testBoundaryDatesModeNull(); + } + + @Test + public void testBoundaryDatesModeScroll() { + JQueryLocator selectOption =3D pjq("input[name$=3DboundaryDatesMod= eInput][value=3Dscroll]"); + selenium.click(selectOption); + selenium.waitForPageToLoad(); + selenium.click(input); + + String thisMonth =3D selenium.getText(monthLabel); + // November, 2010 -> November + thisMonth =3D thisMonth.substring(0, thisMonth.indexOf(",")); + guardNoRequest(selenium).click(cellWeekDay.format(6, 6)); + String newMonth =3D selenium.getText(monthLabel); + newMonth =3D newMonth.substring(0, newMonth.indexOf(",")); + assertEquals(Month.valueOf(newMonth), Month.valueOf(thisMonth).nex= t(), "Month did not change correctly."); + + assertNoDateSelected(); + + // the most top-left column might be 1st day of month + while (selenium.getText(cellWeekDay.format(1, 0)).equals("1")) { + selenium.click(prevMonthButton); + } + + thisMonth =3D selenium.getText(monthLabel); + // November, 2010 -> November + thisMonth =3D thisMonth.substring(0, thisMonth.indexOf(",")); + guardNoRequest(selenium).click(cellWeekDay.format(1, 1)); + newMonth =3D selenium.getText(monthLabel); + newMonth =3D newMonth.substring(0, newMonth.indexOf(",")); + + assertEquals(Month.valueOf(newMonth), Month.valueOf(thisMonth).pre= vious(), "Month did not change correctly."); + + assertNoDateSelected(); + } + + @Test + public void testBoundaryDatesModeSelect() { + JQueryLocator selectOption =3D pjq("input[name$=3DboundaryDatesMod= eInput][value=3Dselect]"); + selenium.click(selectOption); + selenium.waitForPageToLoad(); + selenium.click(input); + + String thisMonth =3D selenium.getText(monthLabel); + String selectedDate =3D selenium.getText(cellWeekDay.format(6, 6)); + // November, 2010 -> November + thisMonth =3D thisMonth.substring(0, thisMonth.indexOf(",")); + guardNoRequest(selenium).click(cellWeekDay.format(6, 6)); + String newMonth =3D selenium.getText(monthLabel); + newMonth =3D newMonth.substring(0, newMonth.indexOf(",")); + assertEquals(Month.valueOf(newMonth), Month.valueOf(thisMonth).nex= t(), "Month did not change correctly."); + + assertSelected(selectedDate); + + // the most top-left column might be 1st day of month + while (selenium.getText(cellWeekDay.format(1, 0)).equals("1")) { + selenium.click(prevMonthButton); + } + + thisMonth =3D selenium.getText(monthLabel); + selectedDate =3D selenium.getText(cellWeekDay.format(1, 1)); + // November, 2010 -> November + thisMonth =3D thisMonth.substring(0, thisMonth.indexOf(",")); + guardNoRequest(selenium).click(cellWeekDay.format(1, 1)); + newMonth =3D selenium.getText(monthLabel); + newMonth =3D newMonth.substring(0, newMonth.indexOf(",")); + + assertEquals(Month.valueOf(newMonth), Month.valueOf(thisMonth).pre= vious(), "Month did not change correctly."); + + assertSelected(selectedDate); + } + + @Test + public void testButtonClass() { + testStyleClass(image, "buttonClass"); + } + + @Test + public void testButtonClassLabel() { + selenium.type(pjq("input[type=3Dtext][id$=3DbuttonLabelInput]"), "= label"); + selenium.waitForPageToLoad(); + + testStyleClass(button, "buttonClass"); + } + + @Test + public void testButtonClassIcon() { + JQueryLocator selectOption =3D pjq("td:has(label:contains(heart)) = > input[name$=3DbuttonIconInput]"); + selenium.click(selectOption); + selenium.waitForPageToLoad(); + + testStyleClass(image, "buttonClass"); + } + + @Test + public void testButtonIcon() { + JQueryLocator selectOption =3D pjq("td:has(label:contains(star)) >= input[name$=3DbuttonIconInput]"); + selenium.click(selectOption); + selenium.waitForPageToLoad(); + + AttributeLocator attr =3D image.getAttribute(Attribute.SRC); + String src =3D selenium.getAttribute(attr); + assertTrue(src.contains("star.png"), "Calendar's icon was not upda= ted."); + + selectOption =3D pjq("td:has(label:contains(null)) > input[name$= =3DbuttonIconInput]"); + selenium.click(selectOption); + selenium.waitForPageToLoad(); + + src =3D selenium.getAttribute(attr); + assertTrue(src.contains("calendarIcon.png"), "Calendar's icon was = not updated."); + } + + @Test + public void testButtonIconDisabled() { + JQueryLocator selectOption =3D pjq("input[name$=3DdisabledInput][v= alue=3Dtrue]"); + selenium.click(selectOption); + selenium.waitForPageToLoad(); + + selectOption =3D pjq("td:has(label:contains(heart)) > input[name$= =3DbuttonIconDisabledInput]"); + selenium.click(selectOption); + selenium.waitForPageToLoad(); + + AttributeLocator attr =3D image.getAttribute(Attribute.SRC); + String src =3D selenium.getAttribute(attr); + assertTrue(src.contains("heart.png"), "Calendar's icon was not upd= ated."); + + selectOption =3D pjq("td:has(label:contains(null)) > input[name$= =3DbuttonIconDisabledInput]"); + selenium.click(selectOption); + selenium.waitForPageToLoad(); + + src =3D selenium.getAttribute(attr); + assertTrue(src.contains("calendarIcon.png"), "Calendar's icon was = not updated."); + } + + @Test + public void testButtonLabel() { + selenium.type(pjq("input[type=3Dtext][id$=3DbuttonLabelInput]"), "= label"); + selenium.waitForPageToLoad(); + + assertTrue(selenium.isDisplayed(button), "Button should be display= ed."); + assertEquals(selenium.getText(button), "label", "Label of the butt= on."); + if (selenium.isElementPresent(image)) { + assertFalse(selenium.isDisplayed(image), "Image should not be = displayed."); + } + + JQueryLocator selectOption =3D pjq("td:has(label:contains(star)) >= input[name$=3DbuttonIconInput]"); + selenium.click(selectOption); + selenium.waitForPageToLoad(); + + if (selenium.isElementPresent(image)) { + assertFalse(selenium.isDisplayed(image), "Image should not be = displayed."); + } + } + + @Test + public void testDatePattern() { + selenium.type(pjq("input[type=3Dtext][id$=3DdatePatternInput]"), "= hh:mm:ss a MMMM d, yyyy"); + selenium.waitForPageToLoad(); + + selenium.click(input); + + selenium.click(cellDay.format(6)); + String day =3D selenium.getText(cellDay.format(6)); + String month =3D selenium.getText(monthLabel); + + String selectedDate =3D null; + try { + Date date =3D new SimpleDateFormat("d MMMM, yyyy hh:mm a").par= se(day + " " + month + " 12:00 PM"); + selectedDate =3D new SimpleDateFormat("hh:mm:ss a MMMM d, yyyy= ").format(date); + } catch (ParseException ex) { + fail(ex.getMessage()); + } + + selenium.click(applyButton); + assertFalse(selenium.isDisplayed(popup), "Popup should not be disp= layed."); + + String inputDate =3D selenium.getValue(input); + assertEquals(inputDate, selectedDate, "Input doesn't contain selec= ted date."); + } + + @Test + public void testDayStyleClass() { + JQueryLocator selectOption =3D pjq("input[name$=3DdayStyleClassInp= ut][value=3DyellowTuesdays]"); + selenium.click(selectOption); + selenium.waitForPageToLoad(); + + selenium.click(input); + + for (int i =3D 2; i < 42; i +=3D 7) { + if (!selenium.belongsClass(cellDay.format(i), "rf-ca-boundary-= dates")) { + assertTrue(selenium.belongsClass(cellDay.format(i), "yello= wDay"), "Cell nr. " + i + " should be yellow."); + } + } + + selectOption =3D pjq("input[name$=3DdayStyleClassInput][value=3D]"= ); + selenium.click(selectOption); + selenium.waitForPageToLoad(); + + selenium.click(input); + + for (int i =3D 0; i < 42; i++) { + assertFalse(selenium.belongsClass(cellDay.format(i), "yellowDa= y"), "Cell nr. " + i + " should not be yellow."); + } + } + + @Test + @IssueTracking("https://jira.jboss.org/browse/RF-9837") + public void testDefaultTime() { + selenium.type(pjq("input[type=3Dtext][id$=3DdefaultTimeInput]"), "= 21:24"); + selenium.waitForPageToLoad(); + + selenium.click(input); + selenium.click(cellWeekDay.format(3, 3)); + + boolean displayed =3D selenium.isDisplayed(timeButton); + assertTrue(displayed, "Time button should be visible."); + String buttonText =3D selenium.getText(timeButton); + assertEquals(buttonText, "21:24", "Default time"); + } + + @Test + public void testDisabled() { + JQueryLocator selectOption =3D pjq("input[name$=3DdisabledInput][v= alue=3Dtrue]"); + selenium.click(selectOption); + selenium.waitForPageToLoad(); + + AttributeLocator disabledAttr =3D input.getAttribute(new Attribute= ("disabled")); + assertTrue(selenium.isAttributePresent(disabledAttr), "Disabled at= tribute of input should be defined."); + assertEquals(selenium.getAttribute(disabledAttr), "disabled", "Inp= ut should be disabled."); + + selenium.click(input); + assertFalse(selenium.isDisplayed(popup), "Popup should not be disp= layed."); + + selenium.click(image); + assertFalse(selenium.isDisplayed(popup), "Popup should not be disp= layed."); + } + + @Test + public void testEnableManualInput() { + AttributeLocator readonlyAttr =3D input.getAttribute(new Attribute= ("readonly")); + assertTrue(selenium.isAttributePresent(readonlyAttr), "Readonly at= tribute of input should be defined."); + assertEquals(selenium.getAttribute(readonlyAttr), "readonly", "Inp= ut should be read-only."); + + JQueryLocator selectOption =3D pjq("input[name$=3DenableManualInpu= tInput][value=3Dtrue]"); + selenium.click(selectOption); + selenium.waitForPageToLoad(); + + assertFalse(selenium.isAttributePresent(readonlyAttr), "Readonly a= ttribute of input should not be defined."); + } + + @Test + @IssueTracking("https://jira.jboss.org/browse/RF-9646") + public void testFirstWeekDay() { + selenium.type(pjq("input[type=3Dtext][id$=3DfirstWeekDayInput]"), = "6"); + selenium.waitForPageToLoad(); + + selenium.click(input); + + String[] labels =3D {"", "Sat", "Sun", "Mon", "Tue", "Wed", "Thu",= "Fri"}; + + for (int i =3D 0; i < 8; i++) { + String label =3D selenium.getText(weekDayLabel.format(i)); + assertEquals(label, labels[i], "Week day label " + i); + } + + // wrong input + selenium.type(pjq("input[type=3Dtext][id$=3DfirstWeekDayInput]"), = "9"); + selenium.waitForPageToLoad(); + + selenium.click(input); + + labels =3D new String[]{"", "Sun", "Mon", "Tue", "Wed", "Thu", "Fr= i", "Sat"}; + + for (int i =3D 0; i < 8; i++) { + String label =3D selenium.getText(weekDayLabel.format(i)); + assertEquals(label, labels[i], "Week day label " + i); + } + } + + @Test + public void testInputClass() { + testStyleClass(input, "inputClass"); + } + + @Test + public void testInputSize() { + selenium.type(pjq("input[type=3Dtext][id$=3DinputSizeInput]"), "30= "); + selenium.waitForPageToLoad(); + + AttributeLocator sizeAttr =3D input.getAttribute(Attribute.SIZE); + assertTrue(selenium.isAttributePresent(sizeAttr), "Size attribute = of input should be defined."); + assertEquals(selenium.getAttribute(sizeAttr), "30", "Input should = be disabled."); + } + + @Test + public void testInputStyle() { + testStyle(input, "inputStyle"); + } + + @Test + public void testLocale() { + selenium.type(pjq("input[type=3Dtext][id$=3DlocaleInput]"), "ru"); + selenium.waitForPageToLoad(); + + selenium.click(input); + + String[] labels =3D {"", "=D0=92=D1=81", "=D0=9F=D0=BD", "=D0=92= =D1=82", "=D0=A1=D1=80", "=D0=A7=D1=82", "=D0=9F=D1=82", "=D0=A1=D0=B1"}; + + for (int i =3D 0; i < 8; i++) { + String label =3D selenium.getText(weekDayLabel.format(i)); + assertEquals(label, labels[i], "Week day label " + i); + } + + selenium.click(cellDay.format(6)); + String day =3D selenium.getText(cellDay.format(6)); + String month =3D selenium.getText(monthLabel); + + String selectedDate =3D null; + try { + Date date =3D new SimpleDateFormat("d MMMM, yyyy hh:mm", new L= ocale("ru")).parse(day + " " + month + " 12:00"); + selectedDate =3D new SimpleDateFormat("MMM d, yyyy hh:mm", new= Locale("ru")).format(date); + } catch (ParseException ex) { + fail(ex.getMessage()); + } + + selenium.click(applyButton); + String inputDate =3D selenium.getValue(input); + assertEquals(inputDate, selectedDate, "Input doesn't contain selec= ted date."); + } + + @Test + public void testOninputblur() { + testFireEvent(Event.BLUR, input, "inputblur"); + } + + @Test + @IssueTracking("https://jira.jboss.org/browse/RF-9602") + public void testOninputchange() { + selenium.type(pjq("input[id$=3DoninputchangeInput]"), "metamerEven= ts +=3D \"inputchange \""); + selenium.waitForPageToLoad(TIMEOUT); + + selenium.click(input); + selenium.click(cellDay.format(6)); + selenium.click(applyButton); + + waitGui.failWith("Attribute oninputchange does not work correctly"= ).until( + new EventFiredCondition(new Event("inputchange"))); + } + + @Test + public void testOninputclick() { + testFireEvent(Event.CLICK, input, "inputclick"); + } + + @Test + public void testOninputdblclick() { + testFireEvent(Event.DBLCLICK, input, "inputdblclick"); + } + + @Test + public void testOninputfocus() { + testFireEvent(Event.FOCUS, input, "inputfocus"); + } + + @Test + public void testOninputkeydown() { + testFireEvent(Event.KEYDOWN, input, "inputkeydown"); + } + + @Test + public void testOninputkeypress() { + testFireEvent(Event.KEYPRESS, input, "inputkeypress"); + } + + @Test + public void testOninputkeyup() { + testFireEvent(Event.KEYUP, input, "inputkeyup"); + } + + @Test + public void testOninputmousedown() { + testFireEvent(Event.MOUSEDOWN, input, "inputmousedown"); + } + + @Test + public void testOninputmousemove() { + testFireEvent(Event.MOUSEMOVE, input, "inputmousemove"); + } + + @Test + public void testOninputmouseout() { + testFireEvent(Event.MOUSEOUT, input, "inputmouseout"); + } + + @Test + public void testOninputmouseover() { + testFireEvent(Event.MOUSEOVER, input, "inputmouseover"); + } + + @Test + public void testOninputmouseup() { + testFireEvent(Event.MOUSEUP, input, "inputmouseup"); + } + + @Test + public void testOninputselect() { + testFireEvent(Event.SELECT, input, "inputselect"); + } + + @Test + public void testPopup() { + selenium.click(pjq("input[name$=3DpopupInput][value=3Dfalse]")); + selenium.waitForPageToLoad(); + + boolean displayed =3D selenium.isDisplayed(calendar); + assertTrue(displayed, "Calendar is not present on the page."); + + if (selenium.isElementPresent(input)) { + displayed =3D selenium.isDisplayed(input); + assertFalse(displayed, "Calendar's input should not be visible= ."); + } + + if (selenium.isElementPresent(image)) { + displayed =3D selenium.isDisplayed(image); + assertFalse(displayed, "Calendar's image should not be visible= ."); + } + + displayed =3D selenium.isDisplayed(popup); + assertTrue(displayed, "Popup should be visible."); + + displayed =3D selenium.isElementPresent(button); + assertFalse(displayed, "Calendar's button should not be visible."); + } + + @Test + public void testRendered() { + selenium.click(pjq("input[type=3Dradio][name$=3DrenderedInput][val= ue=3Dfalse]")); + selenium.waitForPageToLoad(); + + assertFalse(selenium.isElementPresent(calendar), "Panel should not= be rendered when rendered=3Dfalse."); + } + + @Test + public void testShowApplyButton() { + selenium.click(pjq("input[type=3Dradio][name$=3DshowApplyButtonInp= ut][value=3Dfalse]")); + selenium.waitForPageToLoad(); + + selenium.click(input); + if (selenium.isElementPresent(applyButton)) { + assertFalse(selenium.isDisplayed(applyButton), "Apply button s= hould not be displayed."); + } + + guardNoRequest(selenium).click(cellDay.format(6)); + String day =3D selenium.getText(cellDay.format(6)); + String month =3D selenium.getText(monthLabel); + + String selectedDate =3D null; + try { + Date date =3D new SimpleDateFormat("d MMMM, yyyy hh:mm").parse= (day + " " + month + " 12:00"); + selectedDate =3D new SimpleDateFormat("MMM d, yyyy hh:mm").for= mat(date); + } catch (ParseException ex) { + fail(ex.getMessage()); + } + + assertFalse(selenium.isDisplayed(popup), "Popup should not be disp= layed."); + + String inputDate =3D selenium.getValue(input); + assertEquals(inputDate, selectedDate, "Input doesn't contain selec= ted date."); + } + + @Test + public void testShowFooter() { + selenium.click(pjq("input[type=3Dradio][name$=3DshowFooterInput][v= alue=3Dfalse]")); + selenium.waitForPageToLoad(); + + selenium.click(input); + boolean displayed =3D true; + + if (selenium.isElementPresent(todayButton)) { + displayed =3D selenium.isDisplayed(todayButton); + assertFalse(displayed, "Today button should not be visible."); + } + + if (selenium.isElementPresent(applyButton)) { + displayed =3D selenium.isDisplayed(applyButton); + assertFalse(displayed, "Apply button should not be visible."); + } + + displayed =3D selenium.isElementPresent(cleanButton); + assertFalse(displayed, "Clean button should not be visible."); + + displayed =3D selenium.isElementPresent(timeButton); + assertFalse(displayed, "Time button should not be visible."); + + selenium.click(cellWeekDay.format(3, 3)); + + if (selenium.isElementPresent(cleanButton)) { + displayed =3D selenium.isDisplayed(cleanButton); + assertFalse(displayed, "Clean button should not be visible."); + } + + if (selenium.isElementPresent(timeButton)) { + displayed =3D selenium.isDisplayed(timeButton); + assertFalse(displayed, "Time button should not be visible."); + } + } + + @Test + public void testShowHeader() { + selenium.click(pjq("input[type=3Dradio][name$=3DshowHeaderInput][v= alue=3Dfalse]")); + selenium.waitForPageToLoad(); + + selenium.click(input); + boolean displayed =3D true; + + if (selenium.isElementPresent(prevYearButton)) { + displayed =3D selenium.isDisplayed(prevYearButton); + assertFalse(displayed, "Previous year button should not be vis= ible."); + } + + if (selenium.isElementPresent(prevMonthButton)) { + displayed =3D selenium.isDisplayed(prevMonthButton); + assertFalse(displayed, "Previous month button should not be vi= sible."); + } + + if (selenium.isElementPresent(nextMonthButton)) { + displayed =3D selenium.isDisplayed(nextMonthButton); + assertFalse(displayed, "Next month button should not be visibl= e."); + } + + if (selenium.isElementPresent(nextYearButton)) { + displayed =3D selenium.isDisplayed(nextYearButton); + assertFalse(displayed, "Next year button should not be visible= ."); + } + + if (selenium.isElementPresent(closeButton)) { + displayed =3D selenium.isDisplayed(closeButton); + assertFalse(displayed, "Close button should not be visible."); + } + + if (selenium.isElementPresent(monthLabel)) { + displayed =3D selenium.isDisplayed(monthLabel); + assertFalse(displayed, "Month label should not be visible."); + } + } + + @Test + public void testShowInput() { + selenium.click(pjq("input[type=3Dradio][name$=3DshowInputInput][va= lue=3Dfalse]")); + selenium.waitForPageToLoad(); + + if (selenium.isElementPresent(input)) { + boolean displayed =3D selenium.isDisplayed(input); + assertFalse(displayed, "Input should not be visible."); + } + } + + @Test + public void testShowWeekDaysBar() { + selenium.click(pjq("input[type=3Dradio][name$=3DshowWeekDaysBarInp= ut][value=3Dfalse]")); + selenium.waitForPageToLoad(); + + for (int i =3D 0; i < 8; i++) { + if (selenium.isElementPresent(weekDayLabel.format(i))) { + boolean displayed =3D selenium.isDisplayed(weekDayLabel.fo= rmat(i)); + assertFalse(displayed, "Bar with week days should not be v= isible."); + } + } + } + + @Test + public void testShowWeeksBar() { + selenium.click(pjq("input[type=3Dradio][name$=3DshowWeeksBarInput]= [value=3Dfalse]")); + selenium.waitForPageToLoad(); + + for (int i =3D 0; i < 6; i++) { + if (selenium.isElementPresent(week.format(i))) { + boolean displayed =3D selenium.isDisplayed(week.format(i)); + assertFalse(displayed, "Bar with week numbers should not b= e visible."); + } + } + } + + /** + * Checks that no date in the open month is selected. + */ + private void assertNoDateSelected() { + for (int i =3D 0; i < 42; i++) { + assertFalse(selenium.belongsClass(cellDay.format(i), "rf-ca-se= l"), "Cell nr. " + i + " should not be selected."); + } + } + + /** + * Checks that no date in the open month is selected except of one pas= sed as argument. + * @param exceptOfDate date that should be selected (e.g. "13") + */ + private void assertSelected(String exceptOfDate) { + int lowerBoundary =3D 0; + int upperBoundary =3D 42; + + if (Integer.parseInt(exceptOfDate) < 15) { + upperBoundary =3D 21; + } else { + lowerBoundary =3D 21; + } + + // check 3 lines of cells that contain selected date + for (int i =3D lowerBoundary; i < upperBoundary; i++) { + if (exceptOfDate.equals(selenium.getText(cellDay.format(i)))) { + assertTrue(selenium.belongsClass(cellDay.format(i), "rf-ca= -sel"), "Cell nr. " + i + " should not be selected."); + } else { + assertFalse(selenium.belongsClass(cellDay.format(i), "rf-c= a-sel"), "Cell nr. " + i + " should not be selected."); + } + } + + lowerBoundary =3D lowerBoundary =3D=3D 0 ? 21 : 0; + upperBoundary =3D upperBoundary =3D=3D 21 ? 42 : 21; + + // check other 3 lines of cells + for (int i =3D lowerBoundary; i < upperBoundary; i++) { + assertFalse(selenium.belongsClass(cellDay.format(i), "rf-ca-se= l"), "Cell nr. " + i + " should not be selected."); + } + } +} Property changes on: modules/tests/metamer/trunk/ftest-source/src/main/java= /org/richfaces/tests/metamer/ftest/richCalendar/TestRichCalendarAttributes.= java ___________________________________________________________________ Name: svn:keywords + Revision Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces= /tests/metamer/ftest/richCalendar/TestRichCalendarBasic.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/te= sts/metamer/ftest/richCalendar/TestRichCalendarBasic.java = (rev 0) +++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/te= sts/metamer/ftest/richCalendar/TestRichCalendarBasic.java 2010-11-19 09:54:= 45 UTC (rev 20114) @@ -0,0 +1,336 @@ +/*************************************************************************= ****** + * JBoss, Home of Professional Open Source + * Copyright 2010, 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.richCalendar; + +import java.text.ParseException; +import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactor= y.guardNoRequest; +import static org.jboss.test.selenium.utils.URLUtils.buildUrl; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + +import java.net.URL; +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.testng.annotations.Test; + +/** + * Test case for basic functionality of calendar on page faces/components/= richCalendar/simple.xhtml. + * = + * @author Pavol Pitonak + * @version $Revision$ + */ +public class TestRichCalendarBasic extends AbstractCalendarTest { + + @Override + public URL getTestUrl() { + return buildUrl(contextPath, "faces/components/richCalendar/simple= .xhtml"); + } + + @Test + public void testInit() { + boolean displayed =3D selenium.isDisplayed(calendar); + assertTrue(displayed, "Calendar is not present on the page."); + + displayed =3D selenium.isDisplayed(input); + assertTrue(displayed, "Calendar's input should be visible."); + + displayed =3D selenium.isDisplayed(image); + assertTrue(displayed, "Calendar's image should be visible."); + + displayed =3D selenium.isDisplayed(popup); + assertFalse(displayed, "Popup should not be visible."); + + displayed =3D selenium.isElementPresent(button); + assertFalse(displayed, "Calendar's button should not be visible."); + } + + @Test + public void testOpenPopupClickOnInput() { + guardNoRequest(selenium).click(input); + boolean displayed =3D selenium.isDisplayed(popup); + assertTrue(displayed, "Popup should be visible."); + } + + @Test + public void testOpenPopupClickOnImage() { + guardNoRequest(selenium).click(image); + boolean displayed =3D selenium.isDisplayed(popup); + assertTrue(displayed, "Popup should be visible."); + } + + @Test + public void testHeaderButtons() { + selenium.click(input); + + boolean displayed =3D selenium.isDisplayed(prevYearButton); + assertTrue(displayed, "Previous year button should be visible."); + String buttonText =3D selenium.getText(prevYearButton); + assertEquals(buttonText, "<<", "Previous year button"); + + displayed =3D selenium.isDisplayed(prevMonthButton); + assertTrue(displayed, "Previous month button should be visible."); + buttonText =3D selenium.getText(prevMonthButton); + assertEquals(buttonText, "<", "Previous month button"); + + displayed =3D selenium.isDisplayed(nextMonthButton); + assertTrue(displayed, "Next month button should be visible."); + buttonText =3D selenium.getText(nextMonthButton); + assertEquals(buttonText, ">", "Next month button"); + + displayed =3D selenium.isDisplayed(nextYearButton); + assertTrue(displayed, "Next year button should be visible."); + buttonText =3D selenium.getText(nextYearButton); + assertEquals(buttonText, ">>", "Next year button"); + + displayed =3D selenium.isDisplayed(closeButton); + assertTrue(displayed, "Close button should be visible."); + buttonText =3D selenium.getText(closeButton); + assertEquals(buttonText, "x", "Close button"); + } + + @Test + public void testHeaderMonth() { + SimpleDateFormat formatter =3D new SimpleDateFormat("MMMM, yyyy"); + String month =3D formatter.format(new Date()); + + selenium.click(input); + String month2 =3D selenium.getText(monthLabel); + assertEquals(month2, month, "Calendar shows wrong month or year in= its header."); + } + + @Test + public void testFooterButtons() { + selenium.click(input); + + boolean displayed =3D selenium.isDisplayed(todayButton); + assertTrue(displayed, "Today button should be visible."); + String buttonText =3D selenium.getText(todayButton); + assertEquals(buttonText, "Today", "Button's text"); + + displayed =3D selenium.isDisplayed(applyButton); + assertTrue(displayed, "Apply button should be visible."); + buttonText =3D selenium.getText(applyButton); + assertEquals(buttonText, "Apply", "Button's text"); + + displayed =3D selenium.isElementPresent(cleanButton); + assertFalse(displayed, "Clean button should not be visible."); + + displayed =3D selenium.isElementPresent(timeButton); + assertFalse(displayed, "Time button should not be visible."); + + selenium.click(cellWeekDay.format(3, 3)); + + displayed =3D selenium.isDisplayed(cleanButton); + assertTrue(displayed, "Clean button should be visible."); + buttonText =3D selenium.getText(cleanButton); + assertEquals(buttonText, "Clean", "Button's text"); + + displayed =3D selenium.isDisplayed(timeButton); + assertTrue(displayed, "Time button should be visible."); + buttonText =3D selenium.getText(timeButton); + assertEquals(buttonText, "12:00", "Button's text"); + } + + @Test + public void testWeekDaysLabels() { + selenium.click(input); + + String[] labels =3D {"", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri",= "Sat"}; + + for (int i =3D 0; i < 8; i++) { + String label =3D selenium.getText(weekDayLabel.format(i)); + assertEquals(label, labels[i], "Week day label " + i); + } + } + + @Test + public void testTodayIsSelected() { + SimpleDateFormat formatter =3D new SimpleDateFormat("d"); + String today =3D formatter.format(new Date()); + + int lowerBoundary =3D 0; + int upperBoundary =3D 42; + + // go through first half of popup or second half of popup dependin= g on today's date + // it is necessary because of dates from other months are also dis= played + if (Integer.parseInt(today) < 15) { + upperBoundary =3D 28; + } else { + lowerBoundary =3D 14; + } + + selenium.click(input); + + for (int i =3D lowerBoundary; i < upperBoundary; i++) { + String day =3D selenium.getText(cellDay.format(i)); + if (day.equals(today)) { + assertTrue(selenium.belongsClass(cellDay.format(i), "rf-ca= -today"), "Today's date is not styled correctly."); + return; + } + } + + fail("Today's date is not styled correctly."); + } + + @Test + public void testWeekNumbers() { + selenium.click(input); + String month =3D selenium.getText(monthLabel); + String day =3D selenium.getText(cellDay.format(6)); + + Date date =3D null; + try { + date =3D new SimpleDateFormat("d MMMM, yyyy").parse(day + " " = + month); + } catch (ParseException ex) { + fail(ex.getMessage()); + } + String weekNumber =3D new SimpleDateFormat("w").format(date); + + assertEquals(selenium.getText(week.format(0)), weekNumber, "Week n= umber on the first line."); + } + + @Test + public void testSelectDate() { + selenium.click(input); + + guardNoRequest(selenium).click(cellDay.format(6)); + assertTrue(selenium.belongsClass(cellDay.format(6), "rf-ca-sel"), = "Last date in the first week is not selected."); + + selenium.click(cellDay.format(8)); + assertFalse(selenium.belongsClass(cellDay.format(6), "rf-ca-sel"),= "Last date in the first week should not be selected."); + } + + @Test + public void testCleanButton() { + selenium.click(input); + selenium.click(cellDay.format(6)); + + guardNoRequest(selenium).click(cleanButton); + assertFalse(selenium.belongsClass(cellDay.format(6), "rf-ca-sel"),= "Last date in the first week should not be selected."); + } + + @Test + public void testCloseButton() { + selenium.click(input); + boolean displayed =3D selenium.isDisplayed(popup); + assertTrue(displayed, "Popup should be visible."); + + guardNoRequest(selenium).click(closeButton); + displayed =3D selenium.isDisplayed(popup); + assertFalse(displayed, "Popup should not be visible."); + } + + @Test + public void testPrevYearButton() { + selenium.click(input); + String thisYear =3D selenium.getText(monthLabel); + // November, 2010 -> 2010 + thisYear =3D thisYear.substring(thisYear.indexOf(" ") + 1, thisYea= r.length()); + + guardNoRequest(selenium).click(prevYearButton); + String prevYear =3D selenium.getText(monthLabel); + prevYear =3D prevYear.substring(prevYear.indexOf(" ") + 1, prevYea= r.length()); + + assertEquals(Integer.parseInt(prevYear), Integer.parseInt(thisYear= ) - 1, "Year did not change correctly."); + } + + @Test + public void testNextYearButton() { + selenium.click(input); + String thisYear =3D selenium.getText(monthLabel); + // November, 2010 -> 2010 + thisYear =3D thisYear.substring(thisYear.indexOf(" ") + 1, thisYea= r.length()); + + guardNoRequest(selenium).click(nextYearButton); + String nextYear =3D selenium.getText(monthLabel); + nextYear =3D nextYear.substring(nextYear.indexOf(" ") + 1, nextYea= r.length()); + + assertEquals(Integer.parseInt(nextYear), Integer.parseInt(thisYear= ) + 1, "Year did not change correctly."); + } + + @Test + public void testPrevMonthButton() { + selenium.click(input); + String thisMonth =3D selenium.getText(monthLabel); + // November, 2010 -> November + thisMonth =3D thisMonth.substring(0, thisMonth.indexOf(",")); + + guardNoRequest(selenium).click(prevMonthButton); + String prevMonth =3D selenium.getText(monthLabel); + prevMonth =3D prevMonth.substring(0, prevMonth.indexOf(",")); + + assertEquals(Month.valueOf(prevMonth), Month.valueOf(thisMonth).pr= evious(), "Month did not change correctly."); + } + + @Test + public void testNextMonthButton() { + selenium.click(input); + String thisMonth =3D selenium.getText(monthLabel); + // November, 2010 -> November + thisMonth =3D thisMonth.substring(0, thisMonth.indexOf(",")); + + guardNoRequest(selenium).click(nextMonthButton); + String nextMonth =3D selenium.getText(monthLabel); + nextMonth =3D nextMonth.substring(0, nextMonth.indexOf(",")); + + assertEquals(Month.valueOf(nextMonth), Month.valueOf(thisMonth).ne= xt(), "Month did not change correctly."); + } + + @Test + public void testTodayButton() { + selenium.click(input); + String thisMonth =3D selenium.getText(monthLabel); + + selenium.click(nextMonthButton); + selenium.click(prevYearButton); + guardNoRequest(selenium).click(todayButton); + String thisMonth2 =3D selenium.getText(monthLabel); + + assertEquals(thisMonth2, thisMonth, "Today button does not work."); + } + + @Test + public void testApplyButton() { + selenium.click(input); + + selenium.click(cellDay.format(6)); + String day =3D selenium.getText(cellDay.format(6)); + String month =3D selenium.getText(monthLabel); + + String selectedDate =3D null; + try { + Date date =3D new SimpleDateFormat("d MMMM, yyyy hh:mm").parse= (day + " " + month + " 12:00"); + selectedDate =3D new SimpleDateFormat("MMM d, yyyy hh:mm").for= mat(date); + } catch (ParseException ex) { + fail(ex.getMessage()); + } + + guardNoRequest(selenium).click(applyButton); + assertFalse(selenium.isDisplayed(popup), "Popup should not be disp= layed."); + + String inputDate =3D selenium.getValue(input); + assertEquals(inputDate, selectedDate, "Input doesn't contain selec= ted date."); + } +} Property changes on: modules/tests/metamer/trunk/ftest-source/src/main/java= /org/richfaces/tests/metamer/ftest/richCalendar/TestRichCalendarBasic.java ___________________________________________________________________ Name: svn:keywords + Revision --===============3513693011945531321==--