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.

OptionGroupDeclarativeTests.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright 2000-2014 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.server.component.abstractselect;
  17. import org.junit.Before;
  18. import org.junit.Test;
  19. import com.vaadin.server.ThemeResource;
  20. import com.vaadin.tests.design.DeclarativeTestBase;
  21. import com.vaadin.ui.OptionGroup;
  22. public class OptionGroupDeclarativeTests extends
  23. DeclarativeTestBase<OptionGroup> {
  24. private OptionGroup og;
  25. @Before
  26. public void init() {
  27. og = new OptionGroup();
  28. }
  29. @Test
  30. public void testBasicSyntax() {
  31. String expected = "<vaadin-option-group />";
  32. testReadWrite(expected);
  33. }
  34. @Test
  35. public void testOptionSyntax() {
  36. og.addItems("foo", "bar", "baz", "bang");
  37. //@formatter:off
  38. String expected =
  39. "<vaadin-option-group>"
  40. + "<option>foo</option>"
  41. + "<option>bar</option>"
  42. + "<option>baz</option>"
  43. + "<option>bang</option>"
  44. + "</vaadin-option-group>";
  45. //@formatter:on
  46. testReadWrite(expected);
  47. }
  48. @Test
  49. public void testDisabledOptionSyntax() {
  50. og.addItems("foo", "bar", "baz", "bang");
  51. og.setItemEnabled("baz", false);
  52. //@formatter:off
  53. String expected =
  54. "<vaadin-option-group>"
  55. + "<option>foo</option>"
  56. + "<option>bar</option>"
  57. + "<option disabled>baz</option>"
  58. + "<option>bang</option>"
  59. + "</vaadin-option-group>";
  60. //@formatter:on
  61. testReadWrite(expected);
  62. }
  63. @Test
  64. public void testIconSyntax() {
  65. og.addItems("foo", "bar", "baz", "bang");
  66. og.setItemIcon("bar", new ThemeResource("foobar.png"));
  67. //@formatter:off
  68. String expected =
  69. "<vaadin-option-group>"
  70. + "<option>foo</option>"
  71. + "<option icon='theme://foobar.png'>bar</option>"
  72. + "<option>baz</option>"
  73. + "<option>bang</option>"
  74. + "</vaadin-option-group>";
  75. //@formatter:on
  76. testReadWrite(expected);
  77. }
  78. @Test
  79. public void testHTMLCaption() {
  80. og.addItems("foo", "bar", "baz", "bang");
  81. og.setHtmlContentAllowed(true);
  82. og.setItemCaption("foo", "<b>True</b>");
  83. og.setItemCaption("bar", "<font color='red'>False</font>");
  84. //@formatter:off
  85. String expected =
  86. "<vaadin-option-group html-content-allowed>"
  87. + "<option item-id=\"foo\"><b>True</b></option>"
  88. + "<option item-id=\"bar\"><font color='red'>False</font></option>"
  89. + "<option>baz</option>"
  90. + "<option>bang</option>"
  91. + "</vaadin-option-group>";
  92. //@formatter:on
  93. testReadWrite(expected);
  94. }
  95. @Test
  96. public void testPlaintextCaption() {
  97. og.addItems("foo", "bar", "baz", "bang");
  98. og.setItemCaption("foo", "<b>True</b>");
  99. og.setItemCaption("bar", "<font color=\"red\">False</font>");
  100. //@formatter:off
  101. String expected =
  102. "<vaadin-option-group>"
  103. + "<option item-id=\"foo\">&lt;b&gt;True&lt;/b&gt;</option>"
  104. + "<option item-id=\"bar\">&lt;font color=\"red\"&gt;False&lt;/font&gt;</option>"
  105. + "<option>baz</option>"
  106. + "<option>bang</option>"
  107. + "</vaadin-option-group>";
  108. //@formatter:on
  109. testReadWrite(expected);
  110. }
  111. private void testReadWrite(String design) {
  112. testWrite(design, og, true);
  113. testRead(design, og);
  114. }
  115. @Override
  116. public OptionGroup testRead(String design, OptionGroup expected) {
  117. OptionGroup read = super.testRead(design, expected);
  118. testWrite(design, read, true);
  119. return read;
  120. }
  121. }