Skip to content

Commit

Permalink
Merge 73f96e6 into 6ba5f6c
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed Jun 8, 2017
2 parents 6ba5f6c + 73f96e6 commit 235ce4c
Show file tree
Hide file tree
Showing 7 changed files with 454 additions and 536 deletions.
54 changes: 54 additions & 0 deletions doc/docs/reference/javascript/test_helper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
## The Test Helper Service

Opal provides a utility to help you test javascript unit tests.

To bring it in, import the module and inject the service.

``` js

var testHelper;

beforeEach(function(){
module('opal.controllers');
inject(function($injector){
testHelper = $injector.get('testHelper');
});
});
```

The helper has the following functions.

`newEpisode` provides a new episode. It needs to passed in rootScope as as part
of getting a new episode we update the rootSchema to have the schema
information about subrecords.

`getEpisodeData` provides the raw data as pull in from the episode api.


##### Data Loaders

`getRecordLoader` provides a mocked up version of the recordloader that
behaves like the normal recordloader. It comes with the `load` function
already spied on.

`getRecordLoaderData` provides example raw data as pulled from `/api/v0.1/record/`


`getMetaDataLoader` provides a mocked up version of the Metadata that
behaves like the normal Metadata. It comes with the `load` function
already spied on.

`getMetaDataLoader` provides example raw data as pulled from `/api/v0.1/metadata/`


`getReferenceDataLoader` provides a mocked up version of the Referencedata that
behaves like the normal Referencedata. It comes with the `load` function
already spied on.

`getReferenceData` provides example raw data as pulled from `/api/v0.1/referencedata/`

`getUserProfileLoader` provides a mocked up version of the UserProfile that
behaves like the normal UserProfile. It comes with the `load` function
already spied on.

