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 | |
Matteo Scandolo | c012856 | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 24 | xdescribe('when loading meters', () => { |
Matteo Scandolo | 48d890f | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 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 | }); |
Matteo Scandolo | c012856 | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 37 | |
| 38 | describe('when loading service list', () => { |
| 39 | it('should append the list to the scope', () => { |
| 40 | expect(vm.services.length).toBe(2); |
| 41 | expect(vm.services[0].slice.length).toBe(2); |
| 42 | expect(vm.services[1].slice.length).toBe(2); |
| 43 | }); |
| 44 | }); |
| 45 | |
| 46 | describe('when a slice is selected', () => { |
| 47 | it('should load corresponding meters', () => { |
| 48 | vm.loadSliceMeter(vm.services[0].slice[0]); |
| 49 | |
Matteo Scandolo | 32f8392 | 2016-02-11 09:35:29 -0800 | [diff] [blame] | 50 | httpBackend.flush(); |
| 51 | |
Matteo Scandolo | c012856 | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 52 | expect(vm.selectedSlice).toEqual('slice-a-1'); |
| 53 | expect(vm.selectedTenant).toEqual('id-a-1'); |
| 54 | |
Matteo Scandolo | c012856 | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 55 | expect(Object.keys(vm.selectedResources).length).toBe(2); |
| 56 | expect(vm.selectedResources['resource-1'].length).toBe(2); |
| 57 | expect(vm.selectedResources['resource-2'].length).toBe(1); |
| 58 | }); |
| 59 | }); |
Matteo Scandolo | 48d890f | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 60 | }); |
| 61 | |
| 62 | describe('the sample view', () => { |
| 63 | beforeEach(inject(function($httpBackend, $compile, $stateParams){ |
| 64 | |
| 65 | $stateParams.name = 'fakeName'; |
| 66 | $stateParams.tenant = 'fakeTenant'; |
| 67 | |
| 68 | element = angular.element('<ceilometer-samples></ceilometer-samples>'); |
| 69 | $compile(element)(scope); |
| 70 | scope.$digest(); |
| 71 | vm = element.isolateScope().vm; |
| 72 | httpBackend.flush(); |
| 73 | })); |
| 74 | |
| 75 | it('should group samples by resource_id', () => { |
| 76 | expect(Object.keys(vm.samplesList.fakeTenant).length).toBe(2) |
| 77 | expect(Object.keys(vm.samplesList.anotherTenant).length).toBe(3) |
| 78 | expect(Object.keys(vm.samplesList.thirdTenant).length).toBe(1) |
| 79 | }); |
| 80 | |
| 81 | it('should add the comparable samples to the dropdown list', () => { |
| 82 | expect(vm.sampleLabels[0].id).toEqual('anotherTenant') |
| 83 | expect(vm.sampleLabels[1].id).toEqual('thirdTenant') |
| 84 | }); |
| 85 | |
| 86 | it('should add the selected meter to the chart', () => { |
| 87 | expect(vm.chart.labels.length).toBe(2); |
| 88 | expect(vm.chart.series[0]).toBe('fakeTenant'); |
| 89 | expect(vm.chart.data[0].length).toBe(2); |
| 90 | expect(vm.chart.data[0][0]).toBe(110); |
| 91 | expect(vm.chart.data[0][1]).toBe(120); |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 92 | expect(vm.chartMeters[0].project_id).toBe('fakeTenant') |
Matteo Scandolo | 48d890f | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 93 | expect(vm.chartMeters[0].resource_name).toBe('fakeName') |
| 94 | }); |
| 95 | |
| 96 | it('should add a sample to the chart', () => { |
| 97 | vm.addMeterToChart('anotherTenant'); |
| 98 | expect(vm.chart.labels.length).toBe(3); |
| 99 | expect(vm.chart.data[1].length).toBe(3); |
| 100 | expect(vm.chart.data[1][0]).toBe(210); |
| 101 | expect(vm.chart.data[1][1]).toBe(220); |
| 102 | expect(vm.chart.data[1][2]).toBe(230); |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 103 | expect(vm.chartMeters[1].project_id).toBe('anotherTenant') |
Matteo Scandolo | 48d890f | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 104 | expect(vm.chartMeters[1].resource_name).toBe('anotherName') |
| 105 | }); |
| 106 | |
| 107 | it('should remove a sample from the chart', () => { |
| 108 | // for simplyvity add a tenant (it's tested) |
| 109 | vm.addMeterToChart('anotherTenant'); |
| 110 | vm.removeFromChart(vm.chartMeters[0]); |
| 111 | expect(vm.chart.data[0].length).toBe(3); |
| 112 | expect(vm.chart.data[0][0]).toBe(210); |
| 113 | expect(vm.chart.data[0][1]).toBe(220); |
| 114 | expect(vm.chart.data[0][2]).toBe(230); |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 115 | expect(vm.chartMeters[0].project_id).toBe('anotherTenant') |
Matteo Scandolo | 48d890f | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 116 | expect(vm.chartMeters[0].resource_name).toBe('anotherName') |
| 117 | }); |
Matteo Scandolo | 9e1bc29 | 2015-12-15 08:16:56 -0800 | [diff] [blame] | 118 | |
| 119 | describe('The format sample labels method', () => { |
| 120 | it('should create an array of unique labels', () => { |
| 121 | // unique because every resource has multiple samples (time-series) |
| 122 | const samples = [ |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 123 | {project_id: 1, resource_name: 'fakeName'}, |
| 124 | {project_id: 1, resource_name: 'fakeName'}, |
| 125 | {project_id: 2, resource_name: 'anotherName'}, |
| 126 | {project_id: 2, resource_name: 'anotherName'} |
Matteo Scandolo | 9e1bc29 | 2015-12-15 08:16:56 -0800 | [diff] [blame] | 127 | ]; |
| 128 | |
| 129 | const result = vm.formatSamplesLabels(samples); |
| 130 | |
| 131 | expect(result.length).toBe(2); |
| 132 | expect(result[0]).toEqual({id: 1, name: 'fakeName'}); |
| 133 | expect(result[1]).toEqual({id: 2, name: 'anotherName'}); |
| 134 | }); |
| 135 | }); |
| 136 | }); |
Matteo Scandolo | 48d890f | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 137 | }); |