From 78f93b64b2bd98dea60bff62b235692f2830f615 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 25 Jan 2018 16:48:44 +0300 Subject: [PATCH] add e2e tests for autotranslation groovy, python to jscript (#6718) * add test notebook * add test notebook * test data * add tests for autotranslation * add tests for autotranslation * clean test notebook --- .../groovy/AutoTranslationGroovyTest.ipynb | 183 ++++++++++++++++ .../python/AutoTranslationPythonTest.ipynb | 195 ++++++++++++++++++ .../tests/groovy/autotranslationGroovyTest.js | 93 +++++++++ .../tests/python/autotranslationPythonTest.js | 93 +++++++++ 4 files changed, 564 insertions(+) create mode 100644 test/notebooks/groovy/AutoTranslationGroovyTest.ipynb create mode 100644 test/notebooks/python/AutoTranslationPythonTest.ipynb create mode 100644 test/tests/groovy/autotranslationGroovyTest.js create mode 100644 test/tests/python/autotranslationPythonTest.js diff --git a/test/notebooks/groovy/AutoTranslationGroovyTest.ipynb b/test/notebooks/groovy/AutoTranslationGroovyTest.ipynb new file mode 100644 index 0000000000..838c2c73a7 --- /dev/null +++ b/test/notebooks/groovy/AutoTranslationGroovyTest.ipynb @@ -0,0 +1,183 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "92c91f77-7bdc-4ed8-be5e-f114281fa4ab", + "version_major": 2, + "version_minor": 0 + }, + "method": "display_data" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "def nodes = []\n", + "\n", + "for (x in (0..10)){\n", + " nodes.add(radius: x*5 + 5, colorB:(x*20))\n", + "}\n", + "\n", + "beakerx.testData = [nodes: nodes]" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "application/javascript": [ + "require.config({\r\n", + " paths: {\r\n", + " d3: '//cdnjs.cloudflare.com/ajax/libs/d3/4.9.1/d3.min'\r\n", + " }});" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "%%javascript\n", + "require.config({\n", + " paths: {\n", + " d3: '//cdnjs.cloudflare.com/ajax/libs/d3/4.9.1/d3.min'\n", + " }});" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "%%html\n", + "" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "application/javascript": [ + "\r\n", + "beakerx.displayHTML(this, '
');\r\n", + "\r\n", + "var testData = beakerx.testData\r\n", + "\r\n", + "var d3 = require(['d3'], function (d3) {\r\n", + " \r\n", + " var width = 600,\r\n", + " height = 200;\r\n", + "\r\n", + " var svg = d3.select(\"#bkrx\")\r\n", + " .append(\"svg\")\r\n", + " .attr(\"width\", width)\r\n", + " .attr(\"height\", height)\r\n", + " .attr(\"transform\", \"translate(\"+[100, 0]+\")\");\r\n", + "\r\n", + " var node = svg.selectAll()\r\n", + " .data(testData.nodes)\r\n", + " .enter().append(\"circle\")\r\n", + " .attr(\"class\", \"moon\")\r\n", + " .attr(\"r\", function(d) { return d.radius; })\r\n", + " .attr(\"cx\", function(d, i) { return i*40 + d.radius; })\r\n", + " .attr(\"cy\", function(d, i) { return 50 + d.radius; })\r\n", + " .style(\"fill\", function(d) { return d3.rgb(100, 100 , d.colorB); }); \r\n", + "});" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "%%javascript\n", + "\n", + "beakerx.displayHTML(this, '
');\n", + "\n", + "var testData = beakerx.testData\n", + "\n", + "var d3 = require(['d3'], function (d3) {\n", + " \n", + " var width = 600,\n", + " height = 200;\n", + "\n", + " var svg = d3.select(\"#bkrx\")\n", + " .append(\"svg\")\n", + " .attr(\"width\", width)\n", + " .attr(\"height\", height)\n", + " .attr(\"transform\", \"translate(\"+[100, 0]+\")\");\n", + "\n", + " var node = svg.selectAll()\n", + " .data(testData.nodes)\n", + " .enter().append(\"circle\")\n", + " .attr(\"class\", \"moon\")\n", + " .attr(\"r\", function(d) { return d.radius; })\n", + " .attr(\"cx\", function(d, i) { return i*40 + d.radius; })\n", + " .attr(\"cy\", function(d, i) { return 50 + d.radius; })\n", + " .style(\"fill\", function(d) { return d3.rgb(100, 100 , d.colorB); }); \n", + "});" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Groovy", + "language": "groovy", + "name": "groovy" + }, + "language_info": { + "codemirror_mode": "groovy", + "file_extension": ".groovy", + "mimetype": "", + "name": "Groovy", + "nbconverter_exporter": "", + "version": "2.4.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/test/notebooks/python/AutoTranslationPythonTest.ipynb b/test/notebooks/python/AutoTranslationPythonTest.ipynb new file mode 100644 index 0000000000..1cd6325849 --- /dev/null +++ b/test/notebooks/python/AutoTranslationPythonTest.ipynb @@ -0,0 +1,195 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "0425e93c990544fcbcbbf0d3895af7b2", + "version_major": 2, + "version_minor": 0 + } + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "from beakerx import *\n", + "\n", + "nodes = []\n", + "\n", + "for i in range(0, 10):\n", + " nodes.append({\"radius\": int(i*5 + 5), \"colorB\": int(i*20)})\n", + "\n", + "beakerx.testData = {\"nodes\": nodes}\n", + "\n", + "TableDisplay(nodes)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "application/javascript": [ + "require.config({\n", + " paths: {\n", + " d3: '//cdnjs.cloudflare.com/ajax/libs/d3/4.9.1/d3.min'\n", + " }});" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%%javascript\n", + "require.config({\n", + " paths: {\n", + " d3: '//cdnjs.cloudflare.com/ajax/libs/d3/4.9.1/d3.min'\n", + " }});" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%%html\n", + "" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "application/javascript": [ + "\n", + "beakerx.displayHTML(this, '
');\n", + "\n", + "var testData = beakerx.testData\n", + "\n", + "var d3 = require(['d3'], function (d3) {\n", + " \n", + " var width = 600,\n", + " height = 200;\n", + "\n", + " var svg = d3.select(\"#bkrx\")\n", + " .append(\"svg\")\n", + " .attr(\"width\", width)\n", + " .attr(\"height\", height)\n", + " .attr(\"transform\", \"translate(\"+[100, 0]+\")\");\n", + "\n", + " var node = svg.selectAll()\n", + " .data(testData.nodes)\n", + " .enter().append(\"circle\")\n", + " .attr(\"class\", \"moon\")\n", + " .attr(\"r\", function(d) { return d.radius; })\n", + " .attr(\"cx\", function(d, i) { return i*40 + d.radius; })\n", + " .attr(\"cy\", function(d, i) { return 50 + d.radius; })\n", + " .style(\"fill\", function(d) { return d3.rgb(100, 100 , d.colorB); }); \n", + "});" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%%javascript\n", + "\n", + "beakerx.displayHTML(this, '
');\n", + "\n", + "var testData = beakerx.testData\n", + "\n", + "var d3 = require(['d3'], function (d3) {\n", + " \n", + " var width = 600,\n", + " height = 200;\n", + "\n", + " var svg = d3.select(\"#bkrx\")\n", + " .append(\"svg\")\n", + " .attr(\"width\", width)\n", + " .attr(\"height\", height)\n", + " .attr(\"transform\", \"translate(\"+[100, 0]+\")\");\n", + "\n", + " var node = svg.selectAll()\n", + " .data(testData.nodes)\n", + " .enter().append(\"circle\")\n", + " .attr(\"class\", \"moon\")\n", + " .attr(\"r\", function(d) { return d.radius; })\n", + " .attr(\"cx\", function(d, i) { return i*40 + d.radius; })\n", + " .attr(\"cy\", function(d, i) { return 50 + d.radius; })\n", + " .style(\"fill\", function(d) { return d3.rgb(100, 100 , d.colorB); }); \n", + "});" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/test/tests/groovy/autotranslationGroovyTest.js b/test/tests/groovy/autotranslationGroovyTest.js new file mode 100644 index 0000000000..ce0be872d3 --- /dev/null +++ b/test/tests/groovy/autotranslationGroovyTest.js @@ -0,0 +1,93 @@ +/* + * Copyright 2018 TWO SIGMA OPEN SOURCE, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var BeakerXPageObject = require('../beakerx.po.js'); +var beakerxPO; + +describe('Autotranslation Groovy to JavaScript and D3 tests', function () { + + beforeAll(function () { + beakerxPO = new BeakerXPageObject(); + beakerxPO.runNotebookByUrl('/notebooks/test/notebooks/groovy/AutoTranslationGroovyTest.ipynb'); + }); + + afterAll(function () { + beakerxPO.closeAndHaltNotebook(); + }); + + describe('Groovy code', function(){ + it('Output contains data table', function(){ + var codeCell = beakerxPO.runCodeCellByIndex(0); + var bkoTable = codeCell.$('div.bko-table'); + expect(bkoTable.isEnabled()).toBeTruthy(); + var tblText = bkoTable.$('tbody > tr').getText(); + expect(tblText).toMatch('nodes'); + expect(tblText).toMatch('"radius":10'); + expect(tblText).toMatch('"colorB":20'); + }); + }); + + describe('JavaScript and D3 code', function(){ + var svgElement; + + it('Output contains svg tag', function(){ + beakerxPO.runCodeCellByIndex(1); + beakerxPO.runCodeCellByIndex(2); + var codeCell = beakerxPO.runCodeCellByIndex(3); + browser.pause(2000); + svgElement = codeCell.$('div#bkrx > svg'); + expect(svgElement.isEnabled()).toBeTruthy(); + }); + + it('Should set width, height and transform attributes to svg', function(){ + expect(Math.round(svgElement.getAttribute('width'))).toEqual(600); + expect(Math.round(svgElement.getAttribute('height'))).toEqual(200); + expect(svgElement.getAttribute('transform')).toMatch('translate'); + }); + + it('svg has 11 circles', function(){ + expect(svgElement.$$('circle').length).toEqual(11); + }); + + it('First and last circles has "class"= "moon"', function(){ + expect(svgElement.$$('circle')[0].getAttribute('class')).toEqual('moon'); + expect(svgElement.$$('circle')[10].getAttribute('class')).toEqual('moon'); + }); + + it('First circle has "r"=5, "cx"=5, "cy"=55', function(){ + var fCircle = svgElement.$$('circle')[0]; + expect(Math.round(fCircle.getAttribute('r'))).toEqual(5); + expect(Math.round(fCircle.getAttribute('cx'))).toEqual(5); + expect(Math.round(fCircle.getAttribute('cy'))).toEqual(55); + }); + + it('Last circle has "r"=55, "cx"=455, "cy"=105', function(){ + var lCircle = svgElement.$$('circle')[10]; + expect(Math.round(lCircle.getAttribute('r'))).toEqual(55); + expect(Math.round(lCircle.getAttribute('cx'))).toEqual(455); + expect(Math.round(lCircle.getAttribute('cy'))).toEqual(105); + }); + + it('First circle has color rgb(100,100,0)', function(){ + expect(svgElement.$$('circle')[0].getCssProperty('fill').value).toEqual('rgb(100,100,0)'); + }); + + it('Last circle has color rgb(100,100,200)', function(){ + expect(svgElement.$$('circle')[10].getCssProperty('fill').value).toEqual('rgb(100,100,200)'); + }); + }); + +}); diff --git a/test/tests/python/autotranslationPythonTest.js b/test/tests/python/autotranslationPythonTest.js new file mode 100644 index 0000000000..4c121b2803 --- /dev/null +++ b/test/tests/python/autotranslationPythonTest.js @@ -0,0 +1,93 @@ +/* + * Copyright 2018 TWO SIGMA OPEN SOURCE, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var BeakerXPageObject = require('../beakerx.po.js'); +var beakerxPO; + +describe('Autotranslation Python to JavaScript and D3 tests', function () { + + beforeAll(function () { + beakerxPO = new BeakerXPageObject(); + beakerxPO.runNotebookByUrl('/notebooks/test/notebooks/python/AutoTranslationPythonTest.ipynb'); + }); + + afterAll(function () { + beakerxPO.closeAndHaltNotebook(); + }); + + describe('Python code', function(){ + it('Output contains data table', function(){ + var codeCell = beakerxPO.runCodeCellByIndex(0); + var bkoTable = codeCell.$('div.bko-table'); + expect(bkoTable.isEnabled()).toBeTruthy(); + var headTable = bkoTable.$('div.dataTables_scrollHead'); + expect(headTable.$('th[data-column-index="1"]').getText()).toMatch('radius'); + expect(headTable.$('th[data-column-index="2"]').getText()).toMatch('colorB'); + expect(bkoTable.$('div.dataTables_scrollBody').$$('tbody > tr').length).toEqual(10); + }); + }); + + describe('JavaScript and D3 code', function(){ + var svgElement; + + it('Output contains svg tag', function(){ + beakerxPO.runCodeCellByIndex(1); + beakerxPO.runCodeCellByIndex(2); + var codeCell = beakerxPO.runCodeCellByIndex(3); + browser.pause(2000); + svgElement = codeCell.$('div#bkrx > svg'); + expect(svgElement.isEnabled()).toBeTruthy(); + }); + + it('Should set width, height and transform attributes to svg', function(){ + expect(Math.round(svgElement.getAttribute('width'))).toEqual(600); + expect(Math.round(svgElement.getAttribute('height'))).toEqual(200); + expect(svgElement.getAttribute('transform')).toMatch('translate'); + }); + + it('svg has 10 circles', function(){ + expect(svgElement.$$('circle').length).toEqual(10); + }); + + it('First and last circles has "class"= "moon"', function(){ + expect(svgElement.$$('circle')[0].getAttribute('class')).toEqual('moon'); + expect(svgElement.$$('circle')[9].getAttribute('class')).toEqual('moon'); + }); + + it('First circle has "r"=5, "cx"=5, "cy"=55', function(){ + var fCircle = svgElement.$$('circle')[0]; + expect(Math.round(fCircle.getAttribute('r'))).toEqual(5); + expect(Math.round(fCircle.getAttribute('cx'))).toEqual(5); + expect(Math.round(fCircle.getAttribute('cy'))).toEqual(55); + }); + + it('Last circle has "r"=50, "cx"=410, "cy"=100', function(){ + var lCircle = svgElement.$$('circle')[9]; + expect(Math.round(lCircle.getAttribute('r'))).toEqual(50); + expect(Math.round(lCircle.getAttribute('cx'))).toEqual(410); + expect(Math.round(lCircle.getAttribute('cy'))).toEqual(100); + }); + + it('First circle has color rgb(100,100,0)', function(){ + expect(svgElement.$$('circle')[0].getCssProperty('fill').value).toEqual('rgb(100,100,0)'); + }); + + it('Last circle has color rgb(100,100,180)', function(){ + expect(svgElement.$$('circle')[9].getCssProperty('fill').value).toEqual('rgb(100,100,180)'); + }); + }); + +}); \ No newline at end of file