Tested list and action for Content Provider
diff --git a/xos/core/xoslib/karma.conf.js b/xos/core/xoslib/karma.conf.js
index a633c27..7452ffc 100644
--- a/xos/core/xoslib/karma.conf.js
+++ b/xos/core/xoslib/karma.conf.js
@@ -38,6 +38,7 @@
'spec/helpers/jasmine-jquery.js',
'spec/helpers/angular-mocks.js',
+ 'spec/**/*.mock.js',
'spec/**/*.test.js',
'spec/**/*.html',
diff --git a/xos/core/xoslib/spec/views/contentprovider.test.js b/xos/core/xoslib/spec/views/contentprovider.test.js
index 2a4d189..4f19695 100644
--- a/xos/core/xoslib/spec/views/contentprovider.test.js
+++ b/xos/core/xoslib/spec/views/contentprovider.test.js
@@ -2,7 +2,7 @@
describe('The Content Provider SPA', () => {
- var scope, element;
+ var scope, element, isolatedScope, httpBackend, mockLocation;
// injecting main module
beforeEach(module('xos.contentProviderApp'));
@@ -10,6 +10,32 @@
// preload Html Templates with ng-html2js
beforeEach(module('templates'));
+ beforeEach(inject(function(_$location_, $httpBackend) {
+ spyOn(_$location_, 'url');
+ mockLocation = _$location_;
+ httpBackend = $httpBackend;
+ // Setting up mock request
+ $httpBackend.whenGET('/hpcapi/contentproviders/').respond(CPmock.list);
+ $httpBackend.whenDELETE('/hpcapi/contentproviders/1/').respond();
+ }));
+
+ describe('the action directive', () => {
+ beforeEach(inject(function($compile, $rootScope) {
+ scope = $rootScope.$new();
+
+ element = angular.element('<cp-actions id="\'1\'"></cp-actions>');
+ $compile(element)(scope);
+ scope.$digest();
+ isolatedScope = element.isolateScope().vm;
+ }));
+
+ it('should delete an element and redirect to list', () => {
+ isolatedScope.deleteCp(1);
+ httpBackend.flush();
+ expect(mockLocation.url).toHaveBeenCalled();
+ });
+ });
+
describe('the contentProvider list', () => {
beforeEach(inject(function($compile, $rootScope) {
scope = $rootScope.$new();
@@ -17,11 +43,19 @@
element = angular.element('<content-provider-list></content-provider-list>');
$compile(element)(scope);
scope.$digest();
+ httpBackend.flush();
+ isolatedScope = element.isolateScope().vm;
}));
- it('should call startPolling method', () => {
- expect(true).toBe(true);
+ it('should load 2 contentProvider', () => {
+ expect(isolatedScope.contentProviderList.length).toBe(2);
+ });
+
+ it('should delete a contentProvider', () => {
+ isolatedScope.deleteCp(1);
+ httpBackend.flush();
+ expect(isolatedScope.contentProviderList.length).toBe(1);
});
});
});
diff --git a/xos/core/xoslib/spec/views/mocks/contentProvider.mock.js b/xos/core/xoslib/spec/views/mocks/contentProvider.mock.js
new file mode 100644
index 0000000..edc8233
--- /dev/null
+++ b/xos/core/xoslib/spec/views/mocks/contentProvider.mock.js
@@ -0,0 +1,144 @@
+/* eslint-disable key-spacing */
+
+var CPmock = {
+ list: [
+ {
+ 'humanReadableName':'on_lab_content',
+ 'validators':{
+ 'updated':[
+
+ ],
+ 'policed':[
+
+ ],
+ 'name':[
+ 'notBlank'
+ ],
+ 'created':[
+
+ ],
+ 'deleted':[
+
+ ],
+ 'serviceProvider':[
+ 'notBlank'
+ ],
+ 'description':[
+
+ ],
+ 'enabled':[
+
+ ],
+ 'lazy_blocked':[
+
+ ],
+ 'backend_register':[
+ 'notBlank'
+ ],
+ 'write_protect':[
+
+ ],
+ 'content_provider_id':[
+
+ ],
+ 'backend_status':[
+ 'notBlank'
+ ],
+ 'id':[
+
+ ],
+ 'no_sync':[
+
+ ],
+ 'enacted':[
+
+ ]
+ },
+ 'id':1,
+ 'created':'2015-10-22T19:33:55.078Z',
+ 'updated':'2015-10-22T19:33:55.078Z',
+ 'enacted':null,
+ 'policed':null,
+ 'backend_register':'{}',
+ 'backend_status':'0 - Provisioning in progress',
+ 'deleted':false,
+ 'write_protect':false,
+ 'lazy_blocked':false,
+ 'no_sync':false,
+ 'content_provider_id':null,
+ 'name':'on_lab_content',
+ 'enabled':true,
+ 'description':null,
+ 'serviceProvider':'http://0.0.0.0:9000/hpcapi/serviceproviders/1/'
+ },
+ {
+ 'humanReadableName':'test',
+ 'validators':{
+ 'updated':[
+
+ ],
+ 'policed':[
+
+ ],
+ 'name':[
+ 'notBlank'
+ ],
+ 'created':[
+
+ ],
+ 'deleted':[
+
+ ],
+ 'serviceProvider':[
+ 'notBlank'
+ ],
+ 'description':[
+
+ ],
+ 'enabled':[
+
+ ],
+ 'lazy_blocked':[
+
+ ],
+ 'backend_register':[
+ 'notBlank'
+ ],
+ 'write_protect':[
+
+ ],
+ 'content_provider_id':[
+
+ ],
+ 'backend_status':[
+ 'notBlank'
+ ],
+ 'id':[
+
+ ],
+ 'no_sync':[
+
+ ],
+ 'enacted':[
+
+ ]
+ },
+ 'id':2,
+ 'created':'2015-10-23T10:50:37.482Z',
+ 'updated':'2015-10-23T10:52:56.232Z',
+ 'enacted':null,
+ 'policed':null,
+ 'backend_register':'{}',
+ 'backend_status':'0 - Provisioning in progress',
+ 'deleted':false,
+ 'write_protect':false,
+ 'lazy_blocked':false,
+ 'no_sync':false,
+ 'content_provider_id':null,
+ 'name':'test',
+ 'enabled':true,
+ 'description':'',
+ 'serviceProvider':'http://0.0.0.0:9000/hpcapi/serviceproviders/1/'
+ }
+ ]
+};
\ 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 772e58f..8b2169a 100644
--- a/xos/core/xoslib/static/js/xosContentProvider.js
+++ b/xos/core/xoslib/static/js/xosContentProvider.js
@@ -84,6 +84,7 @@
this.deleteCp = function(id) {
ContentProvider.delete({id: id}).$promise
.then(function() {
+ console.log('deleted');
$location.url('/');
});
};
@@ -94,6 +95,7 @@
return {
restrict: 'E',
controllerAs: 'vm',
+ scope: {},
templateUrl: '../../static/templates/contentProvider/cp_list.html',
controller: function() {
var _this = this;