Skip to content

Commit

Permalink
lazy load
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed May 18, 2017
1 parent 9285bc9 commit 6882240
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 132 deletions.
5 changes: 2 additions & 3 deletions opal/core/search/static/js/test/extract.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,7 @@ describe('ExtractCtrl', function(){
referencedata: referencedata
});

$httpBackend.expectGET('/api/v0.1/userprofile/').respond({roles: {default: []}});
$scope.$apply();
$httpBackend.flush();
});

describe('set up', function(){
Expand Down Expand Up @@ -596,6 +594,7 @@ describe('ExtractCtrl', function(){
describe('Search', function(){

it('should ask the server for results', function(){

$httpBackend.expectPOST("/search/extract/").respond({
page_number: 1,
total_pages: 1,
Expand All @@ -604,7 +603,7 @@ describe('ExtractCtrl', function(){
{categories: []}
]
});
// $httpBackend.expectGET('/api/v0.1/userprofile/').respond({roles: {default: []}});
$httpBackend.expectGET('/api/v0.1/userprofile/').respond({roles: {default: []}});
$scope.criteria[0] = {
combine : "and",
column : "symptoms",
Expand Down
30 changes: 10 additions & 20 deletions opal/core/search/static/js/test/search.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ describe('SearchCtrl', function (){
PatientSummary : PatientSummary
});

$httpBackend.expectGET('/api/v0.1/userprofile/').respond({roles: {default: []}});

});});

Expand All @@ -77,31 +76,28 @@ describe('SearchCtrl', function (){
});

describe('getQueryParam()', function() {

it('should return autocomplete if there is no searchTerm', function() {
$httpBackend.expectGET('/search/simple/?query=jane').respond(
{object_list: [{categories: []}]}
);
expect($scope.query.searchTerm.length).toBe(0);
$scope.query.autocompleteSearchTerm = 'jane';
expect($scope.getQueryParam()).toEqual('jane');
$httpBackend.flush();
});

it('should return autocomplete if there is no searchTerm', function() {
$httpBackend.expectGET('/search/simple/?query=jane').respond(
{object_list: [{categories: []}]}
);
$httpBackend.expectGET('/api/v0.1/userprofile/').respond({roles: {default: []}});
expect($scope.query.searchTerm.length).toBe(0);
$scope.query.autocompleteSearchTerm = 'jane';
expect($scope.getQueryParam()).toEqual('jane');
$httpBackend.flush();
});
});

describe('setters', function() {

it('should set state', function() {
$scope.disableShortcuts();
expect($scope.state).toEqual('search');
$httpBackend.flush();
});

it('should set state', function() {
$scope.enableShortcuts();
expect($scope.state).toEqual('normal');
$httpBackend.flush();
});

});
Expand All @@ -112,7 +108,6 @@ describe('SearchCtrl', function (){
$scope.selected({link: '/#/foo/bar'});
expect($scope.query.autocompleteSearchTerm).toEqual("");
expect($window.location.href).toEqual('/#/foo/bar');
$httpBackend.flush();
});

});
Expand Down Expand Up @@ -141,7 +136,6 @@ describe('SearchCtrl', function (){
$scope.search();
var expectedUrl = "/#/search?query=Bond";
expect(locationDetails.href).toEqual(expectedUrl);
$httpBackend.flush();
});

it('should take page numbers into account', function() {
Expand All @@ -151,7 +145,6 @@ describe('SearchCtrl', function (){
$scope.search(3);
var expectedUrl = "/#/search?page_number=3&query=Bond";
expect(locationDetails.href).toEqual(expectedUrl);
$httpBackend.flush();
});

it("should update the url if on the search page", function(){
Expand All @@ -164,7 +157,6 @@ describe('SearchCtrl', function (){
};
expect(location.search()).toEqual(expectedSearch);
expect(locationDetails.href).toEqual("unchanged");
$httpBackend.flush();
});
});

Expand Down Expand Up @@ -193,7 +185,6 @@ describe('SearchCtrl', function (){
}
}
expect($scope.getEpisodeID(patient)).toEqual('42');
$httpBackend.flush();
});

});
Expand All @@ -202,7 +193,6 @@ describe('SearchCtrl', function (){
it('Should call location.path()', function () {
$scope.jumpToEpisode({active_episode_id: 555});
expect(location.path).toHaveBeenCalledWith('/episode/555');
$httpBackend.flush();
});
});

Expand Down
8 changes: 1 addition & 7 deletions opal/static/js/opal/services/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,8 @@ angular.module('opal.services').factory('Metadata', function($q, $http, $window,

return deferred.promise;
};
var promise = load();

return {
load: function(){ return promise; },
then: function(fn){
// TODO: 0.9.0
$log.warn("This API is being deprecated and will be removed in 0.9.0. Please use Metadata.load()");
promise.then(function(result){ fn(result); });
}
load: load
};
});
9 changes: 1 addition & 8 deletions opal/static/js/opal/services/referencedata.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,7 @@ angular.module('opal.services').factory('Referencedata', function($q, $http, $wi
return deferred.promise;
};

var promise = load();

return {
load: function(){ return promise; },
then: function(fn){
// TODO: 0.9.0
$log.warn("This API is being deprecated and will be removed in 0.9.0. Please use Referencedata.load()");
promise.then(function(result){ fn(result); });
}
load: load
};
});
9 changes: 1 addition & 8 deletions opal/static/js/opal/services/user_profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,7 @@ angular.module('opal.services')
return deferred.promise;
};

