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.

GridSwitchRenderersTest.java 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.grid;
  17. import org.junit.Assert;
  18. import org.junit.Test;
  19. import com.vaadin.testbench.elements.CheckBoxElement;
  20. import com.vaadin.testbench.elements.GridElement;
  21. import com.vaadin.testbench.parallel.TestCategory;
  22. import com.vaadin.tests.tb3.MultiBrowserTest;
  23. @TestCategory("grid")
  24. public class GridSwitchRenderersTest extends MultiBrowserTest {
  25. @Test
  26. public void testRendererSwitch() {
  27. // The UI should start with TEXT rendering in the second column
  28. // Clicking the checkbox will toggle rendering to HTML mode
  29. // Clicking it again should return TEXT rendering mode.
  30. openTestURL();
  31. GridElement grid = $(LegacyGridElement.class).first();
  32. Assert.assertTrue(
  33. "Initial rendering of column 1 is not unformatted text",
  34. cellTextIsUnformatted(grid.getCell(0, 1).getText()));
  35. // NOTE: must click at 5,5 because of Valo and rendering in Chrome
  36. // This is a TestBench bug that may be fixed sometime in the future
  37. CheckBoxElement cb = $(CheckBoxElement.class).first();
  38. cb.click(5, 5);
  39. Assert.assertTrue(
  40. "Column 1 data has not been rendered with HTMLRenderer after renderer swap",
  41. cellTextIsHTMLFormatted(grid.getCell(0, 1).getText()));
  42. cb.click(5, 5);
  43. Assert.assertTrue(
  44. "Column 1 data has not been re-rendered as text after renderer swap",
  45. cellTextIsUnformatted(grid.getCell(0, 1).getText()));
  46. }
  47. /**
  48. * Attempts to match a string to a string like {@code <b>(4, 1)</b>}.
  49. *
  50. * @param cellText
  51. * input string
  52. * @return true if input string is formatted like a raw HTML string
  53. */
  54. private boolean cellTextIsUnformatted(String cellText) {
  55. String regex = "<b>\\(\\d+, \\d+\\)</b>";
  56. return cellText.matches(regex);
  57. }
  58. /**
  59. * Attempts to match a string to a string like {@code (4, 1)}, i.e. the HTML
  60. * formatted version of the above (the bold tags should be consumed by the
  61. * renderer).
  62. *
  63. * @param cellText
  64. * input string
  65. * @return true if input string is formatted like plain text (i.e. HTML bits
  66. * have been consumed by renderer)
  67. */
  68. private boolean cellTextIsHTMLFormatted(String cellText) {
  69. String regex = "\\(\\d+, \\d+\\)";
  70. return cellText.matches(regex);
  71. }
  72. }