Skip to content

Commit

Permalink
Merge e7be169 into 70e49fb
Browse files Browse the repository at this point in the history
  • Loading branch information
danvk committed Mar 19, 2015
2 parents 70e49fb + e7be169 commit 801b8b5
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
86 changes: 86 additions & 0 deletions test/components-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* @flow */
'use strict';

var chai = require('chai');
var expect = chai.expect;

var Q = require('q');

var React = require('react/addons'),
TwoBit = require('../src/TwoBit'),
BigBed = require('../src/BigBed'),
Root = require('../src/Root'),
createTwoBitDataSource = require('../src/TwoBitDataSource'),
createBigBedDataSource = require('../src/BigBedDataSource');


var WAIT_FOR_POLL_INTERVAL_MS = 100;
function waitFor(predFn, timeoutMs) {
var def = Q.defer();

var checkTimeoutId = null;

var timeoutId = window.setTimeout(() => {
if (checkTimeoutId) window.clearTimeout(checkTimeoutId);
def.reject('Timed out');
}, timeoutMs);

var check = function() {
if (def.promise.isRejected()) return;
if (predFn()) {
def.resolve();
window.clearTimeout(timeoutId);
} else {
checkTimeoutId = window.setTimeout(check, WAIT_FOR_POLL_INTERVAL_MS);
}
};
checkTimeoutId = window.setTimeout(check, 0);

return def.promise;
}


describe('Root component', function() {
// var genome = new TwoBit('/test/data/test.2bit');
var genome = new TwoBit('http://www.biodalliance.org/datasets/hg19.2bit');
var dataSource = createTwoBitDataSource(genome);

var ensembl = new BigBed('/test/data/ensembl.chr17.bb');
var ensemblDataSource = createBigBedDataSource(ensembl);

var testDiv = document.getElementById('testdiv');

afterEach(function() {
testDiv.innerHTML = ''; // avoid pollution between tests.
});

it('should render reference genome and genes', function(done) {
this.timeout(5000);

var div = document.createElement('div');
div.setAttribute('style', 'width: 800px; height: 200px;');
testDiv.appendChild(div);

React.render(<Root referenceSource={dataSource}
geneSource={ensemblDataSource} />, div);

var ready = (() =>
div.querySelectorAll('.basepair').length > 0 &&
div.querySelectorAll('.gene').length > 0
);

waitFor(ready, 5000)
.then(() => {
var basepairs = div.querySelectorAll('.basepair');
expect(basepairs).to.have.length.at.least(10);
var geneNames = div.querySelectorAll('.gene text');
expect(geneNames.length).to.equal(1);
expect(geneNames[0].textContent).to.equal('TP53');

// Note: there are 11 exons, but two are split into coding/non-coding
expect(div.querySelectorAll('.gene .exon').length).to.equal(13);
done();
})
.done();
});
});
4 changes: 1 addition & 3 deletions test/coverage.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
</head>
<body>
<div id="testdiv"></div>
<div id="mocha"></div>

<!-- Polyfills for PhantomJS -->
Expand All @@ -15,9 +16,6 @@
<!-- Mocha -->
<script src="../node_modules/mocha/mocha.js"></script>
<script>mocha.setup('bdd')</script>

<!--<script src="../build/cov/tests-debug.js"></script>-->
<!--<script src="../build/tests-debug.js"></script>-->
<script src="../build/cov/tests.js"></script>

<script>
Expand Down
1 change: 1 addition & 0 deletions test/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
</head>
<body>
<div id="testdiv"></div>
<div id="mocha"></div>

<!-- Polyfills for PhantomJS -->
Expand Down

0 comments on commit 801b8b5

Please sign in to comment.