Skip to content

Commit

Permalink
Test that filter change via DataView fires DataChangeEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
TatuLund committed Jul 31, 2023
1 parent 5558f5b commit 1aabbff
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/test/java/org/vaadin/tatu/BeanTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ public void lazyFilteringAndPaging() {
fakeClientCommunication();
Assert.assertEquals("No data",
table.bodyElement.getChild(0).getChild(0).getText());
Assert.assertEquals(0, table.footerElement.getChildCount());
Assert.assertEquals(0, table.footerElement.getChildCount());
}

@Test
Expand Down Expand Up @@ -754,10 +754,14 @@ public void column() {

@Test
public void dataView() {
AtomicInteger refreshed = new AtomicInteger(0);
BeanTable<String> table = new BeanTable<>();
BeanTableListDataView<String> dataView = table.setItems("One", "Two",
"Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
"Ten");
table.getDataProvider().addDataProviderListener(e -> {
refreshed.incrementAndGet();
});

Assert.assertEquals(10, dataView.getItemCount());
Assert.assertEquals("One", dataView.getItem(0));
Expand All @@ -769,6 +773,8 @@ public void dataView() {
Assert.assertEquals("Three", table.getGenericDataView().getItem(2));

dataView.setFilter(item -> item.startsWith("T"));
Assert.assertEquals(1, refreshed.get());

Assert.assertEquals(3, dataView.getItemCount());
Assert.assertEquals("Two", dataView.getItem(0));
Assert.assertEquals("Three", dataView.getItem(1));
Expand Down Expand Up @@ -851,7 +857,6 @@ public void selection() {
assertSelectedThemeNotSet(table, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}


@Test
public void emptyTable() {
BeanTable<DataItem> table = new BeanTable<>();
Expand Down Expand Up @@ -893,10 +898,10 @@ private void assertSelectedThemeSet(BeanTable<DataItem> table,
for (int item : items) {
Element row = table.bodyElement.getChild(item);
Assert.assertEquals("item at index " + item + " should be selected",
"selected",
row.getAttribute("theme"));
for (int i=1;i<row.getChildCount();i++) {
Assert.assertEquals("true", row.getChild(i).getAttribute("aria-selected"));
"selected", row.getAttribute("theme"));
for (int i = 1; i < row.getChildCount(); i++) {
Assert.assertEquals("true",
row.getChild(i).getAttribute("aria-selected"));
}
}
}
Expand All @@ -908,8 +913,9 @@ private void assertSelectedThemeNotSet(BeanTable<DataItem> table,
Assert.assertEquals(
"item at index " + item + " should not be selected", null,
row.getAttribute("theme"));
for (int i=1;i<row.getChildCount();i++) {
Assert.assertEquals("false", row.getChild(i).getAttribute("aria-selected"));
for (int i = 1; i < row.getChildCount(); i++) {
Assert.assertEquals("false",
row.getChild(i).getAttribute("aria-selected"));
}
}
}
Expand Down

0 comments on commit 1aabbff

Please sign in to comment.