Matteo Scandolo | 169dc16 | 2015-12-17 16:12:15 -0800 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | describe('In autoscaling app', () => { |
| 4 | var scope, element, vm, httpBackend, Service; |
| 5 | |
| 6 | |
| 7 | |
| 8 | beforeEach(module('autoscaling')); |
| 9 | beforeEach(module('templates')); |
| 10 | |
| 11 | beforeEach(inject(($httpBackend, $rootScope, Autoscaling) => { |
| 12 | httpBackend = $httpBackend; |
| 13 | scope = $rootScope.$new(); |
| 14 | Service = Autoscaling; |
| 15 | })); |
| 16 | |
| 17 | describe('the serviceContainer', () => { |
| 18 | beforeEach(inject(function($httpBackend, $compile){ |
| 19 | |
| 20 | httpBackend.whenGET('/autoscaledata').respond(200, autoscalingMock); |
| 21 | |
| 22 | element = angular.element('<service-container></service-container>'); |
| 23 | $compile(element)(scope); |
| 24 | |
| 25 | scope.$digest(); |
| 26 | vm = element.isolateScope().vm; |
| 27 | httpBackend.flush(); |
| 28 | })); |
| 29 | |
| 30 | it('should correctly format data', () => { |
| 31 | expect(vm.services['service1']).toBeDefined(); |
| 32 | expect(vm.services['service1']['slice1']).toBeDefined(); |
| 33 | expect(vm.services['service1']['slice1']['instance1']).toBeDefined(); |
| 34 | |
| 35 | expect(vm.services['service1']['slice1']['instance1'][0].counter_volume).toBe(10); |
| 36 | expect(vm.services['service1']['slice1']['instance1'][1].counter_volume).toBe(11); |
| 37 | |
| 38 | // triggering the function with 2 resources |
| 39 | vm.printData(Service.formatData(autoscalingMock2instances)); |
| 40 | |
| 41 | const keys = Object.keys(vm.services['service1']['slice1']); |
| 42 | |
| 43 | expect(vm.services['service1']['slice1'][keys[0]][0].counter_volume).toBe(10); |
| 44 | expect(vm.services['service1']['slice1'][keys[0]][1].counter_volume).toBe(11); |
| 45 | |
| 46 | }); |
| 47 | }); |
| 48 | }); |