Matteo Scandolo | 0968aa9 | 2015-10-23 16:31:17 +0200 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | describe('The Content Provider SPA', () => { |
| 4 | |
Matteo Scandolo | ba3b12a | 2015-10-23 17:45:45 +0200 | [diff] [blame] | 5 | var scope, element, isolatedScope, httpBackend, mockLocation; |
Matteo Scandolo | 0968aa9 | 2015-10-23 16:31:17 +0200 | [diff] [blame] | 6 | |
| 7 | // injecting main module |
| 8 | beforeEach(module('xos.contentProviderApp')); |
| 9 | |
| 10 | // preload Html Templates with ng-html2js |
| 11 | beforeEach(module('templates')); |
| 12 | |
Matteo Scandolo | 0fe4c3e | 2015-10-23 18:37:05 +0200 | [diff] [blame^] | 13 | beforeEach(function() { |
| 14 | module(function($provide) { |
| 15 | $provide.provider('$routeParams', function() { |
| 16 | this.$get = function() { |
| 17 | return {id: 1}; |
| 18 | }; |
| 19 | }); |
| 20 | }); |
| 21 | }); |
| 22 | |
Matteo Scandolo | ba3b12a | 2015-10-23 17:45:45 +0200 | [diff] [blame] | 23 | beforeEach(inject(function(_$location_, $httpBackend) { |
| 24 | spyOn(_$location_, 'url'); |
| 25 | mockLocation = _$location_; |
| 26 | httpBackend = $httpBackend; |
| 27 | // Setting up mock request |
Matteo Scandolo | 0fe4c3e | 2015-10-23 18:37:05 +0200 | [diff] [blame^] | 28 | $httpBackend.whenGET('/hpcapi/contentproviders/').respond(CPmock.CPlist); |
| 29 | $httpBackend.whenGET('/hpcapi/serviceproviders/').respond(CPmock.SPlist); |
Matteo Scandolo | ba3b12a | 2015-10-23 17:45:45 +0200 | [diff] [blame] | 30 | $httpBackend.whenDELETE('/hpcapi/contentproviders/1/').respond(); |
| 31 | })); |
| 32 | |
| 33 | describe('the action directive', () => { |
| 34 | beforeEach(inject(function($compile, $rootScope) { |
| 35 | scope = $rootScope.$new(); |
| 36 | |
| 37 | element = angular.element('<cp-actions id="\'1\'"></cp-actions>'); |
| 38 | $compile(element)(scope); |
| 39 | scope.$digest(); |
| 40 | isolatedScope = element.isolateScope().vm; |
| 41 | })); |
| 42 | |
| 43 | it('should delete an element and redirect to list', () => { |
| 44 | isolatedScope.deleteCp(1); |
| 45 | httpBackend.flush(); |
| 46 | expect(mockLocation.url).toHaveBeenCalled(); |
| 47 | }); |
| 48 | }); |
| 49 | |
Matteo Scandolo | 0968aa9 | 2015-10-23 16:31:17 +0200 | [diff] [blame] | 50 | describe('the contentProvider list', () => { |
| 51 | beforeEach(inject(function($compile, $rootScope) { |
| 52 | scope = $rootScope.$new(); |
| 53 | |
| 54 | element = angular.element('<content-provider-list></content-provider-list>'); |
| 55 | $compile(element)(scope); |
| 56 | scope.$digest(); |
Matteo Scandolo | ba3b12a | 2015-10-23 17:45:45 +0200 | [diff] [blame] | 57 | httpBackend.flush(); |
| 58 | isolatedScope = element.isolateScope().vm; |
Matteo Scandolo | 0968aa9 | 2015-10-23 16:31:17 +0200 | [diff] [blame] | 59 | })); |
| 60 | |
| 61 | |
Matteo Scandolo | ba3b12a | 2015-10-23 17:45:45 +0200 | [diff] [blame] | 62 | it('should load 2 contentProvider', () => { |
| 63 | expect(isolatedScope.contentProviderList.length).toBe(2); |
| 64 | }); |
| 65 | |
| 66 | it('should delete a contentProvider', () => { |
| 67 | isolatedScope.deleteCp(1); |
| 68 | httpBackend.flush(); |
| 69 | expect(isolatedScope.contentProviderList.length).toBe(1); |
Matteo Scandolo | 0968aa9 | 2015-10-23 16:31:17 +0200 | [diff] [blame] | 70 | }); |
| 71 | }); |
Matteo Scandolo | 0fe4c3e | 2015-10-23 18:37:05 +0200 | [diff] [blame^] | 72 | |
| 73 | describe('the contentProviderDetail directive', () => { |
| 74 | describe('when an id is set in the route', () => { |
| 75 | |
| 76 | beforeEach(inject(function($compile, $rootScope, ContentProvider) { |
| 77 | scope = $rootScope.$new(); |
| 78 | |
| 79 | httpBackend.expectGET('/hpcapi/contentproviders/1/').respond(CPmock.CPlist[0]); |
| 80 | httpBackend.whenPUT('/hpcapi/contentproviders/1/').respond({name: 'done'}); |
| 81 | |
| 82 | spyOn(ContentProvider, 'save').and.callThrough(); |
| 83 | |
| 84 | element = angular.element('<content-provider-detail></content-provider-detail>'); |
| 85 | $compile(element)(scope); |
| 86 | scope.$digest(); |
| 87 | httpBackend.flush(); |
| 88 | isolatedScope = element.isolateScope().vm; |
| 89 | })); |
| 90 | |
| 91 | it('should request the correct contentProvider', () => { |
| 92 | expect(isolatedScope.cp.name).toEqual(CPmock.CPlist[0].name); |
| 93 | }); |
| 94 | |
| 95 | it('should update a contentProvider', () => { |
| 96 | isolatedScope.cp.name = 'new name'; |
| 97 | isolatedScope.saveContentProvider(isolatedScope.cp); |
| 98 | httpBackend.flush(); |
| 99 | expect(isolatedScope.cp.name).toEqual('done'); |
| 100 | }); |
| 101 | }); |
| 102 | }); |
Matteo Scandolo | 0968aa9 | 2015-10-23 16:31:17 +0200 | [diff] [blame] | 103 | }); |