Matteo Scandolo | 48d890f | 2015-12-14 17:36:09 -0800 | [diff] [blame^] | 1 | 'use strict'; |
| 2 | |
| 3 | describe('In Ceilometer View', () => { |
| 4 | |
| 5 | var scope, element, vm, httpBackend; |
| 6 | |
| 7 | beforeEach(module('xos.ceilometerDashboard')); |
| 8 | beforeEach(module('templates')); |
| 9 | |
| 10 | beforeEach(inject(($httpBackend, $rootScope) => { |
| 11 | httpBackend = $httpBackend; |
| 12 | scope = $rootScope.$new(); |
| 13 | })) |
| 14 | |
| 15 | describe('The dashboard', () => { |
| 16 | beforeEach(inject(function($httpBackend, $compile){ |
| 17 | element = angular.element('<ceilometer-dashboard></ceilometer-dashboard>'); |
| 18 | $compile(element)(scope); |
| 19 | scope.$digest(); |
| 20 | vm = element.isolateScope().vm; |
| 21 | httpBackend.flush(); |
| 22 | })); |
| 23 | |
| 24 | describe('when loading meters', () => { |
| 25 | it('should group meters by services', () => { |
| 26 | expect(Object.keys(vm.projects).length).toBe(2); |
| 27 | }); |
| 28 | |
| 29 | it('should group services by slices', () => { |
| 30 | expect(Object.keys(vm.projects.service_2).length).toBe(2); |
| 31 | }); |
| 32 | |
| 33 | it('should group slices by resources', () => { |
| 34 | expect(Object.keys(vm.projects.service_2.slice_2).length).toBe(2); |
| 35 | }); |
| 36 | }); |
| 37 | }); |
| 38 | |
| 39 | describe('the sample view', () => { |
| 40 | beforeEach(inject(function($httpBackend, $compile, $stateParams){ |
| 41 | |
| 42 | $stateParams.name = 'fakeName'; |
| 43 | $stateParams.tenant = 'fakeTenant'; |
| 44 | |
| 45 | element = angular.element('<ceilometer-samples></ceilometer-samples>'); |
| 46 | $compile(element)(scope); |
| 47 | scope.$digest(); |
| 48 | vm = element.isolateScope().vm; |
| 49 | httpBackend.flush(); |
| 50 | })); |
| 51 | |
| 52 | it('should group samples by resource_id', () => { |
| 53 | expect(Object.keys(vm.samplesList.fakeTenant).length).toBe(2) |
| 54 | expect(Object.keys(vm.samplesList.anotherTenant).length).toBe(3) |
| 55 | expect(Object.keys(vm.samplesList.thirdTenant).length).toBe(1) |
| 56 | }); |
| 57 | |
| 58 | it('should add the comparable samples to the dropdown list', () => { |
| 59 | expect(vm.sampleLabels[0].id).toEqual('anotherTenant') |
| 60 | expect(vm.sampleLabels[1].id).toEqual('thirdTenant') |
| 61 | }); |
| 62 | |
| 63 | it('should add the selected meter to the chart', () => { |
| 64 | expect(vm.chart.labels.length).toBe(2); |
| 65 | expect(vm.chart.series[0]).toBe('fakeTenant'); |
| 66 | expect(vm.chart.data[0].length).toBe(2); |
| 67 | expect(vm.chart.data[0][0]).toBe(110); |
| 68 | expect(vm.chart.data[0][1]).toBe(120); |
| 69 | expect(vm.chartMeters[0].resource_id).toBe('fakeTenant') |
| 70 | expect(vm.chartMeters[0].resource_name).toBe('fakeName') |
| 71 | }); |
| 72 | |
| 73 | it('should add a sample to the chart', () => { |
| 74 | vm.addMeterToChart('anotherTenant'); |
| 75 | expect(vm.chart.labels.length).toBe(3); |
| 76 | expect(vm.chart.data[1].length).toBe(3); |
| 77 | expect(vm.chart.data[1][0]).toBe(210); |
| 78 | expect(vm.chart.data[1][1]).toBe(220); |
| 79 | expect(vm.chart.data[1][2]).toBe(230); |
| 80 | expect(vm.chartMeters[1].resource_id).toBe('anotherTenant') |
| 81 | expect(vm.chartMeters[1].resource_name).toBe('anotherName') |
| 82 | }); |
| 83 | |
| 84 | it('should remove a sample from the chart', () => { |
| 85 | // for simplyvity add a tenant (it's tested) |
| 86 | vm.addMeterToChart('anotherTenant'); |
| 87 | vm.removeFromChart(vm.chartMeters[0]); |
| 88 | expect(vm.chart.data[0].length).toBe(3); |
| 89 | expect(vm.chart.data[0][0]).toBe(210); |
| 90 | expect(vm.chart.data[0][1]).toBe(220); |
| 91 | expect(vm.chart.data[0][2]).toBe(230); |
| 92 | expect(vm.chartMeters[0].resource_id).toBe('anotherTenant') |
| 93 | expect(vm.chartMeters[0].resource_name).toBe('anotherName') |
| 94 | }); |
| 95 | }); |
| 96 | |
| 97 | }); |