mirror of
https://github.com/openMF/community-app.git
synced 2026-02-06 14:11:54 +00:00
Added tests arund the UploadClientIdentifierDocumentController
This commit is contained in:
parent
aacc70ec5e
commit
a52f40c05a
@ -1,6 +1,6 @@
|
||||
(function (module) {
|
||||
mifosX.controllers = _.extend(module, {
|
||||
UploadClientIdentifierDocumentController: function (scope, location, http, routeParams, API_VERSION, $upload, $rootScope) {
|
||||
UploadClientIdentifierDocumentController: function (scope, location, routeParams, API_VERSION, $upload, $rootScope) {
|
||||
scope.clientId = routeParams.clientId;
|
||||
scope.resourceId = routeParams.resourceId;
|
||||
scope.onFileSelect = function ($files) {
|
||||
@ -9,20 +9,20 @@
|
||||
|
||||
scope.submit = function () {
|
||||
$upload.upload({
|
||||
url: $rootScope.hostUrl + API_VERSION + '/client_identifiers/' + scope.resourceId + '/documents',
|
||||
url: $rootScope.hostUrl + API_VERSION + '/client_identifiers/' + scope.resourceId + '/documents',
|
||||
data: scope.formData,
|
||||
file: scope.file
|
||||
}).then(function (data) {
|
||||
// to fix IE not refreshing the model
|
||||
if (!scope.$$phase) {
|
||||
scope.$apply();
|
||||
scope.$apply();
|
||||
}
|
||||
location.path('/viewclient/' + scope.clientId);
|
||||
});
|
||||
};
|
||||
}
|
||||
});
|
||||
mifosX.ng.application.controller('UploadClientIdentifierDocumentController', ['$scope', '$location', '$http', '$routeParams', 'API_VERSION', '$upload', '$rootScope', mifosX.controllers.UploadClientIdentifierDocumentController]).run(function ($log) {
|
||||
mifosX.ng.application.controller('UploadClientIdentifierDocumentController', ['$scope', '$location', '$routeParams', 'API_VERSION', '$upload', '$rootScope', mifosX.controllers.UploadClientIdentifierDocumentController]).run(function ($log) {
|
||||
$log.info("UploadClientIdentifierDocumentController initialized");
|
||||
});
|
||||
}(mifosX.controllers || {}));
|
||||
}(mifosX.controllers || {}));
|
||||
|
||||
@ -0,0 +1,56 @@
|
||||
describe('UploadClientIdentifierDocumentController', function() {
|
||||
var deferedUpload = undefined;
|
||||
|
||||
beforeEach(inject(function($rootScope, $q) {
|
||||
this.scope = $rootScope.$new();
|
||||
this.location = jasmine.createSpyObj('location', ['path']);
|
||||
this.routeParams = {clientId: 'clientId', resourceId: 'resourceId'};
|
||||
this.API_VERSION = 'api_version';
|
||||
this.upload = {
|
||||
upload: jasmine.createSpy().andCallFake(function(){
|
||||
deferedUpload = $q.defer();
|
||||
return deferedUpload.promise;
|
||||
})
|
||||
}
|
||||
this.$rootScope = $rootScope;
|
||||
this.controller = new mifosX.controllers.UploadClientIdentifierDocumentController(
|
||||
this.scope,
|
||||
this.location,
|
||||
this.routeParams,
|
||||
this.API_VERSION,
|
||||
this.upload,
|
||||
this.$rootScope
|
||||
);
|
||||
}));
|
||||
|
||||
it('should put the select file in the scope', function(){
|
||||
var file = {name: 'some file'}
|
||||
this.scope.onFileSelect ([file]);
|
||||
expect(this.scope.file).toBe(file);
|
||||
});
|
||||
|
||||
describe('on submit', function(){
|
||||
var url;
|
||||
beforeEach(function(){
|
||||
url = this.$rootScope.hostUrl + this.API_VERSION + '/client_identifiers/' + this.routeParams.resourceId + '/documents';
|
||||
this.scope.file = {name: 'some file'}
|
||||
this.scope.formData = 'formData';
|
||||
});
|
||||
|
||||
it('should call the upload service', function(){
|
||||
this.scope.submit();
|
||||
expect(this.upload.upload).toHaveBeenCalledWith({
|
||||
url: url,
|
||||
data: this.scope.formData,
|
||||
file: this.scope.file,
|
||||
});
|
||||
});
|
||||
|
||||
it('should change the location after file has been uploaded', function(){
|
||||
this.scope.submit();
|
||||
deferedUpload.resolve('data');
|
||||
this.scope.$digest();
|
||||
expect(this.location.path).toHaveBeenCalledWith('/viewclient/' + this.routeParams.clientId);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user