Search in sources :

Example 1 with JreJsonObject

use of elemental.json.impl.JreJsonObject in project linkki by linkki-framework.

the class BindComboBoxItemStyleAspectDefinitionTest method testCreateComponentValueSetter.

@Test
void testCreateComponentValueSetter() {
    MockVaadin.setup();
    String styleName = "bar";
    BindComboBoxItemStyleAspectDefinition aspectDefinition = new BindComboBoxItemStyleAspectDefinition(styleName);
    ComboBox<Object> comboBox = spy(ComponentFactory.newComboBox());
    @SuppressWarnings("unchecked") ArgumentCaptor<LitRenderer<Object>> argumentCaptor = ArgumentCaptor.forClass(LitRenderer.class);
    ComponentWrapper componentWrapper = new NoLabelComponentWrapper(comboBox);
    Consumer<Function<Object, String>> componentValueSetter = aspectDefinition.createComponentValueSetter(componentWrapper);
    componentValueSetter.accept(o -> EXPECTED_STYLE);
    verify(comboBox).setRenderer(argumentCaptor.capture());
    LitRenderer<Object> renderer = argumentCaptor.getValue();
    Rendering<Object> render = renderer.render(new Element("div"), new KeyMapper<>());
    JreJsonObject jsonObject = new JreJsonObject(new JreJsonFactory());
    render.getDataGenerator().get().generateData(EXPECTED_LABEL, jsonObject);
    assertThat(jsonObject.get("lr_0_" + BindComboBoxItemStyleAspectDefinition.LABEL).asString(), is(EXPECTED_LABEL));
    assertThat(jsonObject.get("lr_0_" + BindComboBoxItemStyleAspectDefinition.STYLE).asString(), is(EXPECTED_STYLE));
    MockVaadin.tearDown();
}
Also used : JreJsonObject(elemental.json.impl.JreJsonObject) Element(com.vaadin.flow.dom.Element) ComponentWrapper(org.linkki.core.binding.wrapper.ComponentWrapper) NoLabelComponentWrapper(org.linkki.core.ui.wrapper.NoLabelComponentWrapper) Function(java.util.function.Function) JreJsonFactory(elemental.json.impl.JreJsonFactory) NoLabelComponentWrapper(org.linkki.core.ui.wrapper.NoLabelComponentWrapper) LitRenderer(com.vaadin.flow.data.renderer.LitRenderer) JreJsonObject(elemental.json.impl.JreJsonObject) Test(org.junit.jupiter.api.Test)

Aggregations

LitRenderer (com.vaadin.flow.data.renderer.LitRenderer)1 Element (com.vaadin.flow.dom.Element)1 JreJsonFactory (elemental.json.impl.JreJsonFactory)1 JreJsonObject (elemental.json.impl.JreJsonObject)1 Function (java.util.function.Function)1 Test (org.junit.jupiter.api.Test)1 ComponentWrapper (org.linkki.core.binding.wrapper.ComponentWrapper)1 NoLabelComponentWrapper (org.linkki.core.ui.wrapper.NoLabelComponentWrapper)1