var promise = load();

return {
load: function(){ return promise; },
then: function(fn){
// TODO: 0.9.0
$log.warn("This API is being deprecated and will be removed in 0.9.0. Please use UserProfile.load()");
promise.then(function(result){ fn(result); });
}
load: load
};
});
5 changes: 0 additions & 5 deletions opal/static/js/test/add_episode.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ describe('AddEpisodeCtrl', function (){
demographics : {},
tags : {tag: 'id', subtag: 'id_inpatients'}
});

$httpBackend.expectGET('/api/v0.1/userprofile/').respond({});
$scope.$apply();
$httpBackend.flush();

});

describe('save()', function(){
Expand Down
2 changes: 0 additions & 2 deletions opal/static/js/test/copy.to.category.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ describe('CopyToCategoryCtrl', function(){
describe('import_existing()', function(){

it('should close the modal', function(){
$httpBackend.expectGET('/api/v0.1/userprofile/').respond({});
$httpBackend.expectPOST('/episode/2/actions/copyto/newcategory').respond({
demographics: [{patient_id: 2}]
});
Expand All @@ -68,7 +67,6 @@ describe('CopyToCategoryCtrl', function(){
});

it('should close the modal even if we failed', function() {
$httpBackend.expectGET('/api/v0.1/userprofile/').respond({});
$httpBackend.expectPOST('/episode/2/actions/copyto/newcategory')
.respond(500, '');

Expand Down
6 changes: 0 additions & 6 deletions opal/static/js/test/discharge.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,9 @@ describe('DischargeEpisodeCtrl', function(){
});
}
mkcontroller(tags)
$httpBackend.expectGET('/api/v0.1/userprofile/').respond({});
});

describe('Set up the controller', function(){

afterEach(function(){
$httpBackend.flush();
})

it('should have the current and new categories', function() {
expect($scope.editing.category).toEqual('Discharged');
});
Expand Down
10 changes: 2 additions & 8 deletions opal/static/js/test/edit_teams.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ describe('EditTeamsCtrl', function(){
beforeEach(function(){
module('opal.controllers');
UserProfile = {
then: function(fn){
fn('someProfile');
},
load: function(){
return {
then: function(fn){
Expand Down Expand Up @@ -169,20 +166,17 @@ describe('EditTeamsCtrl', function(){
});

it('should fetch the options', function() {
$httpBackend.expectGET('/api/v0.1/userprofile/').respond({});
$rootScope.$apply();
$httpBackend.flush();
expect($scope.profile).toBe("someProfile");
expect(UserProfile.load).toHaveBeenCalled();
});
});

describe('save()', function() {

it('should save', function() {
$httpBackend.expectGET('/api/v0.1/userprofile/').respond({});
spyOn(modalInstance, 'close');
$scope.save('close');
$rootScope.$apply();
$httpBackend.flush();
expect(modalInstance.close).toHaveBeenCalledWith('close');
});

Expand Down
8 changes: 3 additions & 5 deletions opal/static/js/test/episode_loader.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ describe('episodeLoader', function() {
$httpBackend = $injector.get('$httpBackend');
$window = $injector.get('$window');
});

$httpBackend.expectGET('/api/v0.1/userprofile/').respond({})
$httpBackend.expectGET('/api/v0.1/record/').respond({})
})
});


describe('fetch episodes', function() {

it('should hit the api', function() {
$route.current = { params: { id: 123 } }

$httpBackend.expectGET('/api/v0.1/record/').respond({});
$httpBackend.expectGET('/api/v0.1/episode/123/').respond(episodeData);
var promise = episodeLoader();
$rootScope.$apply();
Expand All @@ -43,6 +40,7 @@ describe('episodeLoader', function() {
$route.current = { params: { id: 123 } }
spyOn($window, 'alert');

$httpBackend.expectGET('/api/v0.1/record/').respond({});
$httpBackend.expectGET('/api/v0.1/episode/123/').respond(500);
var promise = episodeLoader();
$rootScope.$apply();
Expand Down
13 changes: 0 additions & 13 deletions opal/static/js/test/metadata.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@ describe('Metadata', function(){
$httpBackend.verifyNoOutstandingRequest();
});

it('then should call through to load', function(){
spyOn(Metadata, "load").and.callThrough();
var result;
$httpBackend.whenGET('/api/v0.1/metadata/').respond(metadata);
Metadata.then(function(r){ result = r; });
$rootScope.$apply();
$httpBackend.flush();
expect(result.get('foo')).toEqual('bar');
expect($log.warn).toHaveBeenCalledWith(
'This API is being deprecated and will be removed in 0.9.0. Please use Metadata.load()'
);
});

it('should fetch the metadata', function(){
var result

Expand Down
14 changes: 9 additions & 5 deletions opal/static/js/test/patient_loader.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,10 @@ describe('patientLoader', function() {
$rootScope = $injector.get('$rootScope');
});

$httpBackend.expectGET('/api/v0.1/record/').respond({});
$httpBackend.expectGET('/api/v0.1/userprofile/').respond({});

$route.current = { params: { patient_id: '123' } };
});

afterEach(function(){
$rootScope.$apply();
$httpBackend.flush();
$httpBackend.verifyNoOutstandingRequest();
$httpBackend.verifyNoOutstandingExpectation();
});
Expand All @@ -59,25 +54,34 @@ describe('patientLoader', function() {
describe('load patients', function() {
it('should load a patient from route params', function() {
$httpBackend.expectGET('/api/v0.1/patient/123/').respond(response);
$httpBackend.expectGET('/api/v0.1/record/').respond({});
patientLoader().then(function(patient){
expect(patient.demographics[0].first_name).toEqual("Sue");
});
$rootScope.$apply();
$httpBackend.flush();
});

it('should load a patient an argument', function() {
$httpBackend.expectGET('/api/v0.1/patient/124/').respond(response);
$httpBackend.expectGET('/api/v0.1/record/').respond({});
patientLoader("124").then(function(patient){
expect(patient.demographics[0].first_name).toEqual("Sue");
});
$rootScope.$apply();
$httpBackend.flush();
});
});

describe('patient API errors', function() {
it('should alert() the user', function() {
$httpBackend.expectGET('/api/v0.1/patient/123/').respond(500);
$httpBackend.expectGET('/api/v0.1/record/').respond({});
patientLoader().then(function(patient){
expect(mockWindow.alert).toHaveBeenCalledWith('Patient could not be loaded');
});
$rootScope.$apply();
$httpBackend.flush();
});
});

Expand Down
1 change: 0 additions & 1 deletion opal/static/js/test/patientlists.loader.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ describe('PatientListLoaderTest', function(){
$httpBackend = $injector.get('$httpBackend');
});

$httpBackend.expectGET('/api/v0.1/userprofile/').respond({})
$httpBackend.expectGET('/api/v0.1/record/').respond({})
})

Expand Down
14 changes: 0 additions & 14 deletions opal/static/js/test/recordLoader.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ describe('recordLoader', function(){
spyOn($log, "warn");
});

it('then should call through to load', function(){
spyOn(recordLoader, "load").and.callThrough();
var result;
$httpBackend.whenGET('/api/v0.1/record/').respond(recordSchema);
recordLoader.then(function(r){ result = r; });
$rootScope.$apply();
$httpBackend.flush();
expect(result).toEqual(recordSchema);
expect($rootScope.fields).toEqual(recordSchema);
expect($log.warn).toHaveBeenCalledWith(
'This API is being deprecated and will be removed in 0.9.0. Please use recordLoader.load()'
);
});

it('should fetch the record data', function(){
var result;
$httpBackend.whenGET('/api/v0.1/record/').respond(recordSchema);
Expand Down
13 changes: 0 additions & 13 deletions opal/static/js/test/referencedata.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,6 @@ describe('Referencedata', function(){
spyOn($log, "warn");
});

it('then should call through to load', function(){
spyOn(Referencedata, "load").and.callThrough();
var result;
$httpBackend.whenGET('/api/v0.1/referencedata/').respond(referencedata);
Referencedata.then(function(r){ result = r; });
$rootScope.$apply();
$httpBackend.flush();
expect(result.get('foo')).toEqual(['bar']);
expect($log.warn).toHaveBeenCalledWith(
'This API is being deprecated and will be removed in 0.9.0. Please use Referencedata.load()'
);
});

it('should fetch the referencedata', function(){
var result;

Expand Down
Loading

0 comments on commit 6882240

Please sign in to comment.