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.

GridContextClickTest.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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.contextclick;
  17. import static org.junit.Assert.assertEquals;
  18. import org.junit.Ignore;
  19. import org.junit.Test;
  20. import org.openqa.selenium.WebElement;
  21. import com.vaadin.testbench.elements.ButtonElement;
  22. import com.vaadin.testbench.elements.GridElement;
  23. public class GridContextClickTest extends AbstractContextClickTest {
  24. @Test
  25. public void testBodyContextClickWithTypedListener() {
  26. addOrRemoveTypedListener();
  27. contextClick($(GridElement.class).first().getCell(0, 0));
  28. assertEquals(
  29. "1. ContextClickEvent value: Lisa Schneider, column: Address, section: BODY",
  30. getLogRow(0));
  31. contextClick($(GridElement.class).first().getCell(0, 3));
  32. assertEquals(
  33. "2. ContextClickEvent value: Lisa Schneider, column: Last Name, section: BODY",
  34. getLogRow(0));
  35. }
  36. @Test
  37. public void testHeaderContextClickWithTypedListener() {
  38. addOrRemoveTypedListener();
  39. contextClick($(GridElement.class).first().getHeaderCell(0, 0));
  40. assertEquals(
  41. "1. ContextClickEvent value: Address, column: Address, section: HEADER",
  42. getLogRow(0));
  43. contextClick($(GridElement.class).first().getHeaderCell(0, 3));
  44. assertEquals(
  45. "2. ContextClickEvent value: Last Name, column: Last Name, section: HEADER",
  46. getLogRow(0));
  47. }
  48. @Test
  49. @Ignore("Footer is not currently implemented in grid")
  50. public void testFooterContextClickWithTypedListener() {
  51. addOrRemoveTypedListener();
  52. contextClick($(GridElement.class).first().getFooterCell(0, 0));
  53. assertEquals(
  54. "1. ContextClickEvent value: , column: Address, section: FOOTER",
  55. getLogRow(0));
  56. contextClick($(GridElement.class).first().getFooterCell(0, 3));
  57. assertEquals(
  58. "2. ContextClickEvent value: , column: Last Name, section: FOOTER",
  59. getLogRow(0));
  60. }
  61. @Test
  62. public void testContextClickInEmptyGrid() {
  63. addOrRemoveTypedListener();
  64. $(ButtonElement.class).caption("Remove all content").first().click();
  65. contextClick($(GridElement.class).first(), 100, 100);
  66. assertEquals("1. ContextClickEvent value: , section: BODY",
  67. getLogRow(0));
  68. }
  69. /**
  70. * Performs a context click on given element at coordinates 20, 10 followed
  71. * by a regular click. This prevents browser context menu from blocking
  72. * future operations.
  73. *
  74. * A smaller X offset might hit the resize handle of the previous cell that
  75. * overlaps with the next header cell.
  76. *
  77. * @param e
  78. * web element
  79. */
  80. @Override
  81. protected void contextClick(WebElement e) {
  82. contextClick(e, 20, 10);
  83. }
  84. }