Search in sources :

Example 1 with ValueField

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));
}
Also used : SensitiveComboBox(org.corpus_tools.annis.gui.flatquerybuilder.SensitiveComboBox) TextChangeEvent(com.vaadin.v7.event.FieldEvents.TextChangeEvent) ArrayList(java.util.ArrayList) Collection(java.util.Collection) SearchBox(org.corpus_tools.annis.gui.flatquerybuilder.SearchBox) ValueField(org.corpus_tools.annis.gui.flatquerybuilder.ValueField) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

TextChangeEvent (com.vaadin.v7.event.FieldEvents.TextChangeEvent)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 SearchBox (org.corpus_tools.annis.gui.flatquerybuilder.SearchBox)1 SensitiveComboBox (org.corpus_tools.annis.gui.flatquerybuilder.SensitiveComboBox)1 ValueField (org.corpus_tools.annis.gui.flatquerybuilder.ValueField)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1