Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Matteo Scandolo | 1b9ffac | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 19 | 'use strict'; |
| 20 | |
| 21 | describe('In Ceilometer View', () => { |
Matteo Scandolo | 54bc5f7 | 2016-05-18 14:06:45 -0700 | [diff] [blame] | 22 | |
Matteo Scandolo | 1b9ffac | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 23 | var scope, element, vm, httpBackend; |
| 24 | |
| 25 | beforeEach(module('xos.ceilometerDashboard')); |
| 26 | beforeEach(module('templates')); |
| 27 | |
| 28 | beforeEach(inject(($httpBackend, $rootScope) => { |
| 29 | httpBackend = $httpBackend; |
| 30 | scope = $rootScope.$new(); |
| 31 | })) |
| 32 | |
| 33 | describe('The dashboard', () => { |
| 34 | beforeEach(inject(function($httpBackend, $compile){ |
| 35 | element = angular.element('<ceilometer-dashboard></ceilometer-dashboard>'); |
| 36 | $compile(element)(scope); |
| 37 | scope.$digest(); |
| 38 | vm = element.isolateScope().vm; |
| 39 | httpBackend.flush(); |
| 40 | })); |
| 41 | |
Matteo Scandolo | 88b220e | 2016-06-17 11:57:05 -0700 | [diff] [blame] | 42 | xdescribe('when loading service list', () => { |
| 43 | it('should append the list to the scope', () => { |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 44 | expect(vm.services.length).toBe(2); |
Matteo Scandolo | 8420f62 | 2016-03-24 11:38:50 -0700 | [diff] [blame] | 45 | expect(vm.services[0].slices.length).toBe(2); |
| 46 | expect(vm.services[1].slices.length).toBe(2); |
Matteo Scandolo | 88b220e | 2016-06-17 11:57:05 -0700 | [diff] [blame] | 47 | }); |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 48 | }); |
| 49 | |
Matteo Scandolo | 88b220e | 2016-06-17 11:57:05 -0700 | [diff] [blame] | 50 | xdescribe('when a slice is selected', () => { |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 51 | it('should load corresponding meters', () => { |
Matteo Scandolo | 8420f62 | 2016-03-24 11:38:50 -0700 | [diff] [blame] | 52 | vm.loadSliceMeter(vm.services[0].slices[0]); |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 53 | |
Matteo Scandolo | ba4c9aa | 2016-02-11 09:35:29 -0800 | [diff] [blame] | 54 | httpBackend.flush(); |
| 55 | |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 56 | expect(vm.selectedSlice).toEqual('slice-a-1'); |
| 57 | expect(vm.selectedTenant).toEqual('id-a-1'); |
| 58 | |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 59 | expect(Object.keys(vm.selectedResources).length).toBe(2); |
| 60 | expect(vm.selectedResources['resource-1'].length).toBe(2); |
| 61 | expect(vm.selectedResources['resource-2'].length).toBe(1); |
| 62 | }); |
| 63 | }); |
Matteo Scandolo | 1b9ffac | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 64 | }); |
| 65 | |
| 66 | describe('the sample view', () => { |
| 67 | beforeEach(inject(function($httpBackend, $compile, $stateParams){ |
| 68 | |
| 69 | $stateParams.name = 'fakeName'; |
| 70 | $stateParams.tenant = 'fakeTenant'; |
| 71 | |
| 72 | element = angular.element('<ceilometer-samples></ceilometer-samples>'); |
| 73 | $compile(element)(scope); |
| 74 | scope.$digest(); |
| 75 | vm = element.isolateScope().vm; |
| 76 | httpBackend.flush(); |
| 77 | })); |
| 78 | |
| 79 | it('should group samples by resource_id', () => { |
| 80 | expect(Object.keys(vm.samplesList.fakeTenant).length).toBe(2) |
| 81 | expect(Object.keys(vm.samplesList.anotherTenant).length).toBe(3) |
| 82 | expect(Object.keys(vm.samplesList.thirdTenant).length).toBe(1) |
| 83 | }); |
| 84 | |
Matteo Scandolo | 54bc5f7 | 2016-05-18 14:06:45 -0700 | [diff] [blame] | 85 | xit('should add the comparable samples to the dropdown list', () => { |
| 86 | console.log(vm.sampleLabels); |
Matteo Scandolo | 1b9ffac | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 87 | expect(vm.sampleLabels[0].id).toEqual('anotherTenant') |
| 88 | expect(vm.sampleLabels[1].id).toEqual('thirdTenant') |
| 89 | }); |
| 90 | |
| 91 | it('should add the selected meter to the chart', () => { |
| 92 | expect(vm.chart.labels.length).toBe(2); |
| 93 | expect(vm.chart.series[0]).toBe('fakeTenant'); |
| 94 | expect(vm.chart.data[0].length).toBe(2); |
| 95 | expect(vm.chart.data[0][0]).toBe(110); |
| 96 | expect(vm.chart.data[0][1]).toBe(120); |
Matteo Scandolo | 8420f62 | 2016-03-24 11:38:50 -0700 | [diff] [blame] | 97 | expect(vm.chartMeters[0].resource_id).toBe('fakeTenant') |
Matteo Scandolo | 1b9ffac | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 98 | expect(vm.chartMeters[0].resource_name).toBe('fakeName') |
| 99 | }); |
| 100 | |
| 101 | it('should add a sample to the chart', () => { |
| 102 | vm.addMeterToChart('anotherTenant'); |
| 103 | expect(vm.chart.labels.length).toBe(3); |
| 104 | expect(vm.chart.data[1].length).toBe(3); |
| 105 | expect(vm.chart.data[1][0]).toBe(210); |
| 106 | expect(vm.chart.data[1][1]).toBe(220); |
| 107 | expect(vm.chart.data[1][2]).toBe(230); |
Matteo Scandolo | 8420f62 | 2016-03-24 11:38:50 -0700 | [diff] [blame] | 108 | expect(vm.chartMeters[1].resource_id).toBe('anotherTenant') |
Matteo Scandolo | 1b9ffac | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 109 | expect(vm.chartMeters[1].resource_name).toBe('anotherName') |
| 110 | }); |
| 111 | |
| 112 | it('should remove a sample from the chart', () => { |
| 113 | // for simplyvity add a tenant (it's tested) |
| 114 | vm.addMeterToChart('anotherTenant'); |
| 115 | vm.removeFromChart(vm.chartMeters[0]); |
| 116 | expect(vm.chart.data[0].length).toBe(3); |
| 117 | expect(vm.chart.data[0][0]).toBe(210); |
| 118 | expect(vm.chart.data[0][1]).toBe(220); |
| 119 | expect(vm.chart.data[0][2]).toBe(230); |
Matteo Scandolo | 8420f62 | 2016-03-24 11:38:50 -0700 | [diff] [blame] | 120 | expect(vm.chartMeters[0].resource_id).toBe('anotherTenant') |
Matteo Scandolo | 1b9ffac | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 121 | expect(vm.chartMeters[0].resource_name).toBe('anotherName') |
| 122 | }); |
Matteo Scandolo | 5074ccd | 2015-12-15 08:16:56 -0800 | [diff] [blame] | 123 | |
| 124 | describe('The format sample labels method', () => { |
Matteo Scandolo | 54bc5f7 | 2016-05-18 14:06:45 -0700 | [diff] [blame] | 125 | xit('should create an array of unique labels', () => { |
Matteo Scandolo | 5074ccd | 2015-12-15 08:16:56 -0800 | [diff] [blame] | 126 | // unique because every resource has multiple samples (time-series) |
| 127 | const samples = [ |
Matteo Scandolo | 8420f62 | 2016-03-24 11:38:50 -0700 | [diff] [blame] | 128 | {resource_id: 1, resource_name: 'fakeName'}, |
| 129 | {resource_id: 1, resource_name: 'fakeName'}, |
| 130 | {resource_id: 2, resource_name: 'anotherName'}, |
| 131 | {resource_id: 2, resource_name: 'anotherName'} |
Matteo Scandolo | 5074ccd | 2015-12-15 08:16:56 -0800 | [diff] [blame] | 132 | ]; |
| 133 | |
| 134 | const result = vm.formatSamplesLabels(samples); |
| 135 | |
| 136 | expect(result.length).toBe(2); |
| 137 | expect(result[0]).toEqual({id: 1, name: 'fakeName'}); |
| 138 | expect(result[1]).toEqual({id: 2, name: 'anotherName'}); |
| 139 | }); |
| 140 | }); |
| 141 | }); |
Matteo Scandolo | 1b9ffac | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 142 | }); |