diff options
author | Tatu Lund <tatu@vaadin.com> | 2019-04-02 13:46:29 +0300 |
---|---|---|
committer | Anastasia Smirnova <anasmi@utu.fi> | 2019-04-02 13:46:29 +0300 |
commit | 0035aa1d7a8645a3759d27864b95d83a4b8c2475 (patch) | |
tree | f750585ed58996461c8bcd7e95a0af1992aa1697 | |
parent | 2fa346be939b682e905528c67a531c6a8da9ebff (diff) | |
download | vaadin-framework-0035aa1d7a8645a3759d27864b95d83a4b8c2475.tar.gz vaadin-framework-0035aa1d7a8645a3759d27864b95d83a4b8c2475.zip |
setCaption of Panel did not honor setCaptionAsHtml (#11523)
Verify that correct mode(HTML/TEXT) of caption is set for the Panel
Fixes #11521
6 files changed, 58 insertions, 4 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VPanel.java b/client/src/main/java/com/vaadin/client/ui/VPanel.java index 6396b83336..d740c70fab 100644 --- a/client/src/main/java/com/vaadin/client/ui/VPanel.java +++ b/client/src/main/java/com/vaadin/client/ui/VPanel.java @@ -130,8 +130,12 @@ public class VPanel extends SimplePanel implements ShortcutActionHandlerOwner, } /** For internal use only. May be removed or replaced in the future. */ - public void setCaption(String text) { - DOM.setInnerHTML(captionText, text); + public void setCaption(String text, boolean captionAsHtml) { + if (captionAsHtml) { + captionText.setInnerHTML(text); + } else { + captionText.setInnerText(text); + } } /** For internal use only. May be removed or replaced in the future. */ diff --git a/client/src/main/java/com/vaadin/client/ui/panel/PanelConnector.java b/client/src/main/java/com/vaadin/client/ui/panel/PanelConnector.java index f454e511be..44d60121b1 100644 --- a/client/src/main/java/com/vaadin/client/ui/panel/PanelConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/panel/PanelConnector.java @@ -97,9 +97,9 @@ public class PanelConnector extends AbstractSingleComponentContainerConnector panel.captionNode.setClassName(VPanel.CLASSNAME + "-caption"); boolean hasCaption = hasCaption(); if (hasCaption) { - panel.setCaption(getState().caption); + panel.setCaption(getState().caption,getState().captionAsHtml); } else { - panel.setCaption(""); + panel.setCaption("",false); panel.captionNode.setClassName(VPanel.CLASSNAME + "-nocaption"); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/panel/PanelChangeContents.java b/uitest/src/main/java/com/vaadin/tests/components/panel/PanelChangeContents.java index ae3c617ae5..d00ae206fe 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/panel/PanelChangeContents.java +++ b/uitest/src/main/java/com/vaadin/tests/components/panel/PanelChangeContents.java @@ -35,6 +35,7 @@ public class PanelChangeContents extends AbstractReindeerTestUI buttons.addComponent(companiesButton); buttons.addComponent(settingsButton); panel = new Panel(); + panel.setCaption("<div class=\"caption-with-html\">Caption</div>"); panel.setSizeFull(); panel.setContent(stats); content.addComponent(buttons); diff --git a/uitest/src/main/java/com/vaadin/tests/components/panel/PanelHTMLCaption.java b/uitest/src/main/java/com/vaadin/tests/components/panel/PanelHTMLCaption.java new file mode 100644 index 0000000000..bdae0b58c4 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/panel/PanelHTMLCaption.java @@ -0,0 +1,31 @@ +package com.vaadin.tests.components.panel; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Panel; +import com.vaadin.ui.Button; +import com.vaadin.ui.VerticalLayout; + +public class PanelHTMLCaption extends AbstractTestUI { + public static final String caption = "<b> <div id='divId'>BOLD CAPTION</div></b>"; + + @Override + protected void setup(VaadinRequest request) { + Panel panel = new Panel(); + panel.setId("panelId"); + panel.setWidth("200px"); + panel.setHeight("200px"); + + panel.setCaption(caption); + panel.setCaptionAsHtml(false); + + panel.setContent(new VerticalLayout()); + + addComponent(panel); + Button changeCaptionFormat = new Button("Set Caption as HTML", e -> { + panel.setCaptionAsHtml(true); + }); + changeCaptionFormat.setId("buttonId"); + addComponent(changeCaptionFormat); + } +}
\ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/panel/PanelChangeContentsTest.java b/uitest/src/test/java/com/vaadin/tests/components/panel/PanelChangeContentsTest.java index 317dc1093b..49e2be2ccf 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/panel/PanelChangeContentsTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/panel/PanelChangeContentsTest.java @@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; +import com.vaadin.testbench.By; import com.vaadin.tests.tb3.MultiBrowserTest; public class PanelChangeContentsTest extends MultiBrowserTest { @@ -29,5 +30,6 @@ public class PanelChangeContentsTest extends MultiBrowserTest { "/VVerticalLayout[0]/Slot[1]/VPanel[0]/VVerticalLayout[0]/Slot[0]/VLabel[0]") .getText()); + assertElementNotPresent(By.className("caption-with-html")); } } diff --git a/uitest/src/test/java/com/vaadin/tests/components/panel/PanelHTMLCaptionTest.java b/uitest/src/test/java/com/vaadin/tests/components/panel/PanelHTMLCaptionTest.java new file mode 100644 index 0000000000..e360bfa00a --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/panel/PanelHTMLCaptionTest.java @@ -0,0 +1,16 @@ +package com.vaadin.tests.components.panel; + +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Test; +import org.openqa.selenium.By; + + +public class PanelHTMLCaptionTest extends MultiBrowserTest { + @Test + public void testCaptionDisplayedAsText() { + openTestURL(); + assertElementNotPresent(By.id("divId")); + findElement(By.id("buttonId")).click(); + assertElementPresent(By.id("divId")); + } +} |