use of org.corpus_tools.annis.gui.flatquerybuilder.ValueField in project ANNIS by korpling.
the class FlatQueryBuilderTest method valueFieldTextChange.
@Test
void valueFieldTextChange() {
initQueryBuilder(0);
// Add a pos annotation
queryBuilder.addLinguisticSequenceBox("pos");
SearchBox searchBox = _get(queryBuilder, SearchBox.class);
ValueField valueField = _get(queryBuilder, ValueField.class);
SensitiveComboBox cb = _get(searchBox, SensitiveComboBox.class);
@SuppressWarnings("unchecked") List<String> oldItemIds = new ArrayList<>((Collection<String>) cb.getItemIds());
assertNotEquals("VAFIN", oldItemIds.get(0));
assertNotEquals("VMFIN", oldItemIds.get(1));
assertNotEquals("VVFIN", oldItemIds.get(2));
// Mock a text change event
TextChangeEvent eventVFIN = mock(TextChangeEvent.class);
when(eventVFIN.getText()).thenReturn("VFIN");
valueField.textChange(eventVFIN);
MockVaadin.INSTANCE.clientRoundtrip();
// Check that the order has changed to include the nearest values first
@SuppressWarnings("unchecked") List<String> newItemIds = new ArrayList<>((Collection<String>) cb.getItemIds());
assertEquals("VAFIN", newItemIds.get(0));
assertEquals("VMFIN", newItemIds.get(1));
assertEquals("VVFIN", newItemIds.get(2));
// Test with an empty and null value, the suggestions should stay the same
TextChangeEvent eventEmpty = mock(TextChangeEvent.class);
when(eventEmpty.getText()).thenReturn("");
valueField.textChange(eventEmpty);
MockVaadin.INSTANCE.clientRoundtrip();
newItemIds = new ArrayList<>((Collection<String>) cb.getItemIds());
assertEquals("VAFIN", newItemIds.get(0));
assertEquals("VMFIN", newItemIds.get(1));
assertEquals("VVFIN", newItemIds.get(2));
TextChangeEvent eventNull = mock(TextChangeEvent.class);
when(eventNull.getText()).thenReturn(null);
valueField.textChange(eventNull);
MockVaadin.INSTANCE.clientRoundtrip();
newItemIds = new ArrayList<>((Collection<String>) cb.getItemIds());
assertEquals("VAFIN", newItemIds.get(0));
assertEquals("VMFIN", newItemIds.get(1));
assertEquals("VVFIN", newItemIds.get(2));
}
Aggregations