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.

GridEditorRowTest.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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.components.grid.basicfeatures.server;
  17. import static org.junit.Assert.assertEquals;
  18. import static org.junit.Assert.assertNotNull;
  19. import static org.junit.Assert.assertNull;
  20. import java.util.List;
  21. import org.junit.Before;
  22. import org.junit.Test;
  23. import org.openqa.selenium.By;
  24. import org.openqa.selenium.Keys;
  25. import org.openqa.selenium.NoSuchElementException;
  26. import org.openqa.selenium.WebElement;
  27. import org.openqa.selenium.interactions.Actions;
  28. import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures;
  29. import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
  30. public class GridEditorRowTest extends GridBasicFeaturesTest {
  31. @Before
  32. public void setUp() {
  33. openTestURL();
  34. selectMenuPath("Component", "Editor row", "Enabled");
  35. }
  36. @Test
  37. public void testProgrammaticOpeningClosing() {
  38. selectMenuPath("Component", "Editor row", "Edit item 5");
  39. assertNotNull(getEditorRow());
  40. selectMenuPath("Component", "Editor row", "Cancel edit");
  41. assertNull(getEditorRow());
  42. }
  43. @Test
  44. public void testProgrammaticOpeningWhenDisabled() {
  45. selectMenuPath("Component", "Editor row", "Enabled");
  46. selectMenuPath("Component", "Editor row", "Edit item 5");
  47. assertNull(getEditorRow());
  48. assertEquals(
  49. "4. Exception occured, java.lang.IllegalStateExceptionThis EditorRow is not enabled",
  50. getLogRow(0));
  51. }
  52. @Test
  53. public void testDisablingWhileOpen() {
  54. selectMenuPath("Component", "Editor row", "Edit item 5");
  55. selectMenuPath("Component", "Editor row", "Enabled");
  56. assertNotNull(getEditorRow());
  57. assertEquals(
  58. "4. Exception occured, java.lang.IllegalStateExceptionCannot disable the editor row while an item (5) is being edited.",
  59. getLogRow(0));
  60. }
  61. @Test
  62. public void testProgrammaticOpeningWithScroll() {
  63. selectMenuPath("Component", "Editor row", "Edit item 100");
  64. assertNotNull(getEditorRow());
  65. }
  66. @Test(expected = NoSuchElementException.class)
  67. public void testVerticalScrollLocking() {
  68. selectMenuPath("Component", "Editor row", "Edit item 5");
  69. getGridElement().getCell(200, 0);
  70. }
  71. @Test
  72. public void testKeyboardOpeningClosing() {
  73. getGridElement().getCell(4, 0).click();
  74. new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
  75. assertNotNull(getEditorRow());
  76. new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform();
  77. assertNull(getEditorRow());
  78. // Disable editor row
  79. selectMenuPath("Component", "Editor row", "Enabled");
  80. getGridElement().getCell(5, 0).click();
  81. new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
  82. assertNull(getEditorRow());
  83. }
  84. @Test
  85. public void testComponentBinding() {
  86. selectMenuPath("Component", "State", "Editor row", "Edit item 100");
  87. List<WebElement> widgets = getEditorRow().findElements(
  88. By.className("v-widget"));
  89. assertEquals(GridBasicFeatures.COLUMNS, widgets.size());
  90. assertEquals("(100, 0)", widgets.get(0).getAttribute("value"));
  91. assertEquals("(100, 1)", widgets.get(1).getAttribute("value"));
  92. assertEquals("(100, 2)", widgets.get(2).getAttribute("value"));
  93. assertEquals("<b>100</b>", widgets.get(9).getAttribute("value"));
  94. }
  95. @Test
  96. public void testCommit() {
  97. selectMenuPath("Component", "Editor row", "Edit item 100");
  98. List<WebElement> widgets = getEditorRow().findElements(
  99. By.className("v-textfield"));
  100. widgets.get(0).click();
  101. widgets.get(0).sendKeys(" changed");
  102. WebElement saveButton = getEditorRow().findElement(
  103. By.className("v-editor-row-save"));
  104. saveButton.click();
  105. assertEquals("(100, 0) changed", getGridElement().getCell(100, 0)
  106. .getText());
  107. }
  108. @Test
  109. public void testDiscard() {
  110. selectMenuPath("Component", "Editor row", "Edit item 100");
  111. List<WebElement> widgets = getEditorRow().findElements(
  112. By.className("v-textfield"));
  113. widgets.get(0).sendKeys(" changed");
  114. selectMenuPath("Component", "Editor row", "Discard");
  115. assertEquals("(100, 0)", getGridElement().getCell(100, 0).getText());
  116. }
  117. }