`getUserProfile` provides example raw data as pulled from `/api/v0.1/userprofile/`
28 changes: 5 additions & 23 deletions opal/static/js/test/add_episode.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,8 @@ describe('AddEpisodeCtrl', function (){
"use strict";

var $scope, $httpBackend, $rootScope;
var Schema
var Schema, testHelper;
var modalInstance;
var fields = {
'demographics': {
name: "demographics",
single: true,
fields: [
{name: 'name', type: 'string'},
{name: 'date_of_birth', type: 'date'},
{name: 'created', type: 'date_time'},
],
},
"diagnosis": {
name: "diagnosis",
single: false,
sort: 'date_of_diagnosis',
fields: [
{name: 'date_of_diagnosis', type: 'date'},
{name: 'condition', type: 'string', default: 'flu'},
{name: 'provisional', type: 'boolean'},
]
}
};

var referencedata = {
dogs: ['Poodle', 'Dalmation'],
Expand All @@ -37,6 +16,8 @@ describe('AddEpisodeCtrl', function (){

beforeEach(function(){
module('opal');
module('opalTest');

var $controller, $modal;
$scope = {};

Expand All @@ -46,8 +27,9 @@ describe('AddEpisodeCtrl', function (){
$httpBackend = $injector.get('$httpBackend');
Schema = $injector.get('Schema');
$rootScope = $injector.get('$rootScope');
testHelper = $injector.get('testHelper');
});
$rootScope.fields = fields;
$rootScope.fields = testHelper.getRecordLoaderData();

// var schema = new Schema(columns.default);
modalInstance = $modal.open({template: 'Notatemplate'});
Expand Down
148 changes: 19 additions & 129 deletions opal/static/js/test/edit_item.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,128 +2,17 @@ describe('EditItemCtrl', function (){
"use strict";

var $scope, $timeout, $modal, $httpBackend;
var item, Item, existingEpisode;
var item, Item, existingEpisode, testHelper;
var dialog, Episode, episode, ngProgressLite, $q, $rootScope;
var Schema, $controller, controller, fakeModalInstance;
var $analytics;

var referencedata = {
dogs: ['Poodle', 'Dalmation'],
hats: ['Bowler', 'Top', 'Sun'],
micro_test_c_difficile: [
"C diff", "Clostridium difficile"
],
micro_test_stool_parasitology_pcr: [
"Stool Parasitology PCR"
],
micro_test_defaults: {
micro_test_c_difficile: {
c_difficile_antigen: "pending",
c_difficile_toxin: "pending"
}
},
toLookuplists: function(){return {}}
};
var metadata = {
tag_hierarchy :{'tropical': []},
micro_test_defaults: {
micro_test_c_difficile: {
c_difficile_antigen: "pending",
c_difficile_toxin: "pending"
}
}
};

var episodeData = {
id: 123,
active: true,
category_name: "Inpatient",
prev_episodes: [],
next_episodes: [],
demographics: [{
id: 101,
patient_id: 99,
name: 'John Smith',
date_of_birth: '1980-07-31'
}],
tagging: [{'mine': true, 'tropical': true}],
location: [{
category: 'Inepisode',
hospital: 'UCH',
ward: 'T10',
bed: '15',
date_of_admission: '2013-08-01',
}],
diagnosis: [{
id: 102,
condition: 'Dengue',
provisional: true,
}, {
id: 103,
condition: 'Malaria',
provisional: false,
}]
};

var columns = {
"default": [
{
name: 'demographics',
single: true,
fields: [
{name: 'name', type: 'string'},
{name: 'date_of_birth', type: 'date'},
]},
{
name: 'location',
single: true,
fields: [
{name: 'category', type: 'string'},
{name: 'hospital', type: 'string'},
{name: 'ward', type: 'string'},
{name: 'bed', type: 'string'},
{name: 'date_of_admission', type: 'date'},
{name: 'tags', type: 'list'},
]},
{
name: 'diagnosis',
single: false,
fields: [
{name: 'condition', type: 'string'},
{name: 'provisional', type: 'boolean'},
]},
{
name: 'investigation',
single: false,
fields: [
{name: 'result', type: 'string'},
]
},
{
name: 'microbiology_test',
single: false,
fields: [
{name: 'result', type: 'string'},
{name: 'consistency_token', type: 'string'},
{name: 'test', type: 'string'},
{name: 'c_difficile_toxin', type: 'string'}
]
}
]
};
var $controller, controller, fakeModalInstance;
var $analytics, metadataCopy, profile, referencedata;

var profile = {
readonly : false,
can_extract: true,
can_see_pid: function(){return true; }
};

beforeEach(module('opal.controllers'));
beforeEach(function(){
module('opal.controllers');
module('opalTest');
});

beforeEach(function(){
module(function($provide) {
$provide.value('UserProfile', {load: function(){ return profile; }});
});
$analytics = jasmine.createSpyObj(["eventTrack"]);

inject(function($injector){
Expand All @@ -135,19 +24,20 @@ describe('EditItemCtrl', function (){
$timeout = $injector.get('$timeout');
$modal = $injector.get('$modal');
ngProgressLite = $injector.get('ngProgressLite');
Schema = $injector.get('Schema');
$rootScope = $injector.get('$rootScope');
$modal = $injector.get('$modal');
testHelper = $injector.get('testHelper');
});

$rootScope.fields = columns.default;
episode = testHelper.newEpisode($rootScope);
metadataCopy = testHelper.getMetaData();
profile = testHelper.getUserProfile();
referencedata = testHelper.getReferenceData();
$scope = $rootScope.$new();
var schema = new Schema(columns.default);
episode = new Episode(episodeData);
item = new Item(
{columnName: 'investigation'},
episode,
columns['default'][3]
$rootScope.fields.investigation
);

fakeModalInstance = {
Expand All @@ -161,7 +51,7 @@ describe('EditItemCtrl', function (){
$timeout : $timeout,
$modalInstance: fakeModalInstance,
item : item,
metadata : metadata,
metadata : metadataCopy,
profile : profile,
episode : episode,
ngProgressLite: ngProgressLite,
Expand All @@ -179,7 +69,7 @@ describe('EditItemCtrl', function (){

describe('scope setup', function(){
it('Should hoist metadata onto the scope', function () {
expect($scope.metadata).toBe(metadata);
expect($scope.metadata).toBe(metadataCopy);
});

it('should track analytics data', function(){
Expand Down Expand Up @@ -303,7 +193,7 @@ describe('EditItemCtrl', function (){

describe('testType', function(){
beforeEach(function(){
existingEpisode = new Episode(angular.copy(episodeData));
existingEpisode = new Episode(testHelper.getEpisodeData());

// when we prepopulate we should not remove the consistency_token
existingEpisode.microbiology_test = [{
Expand All @@ -314,7 +204,7 @@ describe('EditItemCtrl', function (){
item = new Item(
existingEpisode.microbiology_test[0],
existingEpisode,
columns['default'][4]
$rootScope.fields.microbiology_test
);

$scope = $rootScope.$new();
Expand All @@ -323,7 +213,7 @@ describe('EditItemCtrl', function (){
$timeout : $timeout,
$modalInstance: fakeModalInstance,
item : item,
metadata : metadata,
metadata : metadataCopy,
profile : profile,
episode : existingEpisode,
ngProgressLite: ngProgressLite,
Expand All @@ -343,7 +233,7 @@ describe('EditItemCtrl', function (){
$timeout : $timeout,
$modalInstance: fakeModalInstance,
item : item,
metadata : metadata,
metadata : metadataCopy,
profile : profile,
episode : existingEpisode,
ngProgressLite: ngProgressLite,
Expand Down
Loading

0 comments on commit 235ce4c

Please sign in to comment.