Component implements HasElement, AttachNotifier, DetachNotifier { @Override public Element getElement() { assert element != null : "getElement() must not be called before the element has been set"; return element; } protected  Component(); protected  Component(Element element); @Override Element getElement(); Optional<Component> getParent(); Stream<Component> getChildren(); Optional<UI> getUI(); void setId(String id); Optional<String> getId(); boolean isAttached(); static T from(Element element,
            Class<T> componentType); void setVisible(boolean visible); boolean isVisible(); void onEnabledStateChanged(boolean enabled); String getTranslation(String key, Object... params); String getTranslation(String key, Locale locale, Object... params);  }
@Test public void getElement() { Assert.assertEquals(Tag.DIV, divWithTextComponent.getElement().getTag()); Assert.assertEquals("Test component", divWithTextComponent.getElement().getTextRecursively()); }
@Test public void defaultGetChildrenMultiple() { Element level1 = ElementFactory.createDiv("Level1"); parentDivComponent.getElement().appendChild(level1); level1.appendChild(child1SpanComponent.getElement()); level1.appendChild(child2InputComponent.getElement()); assertChildren(parentDivComponent, child1SpanComponent, child2InputComponent); }
@Test public void createComponentWithTag() { Component component = new TestComponentWithTag(); Assert.assertEquals(Tag.DIV, component.getElement().getTag()); }
@Test public void createComponentWithInheritedTag() { Component component = new TestComponentWithInheritedTag(); Assert.assertEquals(Tag.DIV, component.getElement().getTag()); }
@Test public void synchronizePropertyBasedOnGetterName() { SynchronizePropertyOnChangeComponent component = new SynchronizePropertyOnChangeComponent(); Element element = component.getElement(); assertSynchronizedProperties("change", element, "}foo"); }
@Test public void synchronizePropertyElementConstructor() { SynchronizePropertyUsingElementConstructor component = new SynchronizePropertyUsingElementConstructor(); component.customInit(); Element element = component.getElement(); assertSynchronizedProperties("change", element, "}foo"); }
@Test public void synchronizePropertyWithPropertyName() { SynchronizePropertyOnChangeGivenPropertyComponent component = new SynchronizePropertyOnChangeGivenPropertyComponent(); Element element = component.getElement(); assertSynchronizedProperties("change", element, "}bar"); }
@Test public void synchronizePropertyWithMultipleEvents() { SynchronizePropertyOnMultipleEventsComponent component = new SynchronizePropertyOnMultipleEventsComponent(); Element element = component.getElement(); assertSynchronizedProperties("input", element, "}foo"); assertSynchronizedProperties("blur", element, "}foo"); }
@Test public void declarativeSyncProperties_propertiesAreRegisteredWithProperDisabledUpdateMode() { TestDiv div = new TestDiv(); ElementListenerMap feature = div.getElement().getNode() .getFeature(ElementListenerMap.class); Set<String> props = feature.getExpressions("bar"); Assert.assertEquals(1, props.size()); Assert.assertTrue(props.contains("}baz")); Assert.assertEquals(DisabledUpdateMode.ALWAYS, feature.getPropertySynchronizationMode("baz")); props = feature.getExpressions("foo"); Assert.assertEquals(1, props.size()); Assert.assertTrue(props.contains("}bar")); Assert.assertEquals(DisabledUpdateMode.ONLY_WHEN_ENABLED, feature.getPropertySynchronizationMode("bar")); }
@Test public void enabledStateChangeOnAttachCalledForParentOfVirtualChildState() { enabledStateChangeOnAttachCalledForParentState(false, (parent, child) -> { Element wrapper = ElementFactory.createAnchor(); parent.getElement().appendVirtualChild(wrapper); wrapper.appendChild(child.getElement()); }); }
@Test public void enabledStateChangeOnDisableParentOfVirtualChild() { enabledStateChangeOnAttachCalledForParentState(true, (parent, child) -> { Element wrapper = ElementFactory.createAnchor(); parent.getElement().appendVirtualChild(wrapper); wrapper.appendChild(child.getElement()); parent.setEnabled(false); }); }
@Test public void enabledStateChangeOnParentOfVirtualChildDetachReturnsOldState() { enabledStateChangeOnParentDetachReturnsOldState((parent, child) -> { Element wrapper = ElementFactory.createAnchor(); parent.getElement().appendVirtualChild(wrapper); wrapper.appendChild(child.getElement()); }); }
@Test public void enabledPassesThroughAllChildensChildrenAndAttributeShouldBeSet() { UI ui = new UI(); EnabledDiv parent = new EnabledDiv(); EnabledDiv child = new EnabledDiv(); EnabledDiv subChild = new EnabledDiv(); EnabledDiv subSubChild = new EnabledDiv(); parent.add(child); child.add(subChild); subChild.add(subSubChild); ui.add(parent); Assert.assertTrue("Parent should be enabled.", parent.isEnabled()); Assert.assertTrue("Child should be enabled.", child.isEnabled()); Assert.assertTrue("SubChild should be enabled.", subChild.isEnabled()); Assert.assertTrue("SubsubChild should be enabled.", subSubChild.isEnabled()); Assert.assertNull("No disabled attribute should not exist for parent", parent.getElement().getAttribute("disabled")); Assert.assertNull("No disabled attribute should not exist for child", child.getElement().getAttribute("disabled")); Assert.assertNull("No disabled attribute should not exist for subChild", subChild.getElement().getAttribute("disabled")); Assert.assertNull( "No disabled attribute should not exist for subSubChild", subSubChild.getElement().getAttribute("disabled")); parent.setEnabled(false); Assert.assertFalse("Parent should be disabled.", parent.isEnabled()); Assert.assertFalse("Child should be disabled.", child.isEnabled()); Assert.assertFalse("SubChild should be disabled.", subChild.isEnabled()); Assert.assertFalse("SubsubChild should be disabled.", subSubChild.isEnabled()); Assert.assertNotNull("Disabled attribute should exist for parent", parent.getElement().getAttribute("disabled")); Assert.assertNotNull("Disabled attribute should exist for child", child.getElement().getAttribute("disabled")); Assert.assertNotNull("Disabled attribute should exist for subChild", subChild.getElement().getAttribute("disabled")); Assert.assertNotNull("Disabled attribute should exist for subSubChild", subSubChild.getElement().getAttribute("disabled")); }