AssetsTableView implements UberElemental<AssetsTableView.Presenter> { void filterTable() { String query = searchAssets.value.trim().toLowerCase(); HTMLCollection<HTMLTableRowElement> rows = assetsTable.tBodies.getAt(0).rows; IntStream.range(0, rows.getLength()).mapToObj(rows::getAt).forEach(row -> { row.hidden = false; if (!query.isEmpty()) { row.hidden = IntStream.range(0, row.cells.getLength()) .mapToObj(row.cells::getAt) .noneMatch(c -> c.textContent.toLowerCase().contains(query)); } }); }  @Override void init(Presenter presenter); void update(); List<?> getSelectedAssets(); @Override HTMLElement getElement(); void clearFilter();  }
@Test public void testFilterTable() { HTMLInputElement filter = assetsTableView.searchAssets; HTMLTableElement table = assetsTableView.assetsTable; HTMLCollection rows = mock(HTMLCollection.class); HTMLTableRowElement[] actualRows = { mock(HTMLTableRowElement.class), mock(HTMLTableRowElement.class) }; HTMLCollection<HTMLTableCellElement> firstRowCells = mock(HTMLCollection.class); HTMLCollection<HTMLTableCellElement> secondRowCells = mock(HTMLCollection.class); HTMLTableCellElement tableCellElement1 = mock(HTMLTableCellElement.class), tableCellElement2 = mock(HTMLTableCellElement.class); tableCellElement1.textContent = "Abc"; tableCellElement2.textContent = "dEfx"; when(firstRowCells.getAt(0)).thenReturn(tableCellElement1); when(firstRowCells.getAt(1)).thenReturn(tableCellElement2); HTMLTableCellElement tableCellElement3 = mock(HTMLTableCellElement.class), tableCellElement4 = mock(HTMLTableCellElement.class); tableCellElement3.textContent = "gHi"; tableCellElement4.textContent = "jKlX"; when(secondRowCells.getAt(0)).thenReturn(tableCellElement3); when(secondRowCells.getAt(1)).thenReturn(tableCellElement4); actualRows[0].cells = firstRowCells; actualRows[1].cells = secondRowCells; when(actualRows[0].cells.getLength()).thenReturn(2); when(actualRows[1].cells.getLength()).thenReturn(2); for (int i = 0; i < actualRows.length; i++) { when(rows.getAt(i)).thenReturn(actualRows[i]); } when(rows.getLength()).thenReturn(actualRows.length); table.tBodies.getAt(0).rows = rows; filter.value = "abC"; assetsTableView.filterTable(); assertTrue(actualRows[1].hidden); assertFalse(actualRows[0].hidden); filter.value = "jkL"; assetsTableView.filterTable(); assertTrue(actualRows[0].hidden); assertFalse(actualRows[1].hidden); filter.value = "X"; assetsTableView.filterTable(); assertFalse(actualRows[0].hidden); assertFalse(actualRows[1].hidden); filter.value = "z"; assetsTableView.filterTable(); assertTrue(actualRows[0].hidden); assertTrue(actualRows[1].hidden); }