use of com.vaadin.flow.dom.Element in project flow by vaadin.
the class TemplateElementStateProviderTest method emptyChildSlotOrder.
@Test
public void emptyChildSlotOrder() {
Element parent = createElement("<div><before></before>@child@<after></after></div>");
Assert.assertEquals(2, parent.getChildCount());
Assert.assertEquals(Arrays.asList("before", "after"), parent.getChildren().map(Element::getTag).collect(Collectors.toList()));
}
use of com.vaadin.flow.dom.Element in project flow by vaadin.
the class TemplateElementStateProviderTest method templateStaticStyleAttribute.
@Test
public void templateStaticStyleAttribute() {
Element element = createElement("<div style='background:blue'></div>");
Assert.assertEquals("background:blue", element.getAttribute("style"));
Assert.assertEquals("blue", element.getStyle().get("background"));
Assert.assertArrayEquals(new Object[] { "style" }, element.getAttributeNames().toArray());
}
use of com.vaadin.flow.dom.Element in project flow by vaadin.
the class TemplateElementStateProviderTest method testElementJsonProperties.
@Test
public void testElementJsonProperties() {
ElementTemplateBuilder builder = new ElementTemplateBuilder("div").setProperty("a", new ModelValueBindingProvider("key"));
Element element = createElement(builder);
StateNode stateNode = element.getNode();
JsonObject json = Json.createObject();
json.put("foo", "bar");
ModelMap.get(stateNode).setValue("key", json);
Assert.assertEquals(json, element.getPropertyRaw("a"));
Assert.assertEquals(new HashSet<>(Arrays.asList("a")), element.getPropertyNames().collect(Collectors.toSet()));
}
use of com.vaadin.flow.dom.Element in project flow by vaadin.
the class TemplateElementStateProviderTest method populatedChildSlotOrder.
@Test
public void populatedChildSlotOrder() {
Element parent = createElement("<div><before></before>@child@<after></after></div>");
Element child = new Element("child");
parent.getNode().getFeature(TemplateMap.class).setChild(child.getNode());
Assert.assertEquals(3, parent.getChildCount());
Assert.assertEquals(Arrays.asList("before", "child", "after"), parent.getChildren().map(Element::getTag).collect(Collectors.toList()));
}
use of com.vaadin.flow.dom.Element in project flow by vaadin.
the class TemplateElementStateProviderTest method getBoundAttribute_setRegularAttribute_hasAttributeAndHasProperValue.
@Test
public void getBoundAttribute_setRegularAttribute_hasAttributeAndHasProperValue() {
TemplateNode node = TemplateParser.parse("<div [attr.attr]='foo'></div>", new NullTemplateResolver());
Element element = createElement(node);
element.setAttribute("foo", "bar");
element.getNode().getFeature(ModelMap.class).setValue("foo", "someValue");
Assert.assertTrue(element.hasAttribute("foo"));
Assert.assertTrue(element.hasAttribute("attr"));
Assert.assertEquals("bar", element.getAttribute("foo"));
Assert.assertEquals("someValue", element.getAttribute("attr"));
List<String> attrs = element.getAttributeNames().collect(Collectors.toList());
Assert.assertEquals(2, attrs.size());
Assert.assertTrue(attrs.contains("attr"));
Assert.assertTrue(attrs.contains("foo"));
}
Aggregations