Commit c1584773 authored by Marek Ostaszewski's avatar Marek Ostaszewski

Merge branch 'tests' into 'master'

Tests

See merge request !10
parents c4290e0c c579f4c0
Pipeline #24435 passed with stages
in 2 minutes and 33 seconds
FROM docker-test
ADD . /plugin
WORKDIR /plugin
RUN /bin/bash tests/docker-init.sh
......@@ -2,6 +2,7 @@ require('../css/styles.css');
const pluginName = 'GSEA';
const pluginVersion = '0.9.1';
const containerName = pluginName + '-container';
const globals = {
models: {},
......@@ -56,6 +57,7 @@ const register = function (_minerva) {
calculatePathways().then(function(){
container.find('.gsea-pw-loading').hide();
initMainPageStructure(container);
pluginContainer.find(`.${containerName}`).data("minervaProxy", minervaProxy);
});
});
};
......@@ -112,7 +114,7 @@ function deHighlightAll() {
function getContainerClass() {
return pluginName + '-container';
return containerName;
}
function initMainContainer(){
......@@ -135,7 +137,7 @@ function initMainContainer(){
function initMainPageStructure() {
const container = $('<div class="' + pluginName + '-container"></div>').appendTo(pluginContainer);
const container = $("." + getContainerClass());//.appendTo(pluginContainer);
container.append(`
<div class="panel card panel-primary border-primary panel-events">
<div class="panel-heading card-header bg-primary text-light">Gene Set Enrichment Analysis</div>
......@@ -304,11 +306,11 @@ function calculateGSEA() {
var N = globals.allProteinRnaGene.length;
var n = ovHgncNames.size;
// console.log('pw', pwName);
// console.log('m', m);
// console.log('k', k);
// console.log('N', N);
// console.log('n', n);
console.log('pw', pwName);
console.log('m', m);
console.log('k', k);
console.log('N', N);
console.log('n', n);
if (k > 0) {
//var px = (kcomb(m,k)*kcomb(N-m,n-k))/kcomb(N,n);
......
#!/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 = 'GSEA';
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) {
return JSON.parse(pluginsResponse.responseText).filter(plugin => plugin.name === pluginName && plugin.isPublic)[0].hash;
});
}
describe('GSEA plugin', async function() {
//Some functions can take a lot of time as they need, for isntance, start MINERVA interface
this.timeout(20000);
let driver;
let minervaProxy;
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 countHighlighted(){
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}`)),10000);
minervaProxy = await driver.executeScript(`return $('.${minervaProxyContainerClass}').data('minervaProxy')`);
await driver.executeScript(function () {
$('td:contains("Sorted-by-species")').parent().find("input").click();
});
await wait(500);
});
describe("show enriched pathways", function () {
before(async function () {
await driver.executeScript(function () {
$('.gsea-buttons .btn-calc').click();
});
await driver.wait(until.elementLocated(By.css(`.gsea-results button`)),5000);
});
let elPanelTitle;
it('should have one record in the table being the main map', async function () {
const panels = await driver.findElements(By.css('.gsea-pw-results-panel'));
assert.equal(panels.length, 1);
elPanelTitle = panels[0].findElement(By.css('.panel-title'));
assert.equal(await elPanelTitle.getText(), 'Main map');
});
describe("clicking reset", function () {
before(async function () {
await driver.executeScript(function () {
$('.gsea-buttons .btn-reset').click();
});
await driver.wait(until.stalenessOf(elPanelTitle),1000);
});
it("should reset results", async function () {
const cnt = await driver.executeScript(function () {
return $('.gsea-results').children().length;
});
assert.equal(cnt, 0);
})
})
});
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