use of com.github.mvysny.kaributesting.v8.GridKt in project ANNIS by korpling.
the class AnnisUITest method tokenSearchPcc2.
@Test
void tokenSearchPcc2() throws Exception {
executeTokenSearch("pcc2", 399, 2);
// Test that the cell values have the correct token value
SingleResultPanel resultPanel = _find(SingleResultPanel.class).get(0);
KWICComponent kwicVis = _get(resultPanel, KWICComponent.class);
AnnotationGrid kwicGrid = _get(kwicVis, AnnotationGrid.class);
ArrayList<Row> tokens = kwicGrid.getRowsByAnnotation().get("tok");
assertEquals(1, tokens.size());
assertEquals(Arrays.asList("Feigenblatt", "Die", "Jugendlichen", "in", "Zossen", "wollen"), tokens.get(0).getEvents().stream().map(GridEvent::getValue).collect(Collectors.toList()));
// Check the annotation values are shown
ArrayList<Row> lemmaRows = kwicGrid.getRowsByAnnotation().get("tiger::lemma");
assertEquals(1, lemmaRows.size());
assertEquals(Arrays.asList("Feigenblatt", "der", "jugendliche", "in", "Zossen", "wollen"), lemmaRows.get(0).getEvents().stream().map(GridEvent::getValue).collect(Collectors.toList()));
ArrayList<Row> posRows = kwicGrid.getRowsByAnnotation().get("tiger::pos");
assertEquals(1, posRows.size());
assertEquals(Arrays.asList("NN", "ART", "NN", "APPR", "NE", "VMFIN"), posRows.get(0).getEvents().stream().map(GridEvent::getValue).collect(Collectors.toList()));
// Test that we can show the first metadata for the button
List<Button> infoButtons = _find(Button.class, spec -> spec.withPredicate(b -> "Show metadata".equals(b.getDescription())));
assertEquals(10, infoButtons.size());
_click(infoButtons.get(0));
Window infoWindow = _get(Window.class);
assertEquals("Info for salt:/pcc2/11299", infoWindow.getCaption());
awaitCondition(30, () -> !_find(infoWindow, Accordion.class).isEmpty());
Accordion metaAccordion = _get(infoWindow, Accordion.class);
@SuppressWarnings("rawtypes") List<Grid> metadataGrids = _find(metaAccordion, Grid.class);
assertEquals(2, metadataGrids.size());
assertEquals("11299 (document)", metaAccordion.getTab(metadataGrids.get(0)).getCaption());
assertEquals("pcc2 (corpus)", metaAccordion.getTab(metadataGrids.get(1)).getCaption());
@SuppressWarnings("unchecked") Annotation firstAnno = (Annotation) GridKt._get(metadataGrids.get(0), 0);
assertEquals("Dokumentname", firstAnno.getKey().getName());
assertEquals("pcc-11299", firstAnno.getVal());
@SuppressWarnings("unchecked") Annotation secondAnno = (Annotation) GridKt._get(metadataGrids.get(0), 1);
assertEquals("Genre", secondAnno.getKey().getName());
assertEquals("Politik", secondAnno.getVal());
@SuppressWarnings("unchecked") Annotation thirdAnno = (Annotation) GridKt._get(metadataGrids.get(0), 2);
assertEquals("Titel", thirdAnno.getKey().getName());
assertEquals("Feigenblatt", thirdAnno.getVal());
// Disable the part-of-speech token annotation display
TreeSet<String> visibleAnnos = new TreeSet<>(Arrays.asList("tiger::lemma"));
resultPanel.setVisibleTokenAnnosVisible(visibleAnnos);
assertNull(kwicGrid.getRowsByAnnotation().get("tiger:pos"));
assertNotNull(kwicGrid.getRowsByAnnotation().get("tiger::lemma"));
// Change the context and test that the KWIC displayed also changed
resultPanel.changeContext(1, 6, false);
// Since the action will replace the whole result panel, we have to get all
// variables again.
List<String> expectedTokens = Arrays.asList("Feigenblatt", "Die", "Jugendlichen", "in", "Zossen", "wollen", "ein");
awaitCondition(10, () -> {
List<SingleResultPanel> allResults = _find(SingleResultPanel.class);
if (allResults.isEmpty()) {
return false;
}
List<AnnotationGrid> annoGrids = _find(allResults.get(0), AnnotationGrid.class);
if (annoGrids.isEmpty()) {
return false;
}
ArrayList<Row> tokensUpdatedContext = annoGrids.get(0).getRowsByAnnotation().get("tok");
if (tokensUpdatedContext.isEmpty()) {
return false;
}
List<String> actualTokens = tokensUpdatedContext.get(0).getEvents().stream().map(GridEvent::getValue).collect(Collectors.toList());
return expectedTokens.equals(actualTokens);
});
}
Aggregations