Skip to content

Commit

Permalink
#6835: add new table display tests (#7000)
Browse files Browse the repository at this point in the history
* #6835 add new tests to notebook

* #6835 create new tests
  • Loading branch information
wojciechowskim authored and scottdraves committed Mar 22, 2018
1 parent 9bf5095 commit ab951fe
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 35 deletions.
77 changes: 75 additions & 2 deletions test/ipynb/groovy/MapLikeTableTest.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1c732f17-98ac-4ee2-9a2c-148f76cb5ca0",
"version_major": 2,
"version_minor": 0
},
"method": "display_data"
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"def myMap = [:]\n",
"def myList = []\n",
Expand All @@ -72,6 +85,66 @@
"myMap"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "271d4b86-d3f3-4597-8e84-ad04c62cb8a2",
"version_major": 2,
"version_minor": 0
},
"method": "display_data"
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"new TableDisplay([[col1: \"This & that\", col2: \"This / that\", col3: \"This > that\"]]);"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5ab08c88-068d-48b3-88c0-97962fec8bd6",
"version_major": 2,
"version_minor": 0
},
"method": "display_data"
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"class MyClass {\n",
" def value;\n",
" public MyClass(String value) {\n",
" this.value = value\n",
" }\n",
" \n",
" public String toString() {\n",
" return this.value;\n",
" }\n",
"}\n",
"\n",
"def clz = new MyClass(\"print this\")\n",
"def tableData = [\n",
" [myclass: clz]\n",
"]\n",
"displayObject = new TableDisplay(tableData);\n",
"displayObject"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
96 changes: 63 additions & 33 deletions test/js/groovy/mapLikeTableTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,17 @@ describe('(Groovy) Testing Map Like Tables', function () {
beakerxPO.closeAndHaltNotebook();
});

