From 93d73859a9a66086528ef35510cfff15e47dd827 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sauli=20T=C3=A4hk=C3=A4p=C3=A4=C3=A4?= Date: Sun, 9 Nov 2014 23:15:28 +0200 Subject: [PATCH] Check if event move is allowed also in month view. (#15174) Change-Id: Ie4f01a74d3f2a8e388aed0c2d8b1a99384cb042f --- .../ui/calendar/schedule/SimpleDayCell.java | 2 +- .../calendar/NullEventMoveHandler.java | 52 +++++++++++++++++ .../calendar/NullEventMoveHandlerTest.java | 56 +++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandler.java create mode 100644 uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandlerTest.java diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java b/client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java index db8452af9a..424531ee58 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java @@ -436,7 +436,7 @@ public class SimpleDayCell extends FocusableFlowPanel implements // event clicks should be allowed even when read-only monthEventMouseDown = true; - if (w instanceof MonthEventLabel) { + if (calendar.isEventMoveAllowed()) { startCalendarEventDrag(event, (MonthEventLabel) w); } } else if (!calendar.isReadOnly()) { diff --git a/uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandler.java b/uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandler.java new file mode 100644 index 0000000000..c2dfdb26c1 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandler.java @@ -0,0 +1,52 @@ +package com.vaadin.tests.components.calendar; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Locale; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Calendar; +import com.vaadin.ui.components.calendar.CalendarComponentEvents; +import com.vaadin.ui.components.calendar.event.BasicEvent; + +public class NullEventMoveHandler extends AbstractTestUI { + @Override + protected void setup(VaadinRequest request) { + Calendar calendar = getCalendar(); + + calendar.setHandler((CalendarComponentEvents.EventMoveHandler) null); + + addComponent(calendar); + } + + private Calendar getCalendar() { + Calendar calendar = new Calendar(); + calendar.setLocale(Locale.US); + + try { + calendar.setStartDate(new SimpleDateFormat("yyyy-MM-dd") + .parse("2014-06-01")); + calendar.setEndDate(new SimpleDateFormat("yyyy-MM-dd") + .parse("2014-06-30")); + + BasicEvent event = new BasicEvent("foo", "bar", + new SimpleDateFormat("yyyy-MM-dd").parse("2014-06-01")); + + calendar.addEvent(event); + } catch (ParseException e) { + e.printStackTrace(); + } + return calendar; + } + + @Override + protected Integer getTicketNumber() { + return 15174; + } + + @Override + protected String getTestDescription() { + return "Events should not be movable when EventMoveHandler is null."; + } +} diff --git a/uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandlerTest.java b/uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandlerTest.java new file mode 100644 index 0000000000..c40cd9ce97 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandlerTest.java @@ -0,0 +1,56 @@ +package com.vaadin.tests.components.calendar; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.DndActionsTest; + +public class NullEventMoveHandlerTest extends DndActionsTest { + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + } + + @Test + public void eventIsNotMovableInMonthView() { + assertEventCannotBeMoved(); + } + + @Test + public void eventIsNotMovableInWeekView() { + openWeekView(); + assertEventCannotBeMoved(); + } + + private void assertEventCannotBeMoved() { + int originalPosition = getEventXPosition(); + + moveEventToNextDay(); + + assertThat("Event position changed.", getEventXPosition(), + is(originalPosition)); + } + + private void openWeekView() { + getDriver().findElement(By.className("v-calendar-week-number")).click(); + } + + private void moveEventToNextDay() { + WebElement event = getEvent(); + dragAndDrop(event, event.getSize().getWidth() + 5, 0); + } + + private int getEventXPosition() { + return getEvent().getLocation().getX(); + } + + private WebElement getEvent() { + return getDriver().findElement(By.className("v-calendar-event")); + } +} \ No newline at end of file -- 2.39.5