Search in sources :

Example 1 with DefaultComponentExtension

use of com.aire.ux.DefaultComponentExtension in project aire-components by aire-ux.

the class ApplicationLayoutTest method ensureRegisteringSimpleComponentWorks.

@ViewTest
@DirtiesContext
void ensureRegisteringSimpleComponentWorks(@Autowired UserInterface ui, @Context TestContext $) {
    val extension = new DefaultComponentExtension<>(":management-menu", (NavigationBar parent) -> {
        val button = spy(new Button("Hello"));
        parent.add(button);
    });
    var button = $.selectFirst("vaadin-button[text~=Hello]", Button.class);
    assertFalse(button.isPresent());
    val registration = ui.register(Selection.path(":main:navigation"), extension);
    $.flush();
    val menu = ui.selectFirst(Selection.path(":main:navigation:management-menu"));
    assertNotNull(menu);
    button = $.selectFirst("vaadin-button[text~=Hello]", Button.class);
    assertTrue(button.isPresent());
    registration.close();
    $.flush(true);
    assertEquals(0, ui.getExtensionRegistry().getExtensionCount());
    button = $.selectFirst("vaadin-button[text~=Hello]", Button.class);
    assertFalse(button.isPresent());
}
Also used : lombok.val(lombok.val) NavigationBar(io.sunshower.zephyr.ui.navigation.NavigationBar) Button(com.vaadin.flow.component.button.Button) DefaultComponentExtension(com.aire.ux.DefaultComponentExtension) DirtiesContext(org.springframework.test.annotation.DirtiesContext) ViewTest(com.aire.ux.test.ViewTest)

Example 2 with DefaultComponentExtension

use of com.aire.ux.DefaultComponentExtension in project aire-components by aire-ux.

the class PathRegistryParameterResolver method create.

@Override
public ElementResolver create(AnnotatedElement element) {
    return new ElementResolver() {

        @Override
        @SuppressWarnings("unchecked")
        public <T> T resolve() {
            val selector = element.getAnnotation(Select.class);
            val value = Utilities.firstNonDefault(selector.value(), selector.selector());
            return (T) Selection.path(value).select(Aire.getUserInterface(), UI::getCurrent, new DefaultComponentExtension<>(value, c -> {
            })).map(ExtensionDefinition::getValue).get();
        }
    };
}
Also used : lombok.val(lombok.val) ExtensionDefinition(com.aire.ux.ExtensionDefinition) ElementResolver(com.aire.ux.test.ElementResolver) DefaultComponentExtension(com.aire.ux.DefaultComponentExtension)

Aggregations

DefaultComponentExtension (com.aire.ux.DefaultComponentExtension)2 lombok.val (lombok.val)2 ExtensionDefinition (com.aire.ux.ExtensionDefinition)1 ElementResolver (com.aire.ux.test.ElementResolver)1 ViewTest (com.aire.ux.test.ViewTest)1 Button (com.vaadin.flow.component.button.Button)1 NavigationBar (io.sunshower.zephyr.ui.navigation.NavigationBar)1 DirtiesContext (org.springframework.test.annotation.DirtiesContext)1