use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols in project scout.rt by eclipse.
the class JsonTableTest method testColumnOrderChangedEvent_assertCellOrder.
@Test
public void testColumnOrderChangedEvent_assertCellOrder() throws JSONException {
TableWith3Cols table = new TableWith3Cols();
table.fill(2);
table.initTable();
table.resetColumns();
IColumn<?> column0 = table.getColumns().get(0);
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
jsonTable.toJson();
// ----------
JSONObject jsonRow = jsonTable.tableRowToJson(table.getRow(0));
JSONArray jsonCells = (JSONArray) jsonRow.get("cells");
JsonEvent event = createJsonColumnMovedEvent(jsonTable.getColumnId(column0), 2);
jsonTable.handleUiEvent(event);
JSONObject jsonRowAfterMoving = jsonTable.tableRowToJson(table.getRow(0));
JSONArray jsonCellsAfterMoving = (JSONArray) jsonRowAfterMoving.get("cells");
// Expect same cell order, even if the columns are moved
for (int i = 0; i < jsonCellsAfterMoving.length(); i++) {
assertEquals(jsonCells.get(i), jsonCellsAfterMoving.get(i));
}
}
use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols in project scout.rt by eclipse.
the class JsonTableTest method testTableEventCoalesceInUi_TwoRowsAdded.
/**
* Tests that multiple model events are coalseced in JSON layer
*/
@Test
public void testTableEventCoalesceInUi_TwoRowsAdded() throws Exception {
TableWith3Cols table = new TableWith3Cols();
table.fill(2);
table.initTable();
table.resetColumns();
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
// Response should contain no events
assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
// Add two rows sequentially --> this should trigger two TableEvents
table.addRowsByMatrix(new Object[] { new Object[] { "NewCell_0", "NewCell_1", "NewCell_2" } });
table.addRowsByMatrix(new Object[] { new Object[] { "AnotherNewCell_0", "AnotherNewCell_1", "AnotherNewCell_2" } });
// Events should not yet be in the response
assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
// But they should be in the event buffer
assertEquals(2, jsonTable.eventBuffer().size());
// When converting to JSON, the event buffer should be cleared and the events should
// be coalesced and written to the response. --> Only one insert event (with two rows)
JSONObject response = m_uiSession.currentJsonResponse().toJson();
assertEquals(0, jsonTable.eventBuffer().size());
JSONArray events = response.getJSONArray("events");
assertEquals(1, events.length());
assertEquals(2, events.getJSONObject(0).getJSONArray("rows").length());
}
use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols in project scout.rt by eclipse.
the class JsonTableTest method testRequestFocusInCellCoalesceWithtAutoDiscardOnDelete.
/**
* Tests if a RequestFocusInCell-Event gets discarded when all rows of the table get deleted and the table has
* setAutoDiscardOnDelete set to true
*/
@Test
public void testRequestFocusInCellCoalesceWithtAutoDiscardOnDelete() {
TableWith3Cols table = new TableWith3Cols();
table.fill(2);
table.initTable();
table.setAutoDiscardOnDelete(true);
table.resetColumns();
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
table.requestFocusInCell(table.getColumns().get(0), table.getRow(0));
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());
}
use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols in project scout.rt by eclipse.
the class JsonTableTest method testTableEventCoalesceInUi_UpdateEventOnFilteredRow.
@Test
public void testTableEventCoalesceInUi_UpdateEventOnFilteredRow() throws Exception {
TableWith3Cols table = new TableWith3Cols();
table.initTable();
table.fill(1, false);
table.resetColumns();
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
m_uiSession.currentJsonResponse().addAdapter(jsonTable);
JSONObject response = m_uiSession.currentJsonResponse().toJson();
JsonTestUtility.endRequest(m_uiSession);
// -------------
table.fill(2, false);
// would normally trigger an event, but we filter the row in the next step
table.getRow(2).setChecked(true);
table.addRowFilter(new ITableRowFilter() {
@Override
public boolean accept(ITableRow r) {
// hide everything expect the first (already existing row)
return r.getRowIndex() == 0;
}
});
response = m_uiSession.currentJsonResponse().toJson();
assertEquals(0, jsonTable.eventBuffer().size());
JSONArray events = response.optJSONArray("events");
// No events should be emitted
assertNull(events);
}
use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols in project scout.rt by eclipse.
the class JsonTableTest method testOptTableRow.
@Test
public void testOptTableRow() throws Exception {
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, new TableWith3Cols(), null);
assertNull(jsonTable.optTableRow("foo"));
}
Aggregations