You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DateFieldDeclarativeTest.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.server.component.datefield;
  17. import java.util.Date;
  18. import java.util.TimeZone;
  19. import org.junit.Test;
  20. import com.vaadin.shared.ui.datefield.Resolution;
  21. import com.vaadin.tests.design.DeclarativeTestBase;
  22. import com.vaadin.ui.DateField;
  23. /**
  24. * Tests the declarative support for implementations of {@link DateField}.
  25. *
  26. * @since 7.4
  27. * @author Vaadin Ltd
  28. */
  29. public class DateFieldDeclarativeTest extends DeclarativeTestBase<DateField> {
  30. private String getYearResolutionDesign() {
  31. return "<vaadin-date-field resolution='year' value='2020'/>";
  32. }
  33. private DateField getYearResolutionExpected() {
  34. DateField df = new DateField();
  35. df.setResolution(Resolution.YEAR);
  36. df.setValue(new Date(2020 - 1900, 1 - 1, 1));
  37. return df;
  38. }
  39. private String getTimezoneDesign() {
  40. return "<vaadin-date-field range-start=\"2014-05-05 00:00:00+0300\" range-end=\"2014-06-05 00:00:00+0300\" date-out-of-range-message=\"Please select a sensible date\" date-format=\"yyyy-MM-dd\" lenient show-iso-week-numbers parse-error-message=\"You are doing it wrong\" time-zone=\"GMT+05:00\" value=\"2014-05-15 00:00:00+0300\"/>";
  41. }
  42. private DateField getTimezoneExpected() {
  43. DateField df = new DateField();
  44. df.setRangeStart(new Date(2014 - 1900, 5 - 1, 5));
  45. df.setRangeEnd(new Date(2014 - 1900, 6 - 1, 5));
  46. df.setDateOutOfRangeMessage("Please select a sensible date");
  47. df.setResolution(Resolution.DAY);
  48. df.setDateFormat("yyyy-MM-dd");
  49. df.setLenient(true);
  50. df.setShowISOWeekNumbers(true);
  51. df.setParseErrorMessage("You are doing it wrong");
  52. df.setTimeZone(TimeZone.getTimeZone("GMT+5"));
  53. df.setValue(new Date(2014 - 1900, 5 - 1, 15));
  54. return df;
  55. }
  56. @Test
  57. public void readTimezone() {
  58. testRead(getTimezoneDesign(), getTimezoneExpected());
  59. }
  60. @Test
  61. public void writeTimezone() {
  62. testWrite(getTimezoneDesign(), getTimezoneExpected());
  63. }
  64. @Test
  65. public void readYearResolution() {
  66. testRead(getYearResolutionDesign(), getYearResolutionExpected());
  67. }
  68. @Test
  69. public void writeYearResolution() {
  70. // Writing is always done in full resolution..
  71. testWrite(
  72. getYearResolutionDesign().replace("2020",
  73. "2020-01-01 00:00:00+0200"),
  74. getYearResolutionExpected());
  75. }
  76. @Test
  77. public void testReadOnlyValue() {
  78. String design = "<vaadin-date-field readonly resolution='year' value='2020-01-01 00:00:00+0200'/>";
  79. DateField df = new DateField();
  80. df.setResolution(Resolution.YEAR);
  81. df.setValue(new Date(2020 - 1900, 1 - 1, 1));
  82. df.setReadOnly(true);
  83. testRead(design, df);
  84. testWrite(design, df);
  85. }
  86. }