diff options
author | Artur <artur@vaadin.com> | 2017-02-22 13:36:45 +0200 |
---|---|---|
committer | Aleksi Hietanen <aleksi@vaadin.com> | 2017-02-22 13:36:45 +0200 |
commit | f3d768252903b8c184cc7d8a77b70ccddc5ef20f (patch) | |
tree | d6c04079289e66e548f780d9eae6cef52f2edbc7 /uitest | |
parent | 1718666cd6a0aac7273e12d5bad459dea9fe997c (diff) | |
download | vaadin-framework-f3d768252903b8c184cc7d8a77b70ccddc5ef20f.tar.gz vaadin-framework-f3d768252903b8c184cc7d8a77b70ccddc5ef20f.zip |
Add support for rendering HTML in ButtonRenderer (#8606)
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/grid/GridClickableRenderers.java | 17 | ||||
-rw-r--r-- | uitest/src/test/java/com/vaadin/tests/components/grid/GridClickableRenderersTest.java | 28 |
2 files changed, 34 insertions, 11 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridClickableRenderers.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridClickableRenderers.java index 75ce1738dd..e2fb91b230 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridClickableRenderers.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridClickableRenderers.java @@ -14,13 +14,15 @@ public class GridClickableRenderers extends AbstractReindeerTestUI { String testText; String imageUrl; String buttonText; + String buttonHtml; boolean truthValue; TestPOJO(String intValue, String imageUrl, String buttonText, - boolean truthValue) { + String buttonHtml, boolean truthValue) { testText = intValue; this.imageUrl = imageUrl; this.buttonText = buttonText; + this.buttonHtml = buttonHtml; this.truthValue = truthValue; } } @@ -37,6 +39,12 @@ public class GridClickableRenderers extends AbstractReindeerTestUI { new ButtonRenderer<>(event -> valueDisplayLabel .setValue(event.getItem().testText + " clicked"))) .setId("buttons").setCaption("Buttons"); + ButtonRenderer<TestPOJO> htmlButtonRenderer = new ButtonRenderer<>(); + htmlButtonRenderer.setHtmlContentAllowed(true); + htmlButtonRenderer.addClickListener(event -> valueDisplayLabel + .setValue(event.getItem().buttonHtml + " clicked")); + grid.addColumn(pojo -> pojo.buttonHtml, htmlButtonRenderer) + .setId("buttonsHtml").setCaption("Buttons HTML"); ButtonRenderer<TestPOJO> yesNoRenderer = new ButtonRenderer<>(); yesNoRenderer.addClickListener(event -> { @@ -48,8 +56,11 @@ public class GridClickableRenderers extends AbstractReindeerTestUI { grid.addColumn(pojo -> pojo.truthValue ? "Yes" : "No", yesNoRenderer) .setCaption("Truth").setId("truth"); - grid.setItems(new TestPOJO("first row", "", "button 1 text", true), - new TestPOJO("second row", "", "button 2 text", false)); + grid.setItems( + new TestPOJO("first row", "", "button 1 text", + "button 1 <b style='color: red'>html</b>", true), + new TestPOJO("second row", "", "button 2 text", + "button 2 <b style='color: red'>html</b>", false)); addComponents(valueDisplayLabel, checkBoxValueLabel, grid); } } diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridClickableRenderersTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridClickableRenderersTest.java index 12fcaabfae..541851b8a1 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridClickableRenderersTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridClickableRenderersTest.java @@ -15,6 +15,8 @@ */ package com.vaadin.tests.components.grid; +import java.util.List; + import org.junit.Assert; import org.junit.Test; import org.openqa.selenium.By; @@ -35,16 +37,26 @@ public class GridClickableRenderersTest extends MultiBrowserTest { @Test public void buttonRendererReturnsCorrectItem() { openTestURL(); - WebElement firstRowButton = findElements(By.className("v-nativebutton")) - .get(0); - WebElement secondRowButton = findElements( - By.className("v-nativebutton")).get(2); + List<WebElement> findElements = findElements( + By.className("v-nativebutton")); + WebElement firstRowTextButton = findElements.get(0); + WebElement firstRowHtmlButton = findElements.get(1); + Assert.assertEquals("button 1 text", firstRowTextButton.getText()); + // If it was rendered as text, getText() would return the markup also + Assert.assertEquals("button 1 html", firstRowHtmlButton.getText()); + + WebElement secondRowTextButton = findElements.get(3); + WebElement secondRowHtmlButton = findElements.get(4); + Assert.assertEquals("button 2 text", secondRowTextButton.getText()); + // If it was rendered as text, getText() would return the markup also + Assert.assertEquals("button 2 html", secondRowHtmlButton.getText()); + LabelElement label = $(LabelElement.class).get(1); - firstRowButton.click(); + firstRowTextButton.click(); Assert.assertEquals("first row clicked", label.getText()); - secondRowButton.click(); + secondRowTextButton.click(); Assert.assertEquals("second row clicked", label.getText()); } @@ -52,9 +64,9 @@ public class GridClickableRenderersTest extends MultiBrowserTest { public void checkBoxRendererClick() { openTestURL(); WebElement firstRowButton = findElements(By.className("v-nativebutton")) - .get(1); + .get(2); WebElement secondRowButton = findElements( - By.className("v-nativebutton")).get(3); + By.className("v-nativebutton")).get(5); LabelElement label = $(LabelElement.class).get(2); firstRowButton.click(); |