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 com.vaadin.tests.components.grid.LegacyGridElement;
  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($(LegacyGridElement.class).first().getCell(0, 0));
  28. assertEquals(
  29. "1. ContextClickEvent value: Lisa Schneider, propertyId: address, section: BODY",
  30. getLogRow(0));
  31. contextClick($(LegacyGridElement.class).first().getCell(0, 3));
  32. assertEquals(
  33. "2. ContextClickEvent value: Lisa Schneider, propertyId: lastName, section: BODY",
  34. getLogRow(0));
  35. }
  36. @Test
  37. public void testHeaderContextClickWithTypedListener() {
  38. addOrRemoveTypedListener();
  39. contextClick($(LegacyGridElement.class).first().getHeaderCell(0, 0));
  40. assertEquals(
  41. "1. ContextClickEvent value: Address, propertyId: address, section: HEADER",
  42. getLogRow(0));
  43. contextClick($(LegacyGridElement.class).first().getHeaderCell(0, 3));
  44. assertEquals(
  45. "2. ContextClickEvent value: Last Name, propertyId: lastName, section: HEADER",
  46. getLogRow(0));
  47. }
  48. @Test
  49. public void testFooterContextClickWithTypedListener() {
  50. addOrRemoveTypedListener();
  51. contextClick($(LegacyGridElement.class).first().getFooterCell(0, 0));
  52. assertEquals(
  53. "1. ContextClickEvent value: , propertyId: address, section: FOOTER",
  54. getLogRow(0));
  55. contextClick($(LegacyGridElement.class).first().getFooterCell(0, 3));
  56. assertEquals(
  57. "2. ContextClickEvent value: , propertyId: lastName, section: FOOTER",
  58. getLogRow(0));
  59. }
  60. @Test
  61. public void testContextClickInEmptyGrid() {
  62. addOrRemoveTypedListener();
  63. $(ButtonElement.class).caption("Remove all content").first().click();
  64. contextClick($(LegacyGridElement.class).first(), 100, 100);
  65. assertEquals(
  66. "1. ContextClickEvent value: , propertyId: null, 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. }