use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols in project scout.rt by eclipse.
the class JsonTableTest method testRowFilter.
@Test
public void testRowFilter() throws JSONException {
TableWith3Cols table = new TableWith3Cols();
table.fill(3);
table.initTable();
JsonTable<ITable> jsonTable = m_uiSession.createJsonAdapter(table, null);
ITableRow row0 = table.getRow(0);
ITableRow row1 = table.getRow(1);
ITableRow row2 = table.getRow(2);
jsonTable.toJson();
assertNotNull(jsonTable.tableRowIdsMap().get(row0));
assertNotNull(jsonTable.tableRowIdsMap().get(row1));
assertNotNull(jsonTable.tableRowIdsMap().get(row2));
String row0Id = jsonTable.getOrCreateRowId(row0);
String row1Id = jsonTable.getOrCreateRowId(row1);
assertNotNull(row0Id);
assertNotNull(jsonTable.getTableRow(row0Id));
assertNotNull(row1Id);
assertNotNull(jsonTable.getTableRow(row1Id));
table.addRowFilter(new ITableRowFilter() {
@Override
public boolean accept(ITableRow r) {
// hide first row
return r.getRowIndex() > 0;
}
});
// After flushing the event buffers and applying the model changes
// to the JsonTable, the row should not exist anymore on the JsonTable
JsonTestUtility.processBufferedEvents(m_uiSession);
assertEquals(3, table.getRowCount());
assertEquals(2, table.getFilteredRowCount());
assertNull(jsonTable.tableRowIdsMap().get(row0));
assertNotNull(jsonTable.tableRowIdsMap().get(row1));
assertNotNull(jsonTable.tableRowIdsMap().get(row2));
// should still exist -> should NOT throw an exception
jsonTable.getTableRow(row1Id);
try {
// throws exception
jsonTable.getTableRow(row0Id);
fail("Expected an exception, but no exception was thrown");
} catch (UiException e) {
// ok
}
}
use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols in project scout.rt by eclipse.
the class JsonTableTest method testRequestFocusInCellCoalesceInMultipleResponses.
@Test
public void testRequestFocusInCellCoalesceInMultipleResponses() throws Exception {
TableWith3Cols table = new TableWith3Cols();
table.fill(2);
table.initTable();
table.resetColumns();
table.setAutoDiscardOnDelete(true);
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
// Response should contain no events
assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
// Request Focus without a row
final ITableRow row = table.getRow(0);
table.requestFocusInCell(table.getColumns().get(0), row);
table.deleteAllRows();
// Events should not yet be in the response
assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
// And there should only one delete event
assertEquals(1, jsonTable.eventBuffer().size());
assertEquals(TableEvent.TYPE_ALL_ROWS_DELETED, jsonTable.eventBuffer().getBufferInternal().get(0).getType());
// So there should be no events at all in the response
JsonTestUtility.processBufferedEvents(m_uiSession);
JSONObject response = m_uiSession.currentJsonResponse().toJson();
assertNull(response.optJSONArray("events"));
// end current request
JsonTestUtility.endRequest(m_uiSession);
// try to requestFocusInCell on deleted row
table.requestFocusInCell(table.getColumns().get(0), row);
// Events should not be in the response
assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
// And also not in the event buffer
assertEquals(0, jsonTable.eventBuffer().size());
// So there should be no events at all in the response
JSONObject response2 = m_uiSession.currentJsonResponse().toJson();
assertNull(response2.optJSONArray("events"));
}
use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols in project scout.rt by eclipse.
the class JsonTableTest method testUserRowFilter_toJson.
/**
* If toJson is called and a user filter is active, every row must be returned and not only the filtered ones
*/
@Test
public void testUserRowFilter_toJson() throws JSONException {
TableWith3Cols table = new TableWith3Cols();
table.fill(3);
table.initTable();
JsonTable<ITable> jsonTable = m_uiSession.createJsonAdapter(table, null);
ITableRow row0 = table.getRow(0);
ITableRow row2 = table.getRow(2);
List<ITableRow> filteredRows = new ArrayList<ITableRow>();
filteredRows.add(row0);
filteredRows.add(row2);
table.getUIFacade().setFilteredRowsFromUI(filteredRows);
jsonTable.toJson();
JsonTestUtility.processBufferedEvents(m_uiSession);
assertEquals(3, table.getRowCount());
assertEquals(2, table.getFilteredRowCount());
assertEquals(3, jsonTable.tableRowIdsMap().size());
}
use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols in project scout.rt by eclipse.
the class JsonTableTest method testRowFilter_nop.
/**
* Usecase:
* <p>
* 1. Add filter to table<br>
* 2. Remove same filter so that no rows are removed<br>
* Assert that no events are generated, especially no rowsDeleted event
*/
@Test
public void testRowFilter_nop() throws JSONException {
TableWith3Cols table = new TableWith3Cols();
table.fill(3);
table.initTable();
JsonTable<ITable> jsonTable = m_uiSession.createJsonAdapter(table, null);
ITableRow row0 = table.getRow(0);
ITableRow row1 = table.getRow(1);
ITableRow row2 = table.getRow(2);
jsonTable.toJson();
assertNotNull(jsonTable.tableRowIdsMap().get(row0));
assertNotNull(jsonTable.tableRowIdsMap().get(row1));
assertNotNull(jsonTable.tableRowIdsMap().get(row2));
ITableRowFilter filter = new ITableRowFilter() {
@Override
public boolean accept(ITableRow r) {
// hide first row
return r.getRowIndex() > 0;
}
};
table.addRowFilter(filter);
assertEquals(2, table.getFilteredRowCount());
// Remove the just added filter -> Must not create any request
table.removeRowFilter(filter);
assertEquals(3, table.getFilteredRowCount());
JsonTestUtility.processBufferedEvents(m_uiSession);
assertNotNull(jsonTable.tableRowIdsMap().get(row1));
assertNotNull(jsonTable.tableRowIdsMap().get(row1));
assertNotNull(jsonTable.tableRowIdsMap().get(row2));
assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
}
use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols in project scout.rt by eclipse.
the class JsonTableTest method testDeleteAfterMove.
@Test
public void testDeleteAfterMove() throws Exception {
TableWith3Cols table = new TableWith3Cols();
table.initTable();
table.fill(3, false);
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
m_uiSession.currentJsonResponse().addAdapter(jsonTable);
JSONObject response = m_uiSession.currentJsonResponse().toJson();
JsonTestUtility.endRequest(m_uiSession);
String row0Id = jsonTable.getTableRowId(table.getRow(0));
String row1Id = jsonTable.getTableRowId(table.getRow(1));
String row2Id = jsonTable.getTableRowId(table.getRow(2));
table.moveRow(0, 2);
table.deleteRow(0);
response = m_uiSession.currentJsonResponse().toJson();
JsonTestUtility.endRequest(m_uiSession);
JSONArray events = response.optJSONArray("events");
assertEquals(2, events.length());
JSONObject event0 = events.getJSONObject(0);
JSONObject event1 = events.getJSONObject(1);
assertEquals("rowOrderChanged", event0.getString("type"));
JSONArray rowIds = event0.optJSONArray("rowIds");
assertTrue(rowIds.length() == 3);
assertEquals(row2Id, rowIds.get(0));
assertEquals(row0Id, rowIds.get(1));
// <-- this is not correct but since it will be deleted it is fine
assertEquals(row1Id, rowIds.get(2));
assertEquals("rowsDeleted", event1.getString("type"));
}
Aggregations