diff options
author | Artur Signell <artur@vaadin.com> | 2014-12-19 01:50:32 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2015-01-02 16:40:29 +0200 |
commit | 26832b6947266ce5cffd92558c23e6556278038d (patch) | |
tree | 6e550fb5dc1510c22b5d76e097970a0f97e4c31d /uitest | |
parent | fea60eaea2c791766be9f17ff2900739b32bf576 (diff) | |
download | vaadin-framework-26832b6947266ce5cffd92558c23e6556278038d.tar.gz vaadin-framework-26832b6947266ce5cffd92558c23e6556278038d.zip |
Option for rendering Calendar event captions as HTML (#9030)
Change-Id: Ib7f6e67c242449e58a10359c596489fea2f679f6
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/com/vaadin/tests/components/calendar/CalendarHtmlInEvents.java | 101 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/components/calendar/CalendarHtmlInEventsTest.java | 103 |
2 files changed, 204 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarHtmlInEvents.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarHtmlInEvents.java new file mode 100644 index 0000000000..15cde71838 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarHtmlInEvents.java @@ -0,0 +1,101 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed 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 com.vaadin.tests.components.calendar; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.data.util.MethodProperty; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Calendar; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.NativeSelect; +import com.vaadin.ui.components.calendar.event.BasicEvent; +import com.vaadin.ui.components.calendar.event.CalendarEvent; +import com.vaadin.ui.components.calendar.event.CalendarEventProvider; + +public class CalendarHtmlInEvents extends AbstractTestUIWithLog { + + private Calendar calendar = new Calendar(); + + @Override + protected void setup(VaadinRequest request) { + final NativeSelect ns = new NativeSelect("Period"); + ns.addItems("Day", "Week", "Month"); + ns.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + if ("Day".equals(ns.getValue())) { + calendar.setStartDate(new Date(2014 - 1900, 1 - 1, 1)); + calendar.setEndDate(new Date(2014 - 1900, 1 - 1, 1)); + } else if ("Week".equals(ns.getValue())) { + calendar.setStartDate(new Date(2014 - 1900, 1 - 1, 1)); + calendar.setEndDate(new Date(2014 - 1900, 1 - 1, 7)); + } else if ("Month".equals(ns.getValue())) { + calendar.setStartDate(new Date(2014 - 1900, 1 - 1, 1)); + calendar.setEndDate(new Date(2014 - 1900, 2 - 1, 1)); + } + } + }); + ns.setValue("Month"); + final CheckBox allowHtml = new CheckBox("Allow HTML in event caption", + new MethodProperty<Boolean>(calendar, "eventCaptionAsHtml")); + allowHtml.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + log("HTML in event caption: " + allowHtml.getValue()); + } + }); + HorizontalLayout hl = new HorizontalLayout(); + hl.setDefaultComponentAlignment(Alignment.BOTTOM_LEFT); + hl.addComponents(ns, allowHtml); + hl.setSpacing(true); + hl.setMargin(true); + calendar.setEventProvider(new CalendarEventProvider() { + + @Override + public List<CalendarEvent> getEvents(Date startDate, Date endDate) { + Date d = startDate; + ArrayList<CalendarEvent> events = new ArrayList<CalendarEvent>(); + while (d.before(endDate)) { + BasicEvent ce = new BasicEvent(); + ce.setAllDay(false); + ce.setCaption("<b>Hello</b> <u>world</u>!"); + ce.setDescription("Nothing really important"); + Date start = new Date(d.getTime()); + start.setHours(d.getDay()); + Date end = new Date(d.getTime()); + end.setHours(d.getDay() + 3); + ce.setStart(start); + ce.setEnd(end); + events.add(ce); + d.setTime(d.getTime() + 1000 * 60 * 60 * 24); + } + + return events; + } + + }); + addComponent(hl); + addComponent(calendar); + } +} diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarHtmlInEventsTest.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarHtmlInEventsTest.java new file mode 100644 index 0000000000..31e3f754e3 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarHtmlInEventsTest.java @@ -0,0 +1,103 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed 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 com.vaadin.tests.components.calendar; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.CalendarElement; +import com.vaadin.testbench.elements.CheckBoxElement; +import com.vaadin.testbench.elements.NativeSelectElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class CalendarHtmlInEventsTest extends SingleBrowserTest { + + private NativeSelectElement periodSelect; + private CheckBoxElement htmlAllowed; + private CalendarElement calendar; + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + periodSelect = $(NativeSelectElement.class).first(); + htmlAllowed = $(CheckBoxElement.class).first(); + calendar = $(CalendarElement.class).first(); + } + + @Test + public void monthViewEventCaptions() { + Assert.assertEquals(getMonthEvent(0).getText(), + "12:00 AM <b>Hello</b> <u>world</u>!"); + + // Switch to HTML mode + click(htmlAllowed); + Assert.assertEquals("1. HTML in event caption: true", getLogRow(0)); + + Assert.assertEquals(getMonthEvent(0).getText(), "12:00 AM Hello world!"); + } + + @Test + public void weekViewEventCaptions() { + periodSelect.selectByText("Week"); + Assert.assertEquals("4:00 AM\n<b>Hello</b> <u>world</u>!", + getWeekEvent(1).getText()); + + // Switch to HTML mode + click(htmlAllowed); + Assert.assertEquals("1. HTML in event caption: true", getLogRow(0)); + + Assert.assertEquals("4:00 AM\nHello world!", getWeekEvent(1).getText()); + } + + @Test + public void dayViewEventCaptions() { + periodSelect.selectByText("Day"); + Assert.assertEquals("3:00 AM\n<b>Hello</b> <u>world</u>!", + getWeekEvent(0).getText()); + + // Switch to HTML mode + click(htmlAllowed); + Assert.assertEquals("1. HTML in event caption: true", getLogRow(0)); + Assert.assertEquals("3:00 AM\nHello world!", getWeekEvent(0).getText()); + } + + private WebElement getMonthEvent(int dayInCalendar) { + return getMonthDay(dayInCalendar).findElement( + By.className("v-calendar-event")); + } + + private WebElement getWeekEvent(int dayInCalendar) { + return getWeekDay(dayInCalendar).findElement( + By.className("v-calendar-event")); + } + + private void click(CheckBoxElement htmlAllowed2) { + htmlAllowed2.findElement(By.xpath("input")).click(); + } + + private WebElement getMonthDay(int i) { + return calendar.findElements(By.className("v-calendar-month-day")).get( + i); + } + + private WebElement getWeekDay(int i) { + return calendar.findElements(By.className("v-calendar-day-times")).get( + i); + } +} |