Started testing CP Details
diff --git a/xos/core/xoslib/karma.conf.js b/xos/core/xoslib/karma.conf.js
index 0d0b15b..8fc9d11 100644
--- a/xos/core/xoslib/karma.conf.js
+++ b/xos/core/xoslib/karma.conf.js
@@ -53,7 +53,7 @@
exclude: [
// '**/xos-utils.test.js', //skip this test, useful in dev, comment before commit
// '**/xos-backbone.test.js',
- // '**/xoslib/**/*.js'
+ '**/xoslib/**/*.js'
],
diff --git a/xos/core/xoslib/spec/views/contentprovider.test.js b/xos/core/xoslib/spec/views/contentprovider.test.js
index 4f19695..ca9b727 100644
--- a/xos/core/xoslib/spec/views/contentprovider.test.js
+++ b/xos/core/xoslib/spec/views/contentprovider.test.js
@@ -10,12 +10,23 @@
// preload Html Templates with ng-html2js
beforeEach(module('templates'));
+ beforeEach(function() {
+ module(function($provide) {
+ $provide.provider('$routeParams', function() {
+ this.$get = function() {
+ return {id: 1};
+ };
+ });
+ });
+ });
+
beforeEach(inject(function(_$location_, $httpBackend) {
spyOn(_$location_, 'url');
mockLocation = _$location_;
httpBackend = $httpBackend;
// Setting up mock request
- $httpBackend.whenGET('/hpcapi/contentproviders/').respond(CPmock.list);
+ $httpBackend.whenGET('/hpcapi/contentproviders/').respond(CPmock.CPlist);
+ $httpBackend.whenGET('/hpcapi/serviceproviders/').respond(CPmock.SPlist);
$httpBackend.whenDELETE('/hpcapi/contentproviders/1/').respond();
}));
@@ -58,4 +69,35 @@
expect(isolatedScope.contentProviderList.length).toBe(1);
});
});
+
+ describe('the contentProviderDetail directive', () => {
+ describe('when an id is set in the route', () => {
+
+ beforeEach(inject(function($compile, $rootScope, ContentProvider) {
+ scope = $rootScope.$new();
+
+ httpBackend.expectGET('/hpcapi/contentproviders/1/').respond(CPmock.CPlist[0]);
+ httpBackend.whenPUT('/hpcapi/contentproviders/1/').respond({name: 'done'});
+
+ spyOn(ContentProvider, 'save').and.callThrough();
+
+ element = angular.element('<content-provider-detail></content-provider-detail>');
+ $compile(element)(scope);
+ scope.$digest();
+ httpBackend.flush();
+ isolatedScope = element.isolateScope().vm;
+ }));
+
+ it('should request the correct contentProvider', () => {
+ expect(isolatedScope.cp.name).toEqual(CPmock.CPlist[0].name);
+ });
+
+ it('should update a contentProvider', () => {
+ isolatedScope.cp.name = 'new name';
+ isolatedScope.saveContentProvider(isolatedScope.cp);
+ httpBackend.flush();
+ expect(isolatedScope.cp.name).toEqual('done');
+ });
+ });
+ });
});
diff --git a/xos/core/xoslib/spec/views/mocks/contentProvider.mock.js b/xos/core/xoslib/spec/views/mocks/contentProvider.mock.js
index edc8233..97ee31b 100644
--- a/xos/core/xoslib/spec/views/mocks/contentProvider.mock.js
+++ b/xos/core/xoslib/spec/views/mocks/contentProvider.mock.js
@@ -1,7 +1,7 @@
/* eslint-disable key-spacing */
var CPmock = {
- list: [
+ CPlist: [
{
'humanReadableName':'on_lab_content',
'validators':{
@@ -140,5 +140,76 @@
'description':'',
'serviceProvider':'http://0.0.0.0:9000/hpcapi/serviceproviders/1/'
}
+ ],
+ SPlist: [
+ {
+ 'humanReadableName':'main_service_provider',
+ 'validators':{
+ 'updated':[
+
+ ],
+ 'policed':[
+
+ ],
+ 'name':[
+ 'notBlank'
+ ],
+ 'created':[
+
+ ],
+ 'deleted':[
+
+ ],
+ 'hpcService':[
+ 'notBlank'
+ ],
+ 'description':[
+
+ ],
+ 'enabled':[
+
+ ],
+ 'service_provider_id':[
+
+ ],
+ 'lazy_blocked':[
+
+ ],
+ 'backend_register':[
+ 'notBlank'
+ ],
+ 'write_protect':[
+
+ ],
+ 'backend_status':[
+ 'notBlank'
+ ],
+ 'id':[
+
+ ],
+ 'no_sync':[
+
+ ],
+ 'enacted':[
+
+ ]
+ },
+ 'id':1,
+ 'created':'2015-10-22T19:33:55.048Z',
+ 'updated':'2015-10-22T19:33:55.048Z',
+ 'enacted':null,
+ 'policed':null,
+ 'backend_register':'{}',
+ 'backend_status':'0 - Provisioning in progress',
+ 'deleted':false,
+ 'write_protect':false,
+ 'lazy_blocked':false,
+ 'no_sync':false,
+ 'hpcService':'http://0.0.0.0:9000/hpcapi/hpcservices/1/',
+ 'service_provider_id':null,
+ 'name':'main_service_provider',
+ 'description':null,
+ 'enabled':true
+ }
]
};
\ No newline at end of file
diff --git a/xos/core/xoslib/static/js/xosContentProvider.js b/xos/core/xoslib/static/js/xosContentProvider.js
index 8b2169a..dfac97b 100644
--- a/xos/core/xoslib/static/js/xosContentProvider.js
+++ b/xos/core/xoslib/static/js/xosContentProvider.js
@@ -84,7 +84,6 @@
this.deleteCp = function(id) {
ContentProvider.delete({id: id}).$promise
.then(function() {
- console.log('deleted');
$location.url('/');
});
};
@@ -121,6 +120,7 @@
return {
restrict: 'E',
controllerAs: 'vm',
+ scope: {},
templateUrl: '../../static/templates/contentProvider/cp_detail.html',
controller: function() {
this.pageName = 'detail';
@@ -165,6 +165,7 @@
}
p.then(function(res) {
+ console.log('save done', res);
_this.result = {
status: 1,
msg: 'Content Provider Saved'