]> source.dussan.org Git - vaadin-framework.git/commitdiff
Check if event move is allowed also in month view. (#15174)
authorSauli Tähkäpää <sauli@vaadin.com>
Sun, 9 Nov 2014 21:15:28 +0000 (23:15 +0200)
committerLeif Åstrand <leif@vaadin.com>
Thu, 5 Feb 2015 09:35:51 +0000 (11:35 +0200)
Change-Id: Ie4f01a74d3f2a8e388aed0c2d8b1a99384cb042f

client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java
uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandler.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandlerTest.java [new file with mode: 0644]

index db8452af9aef315380fdb74cc93123d09d9b6f63..424531ee583aef34d83fcce61f6b75cb3214d4c6 100644 (file)
@@ -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 (file)
index 0000000..c2dfdb2
--- /dev/null
@@ -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 (file)
index 0000000..c40cd9c
--- /dev/null
@@ -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