Skip to content

Commit

Permalink
Add JS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
annapowellsmith committed Oct 25, 2016
1 parent e116f4e commit 11ad3de
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ Update data

First download raw data from ClinicalTrials.gov (instructions are in the Jupyter notebook). Then run the notebook, toggling `REGENERATE_SUMMARY` and `REGENERATE_PUBMED_LINKS` to regenerate the data from scratch. Running this notebook will automatically update the data used in the app.

To rebuild the JavaScript, run `npm run watch` (development) and `npm run build` (production).

Run tests
---------

Test the data utility functions, run in the `data` directory: `nosetests tests/test_utils.py`
Test the JavaScript: TBA.
Toest the data utility functions, run in the `data` directory: `nosetests tests/test_utils.py`. To test the JavaScript: `npm run test`.
3 changes: 2 additions & 1 deletion app/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
},
"devDependencies": {
"browserify": "^9.0.8",
"mocha": "^2.2.5",
"chai": "^3.5.0",
"mocha": "^2.5.3",
"uglifyjs": "^2.4.10",
"watchify": "^3.2.1"
}
Expand Down
2 changes: 2 additions & 0 deletions app/js/test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--reporter dot
--ui bdd
45 changes: 45 additions & 0 deletions app/js/test/test_utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var expect = require('chai').expect;
var utils = require('../utils');

describe('Utils', function () {
describe('#getChartDescription', function () {
it('should construct description for a sponsor', function () {
var data = {
overdue: 4,
rate: 0.4,
total: 10
}, name = 'Sanofi', orgName = 'sanofi';
var description = utils.getChartDescription(data, name, orgName);
var expected = "Since Jan 2006, <strong>Sanofi</strong> completed" +
" 10 eligible trials and <strong><span style='color: #ff4800'>" +
"hasn't published results for 4 trials</span></strong>. That " +
"means 40.0% of its trials are missing results. See " +
"<a target='_blank' href='https://clinicaltrials.gov/ct2/" +
"results/displayOpt?flds=a&flds=b&flds=f&flds=c&flds=g&flds=s" +
"&flds=u&submit_fld_opt=on&recr=Completed&type=Intr&lead=Sanofi" +
"&lead_ex=Y&show_flds=Y'>all its completed trials on " +
"ClinicalTrials.gov&nbsp;<span style='font-size: 60%' " +
"class='glyphicon glyphicon-new-window'></span></a>.";
expect(description).to.equal(expected);
});

it('should construct description for all sponsors', function () {
var data = {
overdue: 40,
rate: 0.4,
total: 100
}, name = 'all major trial sponsors', orgName = '';
var description = utils.getChartDescription(data, name, orgName);
var expected = "Since Jan 2006, <strong>all major trial " +
"sponsors</strong> completed" +
" 100 eligible trials and <strong><span style='color: #ff4800'> " +
"haven't published results for 40 trials</span></strong>. That " +
"means 40.0% of their trials are missing results. ";
expect(description).to.equal(expected);
});
});
// describe('#reshapeData', function () {
// it('should reshape our data', function () {
// });
// });
});
4 changes: 2 additions & 2 deletions app/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ var getChartDescription = function (data, name, orgName) {
title += data.overdue.toLocaleString() + ' trial';
title += (data.overdue === 1) ? '' : 's';
title += '</span></strong>. ';
title += 'That means ' + (data.rate *100).toFixed(1) + '% of ';
title += (orgName === '') ? ' their ' : ' its ';
title += 'That means ' + (data.rate * 100).toFixed(1) + '% of ';
title += (orgName === '') ? 'their ' : 'its ';
title += 'trials are missing results. ';
url = 'https://clinicaltrials.gov/ct2/results/displayOpt?';
url += 'flds=a&flds=b&flds=f&flds=c&flds=g&flds=s&flds=u&submit_fld_opt=on';
Expand Down

0 comments on commit 11ad3de

Please sign in to comment.