Commit 3195cc7c authored by David Hoksza's avatar David Hoksza
Browse files

testing whether the table appears

parent 4d894367
Pipeline #24780 passed with stage
in 1 minute and 30 seconds
FROM docker-test
ADD . /plugin
WORKDIR /plugin
RUN /bin/bash tests/docker-init.sh
...@@ -14,8 +14,8 @@ require('../assets/boostrap-table/bootstrap-table.min'); ...@@ -14,8 +14,8 @@ require('../assets/boostrap-table/bootstrap-table.min');
const pluginName = 'adr'; const pluginName = 'adr';
const pluginLabel = 'Drug reactions'; const pluginLabel = 'Drug reactions';
const pluginVersion = '1.0.0'; const pluginVersion = '1.0.0';
const containerName = pluginName + '-container';
const settings = { const settings = {
drugColumnName: 'Drug', drugColumnName: 'Drug',
...@@ -93,6 +93,7 @@ minervaDefine(function (){ ...@@ -93,6 +93,7 @@ minervaDefine(function (){
function initPlugin () { function initPlugin () {
registerListeners(); registerListeners();
const $container = initMainContainer(); const $container = initMainContainer();
$container.data("minervaProxy", minervaProxy);
initDrugBioEntities().then(function(){ initDrugBioEntities().then(function(){
$container.find('.drugs-loading').hide(); $container.find('.drugs-loading').hide();
initMainPageStructure($container); initMainPageStructure($container);
...@@ -126,7 +127,7 @@ function deHighlightAll(){ ...@@ -126,7 +127,7 @@ function deHighlightAll(){
// **************************************************************************** // ****************************************************************************
function getContainerClass() { function getContainerClass() {
return pluginName + '-container'; return containerName;
} }
function initMainContainer(){ function initMainContainer(){
......
#!/bin/bash
rm -r node_modules
npm install
npm run build
mkdir /usr/local/tomcat/webapps/test
cp dist/plugin.js /usr/local/tomcat/webapps/test/
PLUGIN_FILE=plugin.js
PLUGIN_MD5=($(md5sum dist/plugin.js))
/usr/local/tomcat/bin/startup.sh
sleep 15
test 200 = $(curl -X POST -d "login=admin&password=admin" --write-out %{http_code} --silent --output /dev/null -c cookie.txt http://localhost:8080/minerva/api/doLogin)
curl "http://localhost:8080/minerva/api/plugins/" --cookie cookie.txt --data "hash=$PLUGIN_MD5&url=http%3A%2F%2Flocalhost%3A8080%2Ftest%2F$PLUGIN_FILE&name=test&version=0.0.1&isPublic=false"
npm run test
\ No newline at end of file
const {Builder, By, until} = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const assert = require('chai').assert;
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
// Some tests need to access the MINERVA proxy to, e.g., check which elements are highlighted. However, the tests
// do not run in the same scope as the plugin and thus they do not have access to the Proxy. Therefore, the plugin
// exposes the proxy by attaching it as a data attribute to the main div element.
const pluginName = 'adr';
const pluginLabel = 'Drug reactions';
const minervaProxyContainerClass = pluginName + '-container';
const minervaProxyCode = `$('.${minervaProxyContainerClass}').data('minervaProxy')`;
function minervaLogin() {
const xhr = new XMLHttpRequest();
return new Promise(function (resolve, reject) {
xhr.onreadystatechange = function () {
if (xhr.readyState !== 4) return;
if (xhr.status >= 200 && xhr.status < 300) {
resolve(xhr);
} else {
reject({
status: xhr.status,
statusText: xhr.statusText
});
}
};
xhr.open("POST", 'http://localhost:8080/minerva/api/doLogin', false);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("login=admin&password=admin");
});
}
async function getRequest(uri) {
const xhr = new XMLHttpRequest();
return new Promise(function (resolve, reject) {
xhr.onreadystatechange = function () {
if (xhr.readyState !== 4) return;
if (xhr.status >= 200 && xhr.status < 300) {
resolve(xhr);
} else {
reject({
status: xhr.status,
statusText: xhr.statusText
});
}
};
xhr.open("GET", uri);
xhr.send();
});
}
async function getPluginHash(){
return getRequest('http://localhost:8080/minerva/api/plugins/').then(function (pluginsResponse) {
let hashes = JSON.parse(pluginsResponse.responseText).filter(plugin => plugin.name === pluginLabel);
if (hashes.length === 0){
// when tested withing CI there is only one plugin, the current one and it's name is test
hashes = JSON.parse(pluginsResponse.responseText);
}
return hashes[hashes.length -1].hash;
});
}
describe("drug reactions plugin", async function() {
//Some functions can take a lot of time as they need, for isntance, start MINERVA interface
this.timeout(600000);
let driver;
let pluginContainer;
function wait(timeInMs) {
return driver.executeAsyncScript(`
const callback = arguments[arguments.length - 1];
setTimeout(()=>callback(), ${timeInMs})`);
}
function deHighlightAll(){
return driver.executeScript(`minervaProxy = ${minervaProxyCode}; minervaProxy.project.map.getHighlightedBioEntities().then( highlighted => minervaProxy.project.map.hideBioEntity(highlighted) )`);
}
async function getHighlighted(){
return driver.executeAsyncScript(`
var callback = arguments[arguments.length - 1];
${minervaProxyCode}.project.map.getHighlightedBioEntities().then(highlighted => callback(highlighted));
`);
}
before(async function () {
const opts = new chrome.Options().addArguments('--no-sandbox', '--headless', '--remote-debugging-port=9222');
// driver = await new Builder().setChromeOptions(opts).forBrowser('chrome').build();
driver = await new Builder().forBrowser('chrome').build();
await driver.manage().window().maximize();
const loginResponse = await minervaLogin();
const minervaToken = JSON.parse(loginResponse.responseText).token;
await driver.get('http://localhost:8080');
await driver.manage().addCookie({name: 'MINERVA_AUTH_TOKEN', value: minervaToken});
const pluginHash = await getPluginHash();
await driver.get(`http://localhost:8080/minerva/index.xhtml?id=single-map&plugins=${pluginHash}`);
pluginContainer = await driver.wait(until.elementLocated(By.css(`.${minervaProxyContainerClass}`)));
await driver.wait(until.elementLocated(By.css('.adr-table')));
});
it("should have arcalys", async function () {
const aracalyst = await driver.executeScript(function () {
return $('.adr-table td:contains("Arcalyst")');
});
assert.equal(aracalyst.length, 2);
});
it("should highlight entities", function () {
});
after(async function finishWebDriver() {
// await driver.quit();
});
});
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment