Search in sources :

Example 1 with JreJsonFactory

use of elemental.json.impl.JreJsonFactory in project flow-components by vaadin.

the class CrudTest method itemAvailableInAllEvents.

@Test
public void itemAvailableInAllEvents() {
    // Assert that all these events come with an item.
    systemUnderTest.addCancelListener(e -> Assert.assertNotNull(e.getItem()));
    systemUnderTest.addDeleteListener(e -> Assert.assertNotNull(e.getItem()));
    systemUnderTest.addEditListener(e -> Assert.assertNotNull(e.getItem()));
    systemUnderTest.addSaveListener(e -> Assert.assertNotNull(e.getItem()));
    systemUnderTest.addNewListener(e -> Assert.assertNotNull(e.getItem()));
    // A client-side Grid item.
    final JsonObject selectedItem = new JreJsonFactory().parse("{\"key\": \"1\"}");
    // Simulate a sequence of interactions.
    Arrays.asList(new Crud.NewEvent<>(systemUnderTest, false, null), new Crud.CancelEvent<>(systemUnderTest, false, null), new Crud.EditEvent<>(systemUnderTest, false, selectedItem, null), new Crud.DeleteEvent<>(systemUnderTest, false, null), new Crud.EditEvent<>(systemUnderTest, false, selectedItem, null), new Crud.SaveEvent<>(systemUnderTest, false, null)).forEach(e -> ComponentUtil.fireEvent(systemUnderTest, e));
}
Also used : JreJsonFactory(elemental.json.impl.JreJsonFactory) JsonObject(elemental.json.JsonObject) Test(org.junit.Test)

Example 2 with JreJsonFactory

use of elemental.json.impl.JreJsonFactory 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)

Example 3 with JreJsonFactory

use of elemental.json.impl.JreJsonFactory in project flow-components by vaadin.

the class ChartsSerializableTest method verifyJsonFactoryDeserialization.

@Test
public void verifyJsonFactoryDeserialization() throws Throwable {
    final Chart chart = new Chart();
    final JreJsonFactory jsonFactory = chart.getJsonFactory();
    final Chart deserializedChart = super.serializeAndDeserialize(chart);
    Assert.assertNotNull(deserializedChart);
    Assert.assertNotNull(deserializedChart.getJsonFactory());
    Assert.assertNotEquals(chart, deserializedChart);
    Assert.assertNotEquals(jsonFactory, deserializedChart.getJsonFactory());
}
Also used : JreJsonFactory(elemental.json.impl.JreJsonFactory) ClassesSerializableTest(com.vaadin.flow.testutil.ClassesSerializableTest) Test(org.junit.Test)

Aggregations

JreJsonFactory (elemental.json.impl.JreJsonFactory)3 Test (org.junit.Test)2 LitRenderer (com.vaadin.flow.data.renderer.LitRenderer)1 Element (com.vaadin.flow.dom.Element)1 ClassesSerializableTest (com.vaadin.flow.testutil.ClassesSerializableTest)1 JsonObject (elemental.json.JsonObject)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