use of com.vaadin.flow.component.CompositeNestedTest.TestLayout in project flow by vaadin.
the class CompositeTest method setup.
@Before
public void setup() {
compositeWithComponent = new CompositeWithComponent() {
@Override
public String toString() {
return "Composite";
}
};
layoutWithSingleComponentComposite = new TestLayout() {
@Override
public String toString() {
return "Layout";
}
};
layoutWithSingleComponentComposite.addComponent(compositeWithComponent);
((TracksAttachDetach) componentInsideLayoutInsideComposite).track();
compositeWithComponent.track();
layoutInsideComposite.track();
layoutWithSingleComponentComposite.track();
Assert.assertNull(VaadinService.getCurrent());
VaadinService service = Mockito.mock(VaadinService.class);
DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
Mockito.when(configuration.isProductionMode()).thenReturn(true);
Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
VaadinService.setCurrent(service);
}
use of com.vaadin.flow.component.CompositeNestedTest.TestLayout in project flow by vaadin.
the class CompositeTest method testOnAttachOnDetachAndEventsOrder.
@Test
public void testOnAttachOnDetachAndEventsOrder() {
List<Integer> triggered = new ArrayList<>();
Component component = new Component(new Element("div")) {
@Override
protected void onAttach(AttachEvent attachEvent) {
triggered.add(1);
}
@Override
protected void onDetach(DetachEvent detachEvent) {
triggered.add(-1);
}
};
component.addAttachListener(event -> triggered.add(2));
component.addDetachListener(event -> triggered.add(-2));
Composite<Component> compositeInsideComposite = new Composite<Component>() {
@Override
protected Component initContent() {
return component;
}
@Override
protected void onAttach(AttachEvent attachEvent) {
triggered.add(3);
}
@Override
protected void onDetach(DetachEvent detachEvent) {
triggered.add(-3);
}
};
compositeInsideComposite.addAttachListener(event -> triggered.add(4));
compositeInsideComposite.addDetachListener(event -> triggered.add(-4));
Composite<Component> composite = new Composite<Component>() {
@Override
protected Component initContent() {
return compositeInsideComposite;
}
@Override
protected void onAttach(AttachEvent attachEvent) {
triggered.add(5);
}
@Override
protected void onDetach(DetachEvent detachEvent) {
triggered.add(-5);
}
};
composite.addAttachListener(event -> triggered.add(6));
composite.addDetachListener(event -> triggered.add(-6));
UI ui = new UI();
ui.add(composite);
TestUtil.assertArrays(triggered.toArray(), new Integer[] { 1, 2, 3, 4, 5, 6 });
triggered.clear();
ui.remove(composite);
TestUtil.assertArrays(triggered.toArray(), new Integer[] { -1, -2, -3, -4, -5, -6 });
TestLayout container = createTestLayout();
ui.add(container, composite);
triggered.clear();
container.addComponent(composite);
TestUtil.assertArrays(triggered.toArray(), new Integer[] { -1, -2, -3, -4, -5, -6, 1, 2, 3, 4, 5, 6 });
}
Aggregations