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