blob: 053481e864e67a86d9b09bab8590bdc54176faa5 [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
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 Scandolo1b9ffac2015-12-14 17:36:09 -080019'use strict';
20
21describe('In Ceilometer View', () => {
Matteo Scandolo54bc5f72016-05-18 14:06:45 -070022
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -080023 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 Scandolo88b220e2016-06-17 11:57:05 -070042 xdescribe('when loading service list', () => {
43 it('should append the list to the scope', () => {
Matteo Scandolo9db064f2016-02-08 14:17:42 -080044 expect(vm.services.length).toBe(2);
Matteo Scandolo8420f622016-03-24 11:38:50 -070045 expect(vm.services[0].slices.length).toBe(2);
46 expect(vm.services[1].slices.length).toBe(2);
Matteo Scandolo88b220e2016-06-17 11:57:05 -070047 });
Matteo Scandolo9db064f2016-02-08 14:17:42 -080048 });
49
Matteo Scandolo88b220e2016-06-17 11:57:05 -070050 xdescribe('when a slice is selected', () => {
Matteo Scandolo9db064f2016-02-08 14:17:42 -080051 it('should load corresponding meters', () => {
Matteo Scandolo8420f622016-03-24 11:38:50 -070052 vm.loadSliceMeter(vm.services[0].slices[0]);
Matteo Scandolo9db064f2016-02-08 14:17:42 -080053
Matteo Scandoloba4c9aa2016-02-11 09:35:29 -080054 httpBackend.flush();
55
Matteo Scandolo9db064f2016-02-08 14:17:42 -080056 expect(vm.selectedSlice).toEqual('slice-a-1');
57 expect(vm.selectedTenant).toEqual('id-a-1');
58
Matteo Scandolo9db064f2016-02-08 14:17:42 -080059 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 Scandolo1b9ffac2015-12-14 17:36:09 -080064 });
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 Scandolo54bc5f72016-05-18 14:06:45 -070085 xit('should add the comparable samples to the dropdown list', () => {
86 console.log(vm.sampleLabels);
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -080087 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 Scandolo8420f622016-03-24 11:38:50 -070097 expect(vm.chartMeters[0].resource_id).toBe('fakeTenant')
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -080098 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 Scandolo8420f622016-03-24 11:38:50 -0700108 expect(vm.chartMeters[1].resource_id).toBe('anotherTenant')
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -0800109 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 Scandolo8420f622016-03-24 11:38:50 -0700120 expect(vm.chartMeters[0].resource_id).toBe('anotherTenant')
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -0800121 expect(vm.chartMeters[0].resource_name).toBe('anotherName')
122 });
Matteo Scandolo5074ccd2015-12-15 08:16:56 -0800123
124 describe('The format sample labels method', () => {
Matteo Scandolo54bc5f72016-05-18 14:06:45 -0700125 xit('should create an array of unique labels', () => {
Matteo Scandolo5074ccd2015-12-15 08:16:56 -0800126 // unique because every resource has multiple samples (time-series)
127 const samples = [
Matteo Scandolo8420f622016-03-24 11:38:50 -0700128 {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 Scandolo5074ccd2015-12-15 08:16:56 -0800132 ];
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 Scandolo1b9ffac2015-12-14 17:36:09 -0800142});