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.

DateTimeFieldWeekDaysTest.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright 2000-2016 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.components.datefield;
  17. import org.junit.Assert;
  18. import org.junit.Test;
  19. import org.openqa.selenium.WebElement;
  20. import org.openqa.selenium.support.ui.ExpectedConditions;
  21. import com.vaadin.testbench.By;
  22. import com.vaadin.testbench.customelements.DateTimeFieldElement;
  23. import com.vaadin.testbench.elements.ButtonElement;
  24. import com.vaadin.testbench.elements.CheckBoxElement;
  25. import com.vaadin.tests.tb3.SingleBrowserTest;
  26. public class DateTimeFieldWeekDaysTest extends SingleBrowserTest {
  27. @Test
  28. public void testFiLocale_weekNumbersVisible() {
  29. openTestURL();
  30. openPopupAndValidateWeekNumbers();
  31. }
  32. @Test
  33. public void testToggleWeekNumbers_renderedCorrectly() {
  34. openTestURL();
  35. openPopupAndValidateWeekNumbers();
  36. $(CheckBoxElement.class).first().click();
  37. Assert.assertFalse("Checkbox is selected even though should be unselected.", $(CheckBoxElement.class).first().isChecked());
  38. openPopupAndValidateNoWeeknumbers();
  39. }
  40. @Test
  41. public void testLocaleChangeToEnglish_removesWeekNumbers() {
  42. openTestURL();
  43. openPopupAndValidateWeekNumbers();
  44. $(ButtonElement.class).id("english").click();
  45. openPopupAndValidateNoWeeknumbers();
  46. }
  47. @Test
  48. public void testChangeBackToFinnish_weekNumbersVisible() {
  49. openTestURL();
  50. $(ButtonElement.class).id("english").click();
  51. openPopupAndValidateNoWeeknumbers();
  52. $(ButtonElement.class).id("finnish").click();
  53. openPopupAndValidateWeekNumbers();
  54. }
  55. private void openPopupAndValidateWeekNumbers() {
  56. WebElement popupButton = $(DateTimeFieldElement.class).first()
  57. .findElement(By.className("v-datefield-button"));
  58. // Open date popup
  59. popupButton.click();
  60. waitUntil(ExpectedConditions.visibilityOfElementLocated(
  61. org.openqa.selenium.By.className("v-datefield-popup")));
  62. Assert.assertFalse("No week numbers found for date field!",
  63. findElements(
  64. By.className("v-datefield-calendarpanel-weeknumber"))
  65. .isEmpty());
  66. // Close popup
  67. popupButton.click();
  68. }
  69. private void openPopupAndValidateNoWeeknumbers() {
  70. WebElement popupButton = $(DateTimeFieldElement.class).first()
  71. .findElement(By.className("v-datefield-button"));
  72. // Open date popup
  73. popupButton.click();
  74. waitUntil(ExpectedConditions.visibilityOfElementLocated(
  75. org.openqa.selenium.By.className("v-datefield-popup")));
  76. Assert.assertTrue("Week numbers still found in calendar popup!",
  77. findElements(
  78. By.className("v-datefield-calendarpanel-weeknumber"))
  79. .isEmpty());
  80. // Close popup
  81. popupButton.click();
  82. }
  83. }