use of com.vaadin.flow.data.provider.KeyMapper in project flow-components by vaadin.
the class NativeButtonRendererTest method templateRenderered_containerIsDisabled_buttonIsDisabled.
@Test
public void templateRenderered_containerIsDisabled_buttonIsDisabled() {
NativeButtonRenderer<String> renderer = new NativeButtonRenderer<>("Label");
Element container = new Element("div");
KeyMapper<String> keyMapper = new KeyMapper<>();
Rendering<String> rendering = renderer.render(container, keyMapper);
mockAttach(renderer, container, rendering, keyMapper);
Assert.assertTrue("The DataGenerator should be present", rendering.getDataGenerator().isPresent());
DataGenerator<String> dataGenerator = rendering.getDataGenerator().get();
JsonObject json = Json.createObject();
dataGenerator.generateData("something", json);
Assert.assertFalse("The button shouldn't be disabled", json.getBoolean(renderer.getTemplatePropertyName(rendering) + "_disabled"));
mockDisabled(container);
json = Json.createObject();
dataGenerator.generateData("something", json);
Assert.assertTrue("The button should be disabled", json.getBoolean(renderer.getTemplatePropertyName(rendering) + "_disabled"));
}
use of com.vaadin.flow.data.provider.KeyMapper in project flow-components by vaadin.
the class ComponentRendererTest method templateRenderered_parentAttachedBeforeChild.
@Test
public void templateRenderered_parentAttachedBeforeChild() {
UI ui = new TestUI();
TestUIInternals internals = (TestUIInternals) ui.getInternals();
ComponentRenderer<TestDiv, String> renderer = new ComponentRenderer<>(e -> (new TestDiv()));
Element containerParent = new Element("div");
Element container = new Element("div");
KeyMapper<String> keyMapper = new KeyMapper<>();
ComponentDataGenerator<String> rendering = (ComponentDataGenerator<String>) renderer.render(container, keyMapper);
// simulate a call from the grid to refresh data - template is not setup
containerParent.getNode().runWhenAttached(ui2 -> ui2.getInternals().getStateTree().beforeClientResponse(containerParent.getNode(), context -> {
Assert.assertNotNull("NodeIdPropertyName should not be null", rendering.getNodeIdPropertyName());
JsonObject value = Json.createObject();
rendering.generateData("item", value);
Assert.assertEquals("generateData should add one element in the jsonobject", 1, value.keys().length);
}));
// attach the parent (ex: grid) before the child (ex: column)
attachElement(ui, containerParent);
attachElement(ui, container);
internals.getStateTree().runExecutionsBeforeClientResponse();
}
use of com.vaadin.flow.data.provider.KeyMapper in project flow-components by vaadin.
the class ComponentRendererTest method templateRenderered_childAttachedBeforeParent.
@Test
public void templateRenderered_childAttachedBeforeParent() {
UI ui = new TestUI();
TestUIInternals internals = (TestUIInternals) ui.getInternals();
ComponentRenderer<TestDiv, String> renderer = new ComponentRenderer<>(e -> (new TestDiv()));
Element containerParent = new Element("div");
Element container = new Element("div");
KeyMapper<String> keyMapper = new KeyMapper<>();
ComponentDataGenerator<String> rendering = (ComponentDataGenerator<String>) renderer.render(container, keyMapper);
containerParent.getNode().runWhenAttached(ui2 -> ui2.getInternals().getStateTree().beforeClientResponse(containerParent.getNode(), context -> {
// if nodeid is null then the component
// won't be rendered correctly
Assert.assertNotNull("NodeIdPropertyName should not be null", rendering.getNodeIdPropertyName());
JsonObject value = Json.createObject();
rendering.generateData("item", value);
Assert.assertEquals("generateData should add one element in the jsonobject", 1, value.keys().length);
}));
// attach the child (ex: container) before the parent (ex: grid)
attachElement(ui, container);
attachElement(ui, containerParent);
internals.getStateTree().runExecutionsBeforeClientResponse();
}
Aggregations