use of io.jmix.ui.component.Component in project jmix by jmix-framework.
the class LookupFieldTest method testValueLoadFromOptions.
@Test
public void testValueLoadFromOptions() {
LookupField component = create(LookupField.class);
// noinspection unchecked
Datasource<User> testDs = new DsBuilder().setId("testDs").setJavaClass(User.class).setView(viewRepository.getFetchPlan(User.class, FetchPlan.LOCAL)).buildDatasource();
testDs.setItem(new User());
((DatasourceImpl) testDs).valid();
assertNull(component.getValue());
Group g = new Group();
testDs.getItem().setGroup(g);
// noinspection unchecked
CollectionDatasource<Group, UUID> groupsDs = new DsBuilder().setId("testDs").setJavaClass(Group.class).setView(viewRepository.getFetchPlan(Group.class, FetchPlan.LOCAL)).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setAllowCommit(false).buildCollectionDatasource();
groupsDs.includeItem(g);
Group g1 = new Group();
g1.setId(g.getId());
groupsDs.includeItem(g1);
Group g2 = new Group();
groupsDs.includeItem(g2);
component.setOptionsDatasource(groupsDs);
component.setDatasource(testDs, "group");
assertSame(g, component.getValue(), "Value should be from value ds");
component.setValue(g2);
Consumer<HasValue.ValueChangeEvent> listener1 = e -> {
assertEquals(g2, e.getPrevValue());
assertEquals(g1, e.getValue());
};
component.addValueChangeListener(listener1);
component.setValue(g);
}
use of io.jmix.ui.component.Component in project jmix by jmix-framework.
the class LookupFieldTest method testNew.
@Test
public void testNew() {
Component component = create(LookupField.NAME);
assertNotNull(component);
assertTrue(component instanceof LookupField);
}
use of io.jmix.ui.component.Component in project jmix by jmix-framework.
the class LookupPickerFieldTest method testNew.
@Test
public void testNew() {
Component component = create(LookupPickerField.NAME);
assertNotNull(component);
assertTrue(component instanceof LookupPickerField);
}
use of io.jmix.ui.component.Component in project jmix by jmix-framework.
the class LookupPickerFieldTest method testValueLoadFromOptions.
@Test
public void testValueLoadFromOptions() {
LookupPickerField component = create(LookupPickerField.class);
// noinspection unchecked
Datasource<User> testDs = new DsBuilder().setId("testDs").setJavaClass(User.class).setView(viewRepository.getFetchPlan(User.class, FetchPlan.LOCAL)).buildDatasource();
testDs.setItem(new User());
((DatasourceImpl) testDs).valid();
assertNull(component.getValue());
Group g = new Group();
testDs.getItem().setGroup(g);
// noinspection unchecked
CollectionDatasource<Group, UUID> groupsDs = new DsBuilder().setId("testDs").setJavaClass(Group.class).setView(viewRepository.getFetchPlan(Group.class, FetchPlan.LOCAL)).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setAllowCommit(false).buildCollectionDatasource();
groupsDs.includeItem(g);
Group g1 = new Group();
g1.setId(g.getId());
groupsDs.includeItem(g1);
Group g2 = new Group();
groupsDs.includeItem(g2);
component.setOptionsDatasource(groupsDs);
component.setDatasource(testDs, "group");
assertSame(g, component.getValue(), "Value should be from options ds");
component.setValue(g2);
Consumer<HasValue.ValueChangeEvent> listener1 = e -> {
assertEquals(g2, e.getPrevValue());
assertEquals(g1, e.getValue());
};
component.addValueChangeListener(listener1);
component.setValue(g);
}
use of io.jmix.ui.component.Component in project jmix by jmix-framework.
the class OptionsGroupTest method testValueChangeListener.
@Test
public void testValueChangeListener() {
OptionsGroup component = create(OptionsGroup.class);
final AtomicInteger counter = new AtomicInteger(0);
assertNull(component.getValue());
Consumer<HasValue.ValueChangeEvent> listener1 = e -> {
assertNull(e.getPrevValue());
assertEquals("Two", e.getValue());
counter.addAndGet(1);
};
Subscription subscription = component.addValueChangeListener(listener1);
component.setOptionsList(new ArrayList<>(Arrays.asList("One", "Two", "Three")));
component.setValue("Two");
subscription.remove();
assertEquals(1, counter.get());
Consumer<HasValue.ValueChangeEvent> listener2 = e -> {
assertEquals("Two", e.getPrevValue());
assertEquals("One", e.getValue());
counter.addAndGet(1);
};
subscription = component.addValueChangeListener(listener2);
component.setValue("One");
assertEquals("One", component.getValue());
assertEquals(2, counter.get());
subscription.remove();
Consumer<HasValue.ValueChangeEvent> listener3 = e -> {
assertEquals("One", e.getPrevValue());
assertEquals("Three", e.getValue());
counter.addAndGet(1);
};
component.addValueChangeListener(listener3);
component.setValue("Three");
assertEquals(3, counter.get());
}
Aggregations