function checkRowValues(dtContainer, rowIndex, cell1, cell2, cell3) {
expect(tableHelper.getCellOfTableBody(dtContainer, rowIndex, 0).getText()).toMatch(cell1);
expect(tableHelper.getCellOfTableBody(dtContainer, rowIndex, 1).getText()).toMatch(cell2);
expect(tableHelper.getCellOfTableBody(dtContainer, rowIndex, 2).getText()).toMatch(cell3);
}
function checkHeaderValues(dtContainer, headerCellIndex, value) {
var headers = tableHelper.getAllCellsOfTableHeader(dtContainer);

function checkHeaderValues(dtContainer, value1, value2) {
expect(tableHelper.getCellOfTableHeader(dtContainer, 1).getText()).toMatch(value1);
expect(tableHelper.getCellOfTableHeader(dtContainer, 2).getText()).toMatch(value2);
expect(headers[headerCellIndex].getText()).toMatch(value);
}

function checkTableRows(dtContainer, lenght) {
expect(tableHelper.getAllRowsOfTableBody(dtContainer).length).toEqual(lenght);
function checkRowValues(dtContainer, rowCellIndex, value) {
var rows = tableHelper.getAllRowsOfTableBody(dtContainer
);

expect(rows[rowCellIndex].getText()).toBe(value);
}

var cellIndex;
Expand All @@ -53,53 +51,85 @@ describe('(Groovy) Testing Map Like Tables', function () {
cellIndex = 0;
var dtContainer = beakerxPO.runCellToGetDtContainer(cellIndex);

checkHeaderValues(dtContainer, 'Key', 'Value');
checkRowValues(dtContainer, 0, '0', 'x', '1');
checkRowValues(dtContainer, 1, '1', 'y', '2');
checkHeaderValues(dtContainer, 1, 'Key');
checkHeaderValues(dtContainer, 2, 'Value');

checkRowValues(dtContainer, 0, '0 x 1');
checkRowValues(dtContainer, 1, '1 y 2');
});

it('An ArrayList is rendered correctly', function () {
cellIndex += 1;
var dtContainer = beakerxPO.runCellToGetDtContainer(cellIndex);
dtContainer = beakerxPO.runCellToGetDtContainer(cellIndex);

checkHeaderValues(dtContainer, 1, 'x');
checkHeaderValues(dtContainer, 2, 'y');

checkHeaderValues(dtContainer, 'x', 'y');
checkRowValues(dtContainer, 0, '0', '1', '2');
checkRowValues(dtContainer, 1, '1', '3', '4');
checkRowValues(dtContainer, 0, '0 1 2');
checkRowValues(dtContainer, 1, '1 3 4');
});

it('A Map is rendered correctly', function () {
cellIndex += 1;
var dtContainer = beakerxPO.runCellToGetDtContainer(cellIndex);
dtContainer = beakerxPO.runCellToGetDtContainer(cellIndex);

checkHeaderValues(dtContainer, 'x', 'y');
checkRowValues(dtContainer, 0, '0', '1', '2');
checkRowValues(dtContainer, 1, '1', '3', '4');
checkHeaderValues(dtContainer, 1, 'x');
checkHeaderValues(dtContainer, 2, 'y');

checkRowValues(dtContainer, 0, '0 1 2');
checkRowValues(dtContainer, 1, '1 3 4');
});

it('A Map is rendered correctly', function () {
cellIndex += 1;
var dtContainer = beakerxPO.runCellToGetDtContainer(cellIndex);
dtContainer = beakerxPO.runCellToGetDtContainer(cellIndex);

checkHeaderValues(dtContainer, 1, 'test');
checkHeaderValues(dtContainer, 2, 'test2');

checkHeaderValues(dtContainer, 'test', 'test2');
checkRowValues(dtContainer, 0, '0', '1', '2');
checkRowValues(dtContainer, 1, '1', '2', '4');
checkRowValues(dtContainer, 2, '2', '3', '6');
checkRowValues(dtContainer, 0, '0 1 2');
checkRowValues(dtContainer, 1, '1 2 4');
checkRowValues(dtContainer, 2, '2 3 6');
});

it('A List inside a List is rendered correctly', function () {
cellIndex += 1;
var dtContainer = beakerxPO.runCellToGetDtContainer(cellIndex);
dtContainer = beakerxPO.runCellToGetDtContainer(cellIndex);

checkHeaderValues(dtContainer, 1, 'Key');
checkHeaderValues(dtContainer, 2, 'Value');

checkHeaderValues(dtContainer, 'Key', 'Value');
checkRowValues(dtContainer, 0, '0', '1', '[[1,2,3],[2,3,4]]');
checkRowValues(dtContainer, 0, '0 1 [[1,2,3],[2,3,4]]');
});

it('A Map inside a List is rendered correctly', function () {
cellIndex += 1;
var dtContainer = beakerxPO.runCellToGetDtContainer(cellIndex);
dtContainer = beakerxPO.runCellToGetDtContainer(cellIndex);

checkHeaderValues(dtContainer, 1, 'Key');
checkHeaderValues(dtContainer, 2, 'Value');

checkRowValues(dtContainer, 0, '0 1 {"num1":1,"num2":2}');
});

it('Display a 3-column table', function () {
cellIndex += 1;
dtContainer = beakerxPO.runCellToGetDtContainer(cellIndex);

checkHeaderValues(dtContainer, 1, 'col1');
checkHeaderValues(dtContainer, 2, 'col2');
checkHeaderValues(dtContainer, 3, 'col3');

checkRowValues(dtContainer, 0, '0 This & that This / that This > that');

});

it('Display object is rendered correctly', function () {
cellIndex += 1;
dtContainer = beakerxPO.runCellToGetDtContainer(cellIndex);

checkHeaderValues(dtContainer, 'Key', 'Value');
checkRowValues(dtContainer, 0, '0', '1', '{"num1":1,"num2":2}');
checkHeaderValues(dtContainer, 1, 'myclass');
checkRowValues(dtContainer, 0, '0 {"value":"print this"}');
});
});
});
});

0 comments on commit ab951fe

Please sign in to comment.