Matteo Scandolo | 48d890f | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | describe('In Ceilometer View', () => { |
Matteo Scandolo | d24b871 | 2016-05-18 14:06:45 -0700 | [diff] [blame] | 4 | |
Matteo Scandolo | 48d890f | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 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 | describe('when loading service list', () => { |
Matteo Scandolo | d24b871 | 2016-05-18 14:06:45 -0700 | [diff] [blame] | 25 | it('should append the list to the scope', inject(() => { |
Matteo Scandolo | c012856 | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 26 | expect(vm.services.length).toBe(2); |
Matteo Scandolo | 89b179c | 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 | d24b871 | 2016-05-18 14:06:45 -0700 | [diff] [blame] | 29 | })); |
Matteo Scandolo | c012856 | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 30 | }); |
| 31 | |
| 32 | describe('when a slice is selected', () => { |
| 33 | it('should load corresponding meters', () => { |
Matteo Scandolo | 89b179c | 2016-03-24 11:38:50 -0700 | [diff] [blame] | 34 | vm.loadSliceMeter(vm.services[0].slices[0]); |
Matteo Scandolo | c012856 | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 35 | |
Matteo Scandolo | 32f8392 | 2016-02-11 09:35:29 -0800 | [diff] [blame] | 36 | httpBackend.flush(); |
| 37 | |
Matteo Scandolo | c012856 | 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 | c012856 | 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 | 48d890f | 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 | |
Matteo Scandolo | d24b871 | 2016-05-18 14:06:45 -0700 | [diff] [blame] | 67 | xit('should add the comparable samples to the dropdown list', () => { |
| 68 | console.log(vm.sampleLabels); |
Matteo Scandolo | 48d890f | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 69 | expect(vm.sampleLabels[0].id).toEqual('anotherTenant') |
| 70 | expect(vm.sampleLabels[1].id).toEqual('thirdTenant') |
| 71 | }); |
| 72 | |
| 73 | it('should add the selected meter to the chart', () => { |
| 74 | expect(vm.chart.labels.length).toBe(2); |
| 75 | expect(vm.chart.series[0]).toBe('fakeTenant'); |
| 76 | expect(vm.chart.data[0].length).toBe(2); |
| 77 | expect(vm.chart.data[0][0]).toBe(110); |
| 78 | expect(vm.chart.data[0][1]).toBe(120); |
Matteo Scandolo | 89b179c | 2016-03-24 11:38:50 -0700 | [diff] [blame] | 79 | expect(vm.chartMeters[0].resource_id).toBe('fakeTenant') |
Matteo Scandolo | 48d890f | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 80 | expect(vm.chartMeters[0].resource_name).toBe('fakeName') |
| 81 | }); |
| 82 | |
| 83 | it('should add a sample to the chart', () => { |
| 84 | vm.addMeterToChart('anotherTenant'); |
| 85 | expect(vm.chart.labels.length).toBe(3); |
| 86 | expect(vm.chart.data[1].length).toBe(3); |
| 87 | expect(vm.chart.data[1][0]).toBe(210); |
| 88 | expect(vm.chart.data[1][1]).toBe(220); |
| 89 | expect(vm.chart.data[1][2]).toBe(230); |
Matteo Scandolo | 89b179c | 2016-03-24 11:38:50 -0700 | [diff] [blame] | 90 | expect(vm.chartMeters[1].resource_id).toBe('anotherTenant') |
Matteo Scandolo | 48d890f | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 91 | expect(vm.chartMeters[1].resource_name).toBe('anotherName') |
| 92 | }); |
| 93 | |
| 94 | it('should remove a sample from the chart', () => { |
| 95 | // for simplyvity add a tenant (it's tested) |
| 96 | vm.addMeterToChart('anotherTenant'); |
| 97 | vm.removeFromChart(vm.chartMeters[0]); |
| 98 | expect(vm.chart.data[0].length).toBe(3); |
| 99 | expect(vm.chart.data[0][0]).toBe(210); |
| 100 | expect(vm.chart.data[0][1]).toBe(220); |
| 101 | expect(vm.chart.data[0][2]).toBe(230); |
Matteo Scandolo | 89b179c | 2016-03-24 11:38:50 -0700 | [diff] [blame] | 102 | expect(vm.chartMeters[0].resource_id).toBe('anotherTenant') |
Matteo Scandolo | 48d890f | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 103 | expect(vm.chartMeters[0].resource_name).toBe('anotherName') |
| 104 | }); |
Matteo Scandolo | 9e1bc29 | 2015-12-15 08:16:56 -0800 | [diff] [blame] | 105 | |
| 106 | describe('The format sample labels method', () => { |
Matteo Scandolo | d24b871 | 2016-05-18 14:06:45 -0700 | [diff] [blame] | 107 | xit('should create an array of unique labels', () => { |
Matteo Scandolo | 9e1bc29 | 2015-12-15 08:16:56 -0800 | [diff] [blame] | 108 | // unique because every resource has multiple samples (time-series) |
| 109 | const samples = [ |
Matteo Scandolo | 89b179c | 2016-03-24 11:38:50 -0700 | [diff] [blame] | 110 | {resource_id: 1, resource_name: 'fakeName'}, |
| 111 | {resource_id: 1, resource_name: 'fakeName'}, |
| 112 | {resource_id: 2, resource_name: 'anotherName'}, |
| 113 | {resource_id: 2, resource_name: 'anotherName'} |
Matteo Scandolo | 9e1bc29 | 2015-12-15 08:16:56 -0800 | [diff] [blame] | 114 | ]; |
| 115 | |
| 116 | const result = vm.formatSamplesLabels(samples); |
| 117 | |
| 118 | expect(result.length).toBe(2); |
| 119 | expect(result[0]).toEqual({id: 1, name: 'fakeName'}); |
| 120 | expect(result[1]).toEqual({id: 2, name: 'anotherName'}); |
| 121 | }); |
| 122 | }); |
| 123 | }); |
Matteo Scandolo | 48d890f | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 124 | }); |