aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeemu Pòˆntelin <teemu@vaadin.com>2014-05-05 23:58:00 +0300
committerVaadin Code Review <review@vaadin.com>2014-05-14 07:24:41 +0000
commitac6a98648d54fc89cab5c5cecc2d9f1b9a3b01dc (patch)
treecda58ae8d2e388e30d3b30fba029c647443a004a
parent717d868b79896811e5a9489239f3eea42e1fed09 (diff)
downloadvaadin-framework-ac6a98648d54fc89cab5c5cecc2d9f1b9a3b01dc.tar.gz
vaadin-framework-ac6a98648d54fc89cab5c5cecc2d9f1b9a3b01dc.zip
Fixed disabled and read-only modes of InlineDateField (#10262)
Change-Id: If95d50954a4122b1039174ffcacd7874f7f1f71e
-rw-r--r--client/src/com/vaadin/client/ui/VCalendarPanel.java12
-rw-r--r--uitest/src/com/vaadin/tests/components/datefield/DisabledInlineDateField.java58
-rw-r--r--uitest/src/com/vaadin/tests/components/datefield/DisabledInlineDateFieldTest.java79
3 files changed, 143 insertions, 6 deletions
diff --git a/client/src/com/vaadin/client/ui/VCalendarPanel.java b/client/src/com/vaadin/client/ui/VCalendarPanel.java
index 5bdb3388e9..d8c96917d8 100644
--- a/client/src/com/vaadin/client/ui/VCalendarPanel.java
+++ b/client/src/com/vaadin/client/ui/VCalendarPanel.java
@@ -139,6 +139,10 @@ public class VCalendarPanel extends FocusableFlexTable implements
*/
@Override
public void onClick(ClickEvent event) {
+ if (!isEnabled() || isReadonly()) {
+ return;
+ }
+
Date newDate = ((Day) event.getSource()).getDate();
if (!isDateInsideRange(newDate, Resolution.DAY)) {
return;
@@ -175,10 +179,6 @@ public class VCalendarPanel extends FocusableFlexTable implements
private Date value;
- private boolean enabled = true;
-
- private boolean readonly = false;
-
private DateTimeService dateTimeService;
private boolean showISOWeekNumbers;
@@ -350,11 +350,11 @@ public class VCalendarPanel extends FocusableFlexTable implements
}
private boolean isReadonly() {
- return readonly;
+ return parent.isReadonly();
}
private boolean isEnabled() {
- return enabled;
+ return parent.isEnabled();
}
@Override
diff --git a/uitest/src/com/vaadin/tests/components/datefield/DisabledInlineDateField.java b/uitest/src/com/vaadin/tests/components/datefield/DisabledInlineDateField.java
new file mode 100644
index 0000000000..affc5d322c
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/datefield/DisabledInlineDateField.java
@@ -0,0 +1,58 @@
+/*
+ * 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.datefield;
+
+import java.util.Calendar;
+import java.util.Date;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.DateField;
+import com.vaadin.ui.InlineDateField;
+
+public class DisabledInlineDateField extends AbstractTestUI {
+
+ private static final Date testDate;
+ static {
+ Calendar cal = Calendar.getInstance();
+ cal.set(2014, 5, 5);
+ testDate = cal.getTime();
+ }
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ DateField df = new InlineDateField("Disabled");
+ df.setValue(testDate);
+ df.setEnabled(false);
+ addComponent(df);
+
+ df = new InlineDateField("Read-only");
+ df.setValue(testDate);
+ df.setReadOnly(true);
+ addComponent(df);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Testing disabled and read-only modes of InlineDateField.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 10262;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/datefield/DisabledInlineDateFieldTest.java b/uitest/src/com/vaadin/tests/components/datefield/DisabledInlineDateFieldTest.java
new file mode 100644
index 0000000000..2c50030461
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/datefield/DisabledInlineDateFieldTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.datefield;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class DisabledInlineDateFieldTest extends MultiBrowserTest {
+
+ @Test
+ public void testDisabled() {
+ openTestURL();
+ testNextMonthControls(".v-disabled");
+ testDaySelection(".v-disabled");
+ }
+
+ @Test
+ public void testReadOnly() {
+ openTestURL();
+ testNextMonthControls(".v-readonly");
+ testDaySelection(".v-readonly");
+ }
+
+ private void testNextMonthControls(String cssClass) {
+ // Get the currently selected month.
+ String expectedMonth = getSelectedMonth(cssClass);
+
+ // Attempt to click the next month button.
+ driver.findElement(By.cssSelector(cssClass + " .v-button-nextmonth"))
+ .click();
+
+ // Assert that we did not navigate to next month.
+ String actualMonth = getSelectedMonth(cssClass);
+ assertEquals(expectedMonth, actualMonth);
+ }
+
+ private void testDaySelection(String cssClass) {
+ // We know that the first day element is not selected, because of the
+ // fixed date in the test.
+ WebElement nonSelectedDay = driver.findElement(By.cssSelector(cssClass
+ + " .v-inline-datefield-calendarpanel-day"));
+
+ // Assert it is not selected before click.
+ assertFalse(nonSelectedDay.getAttribute("class").contains("selected"));
+
+ // Click on the non-selected day.
+ nonSelectedDay.click();
+
+ // Assert that clicking did not select the day.
+ assertFalse(nonSelectedDay.getAttribute("class").contains("selected"));
+ }
+
+ private String getSelectedMonth(String selectorPrefix) {
+ return driver.findElement(
+ By.cssSelector(selectorPrefix
+ + " .v-inline-datefield-calendarpanel-month"))
+ .getText();
+ }
+
+}