blob: 933f892ad89a240db77da6c26e617dd7ee78b391 [file] [log] [blame]
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -08001'use strict';
2
3describe('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 Scandolo9db064f2016-02-08 14:17:42 -080024 describe('when loading service list', () => {
25 it('should append the list to the scope', () => {
26 expect(vm.services.length).toBe(2);
Matteo Scandolo8420f622016-03-24 11:38:50 -070027 expect(vm.services[0].slices.length).toBe(2);
28 expect(vm.services[1].slices.length).toBe(2);
Matteo Scandolo9db064f2016-02-08 14:17:42 -080029 });
30 });
31
32 describe('when a slice is selected', () => {
33 it('should load corresponding meters', () => {
Matteo Scandolo8420f622016-03-24 11:38:50 -070034 vm.loadSliceMeter(vm.services[0].slices[0]);
Matteo Scandolo9db064f2016-02-08 14:17:42 -080035
Matteo Scandoloba4c9aa2016-02-11 09:35:29 -080036 httpBackend.flush();
37
Matteo Scandolo9db064f2016-02-08 14:17:42 -080038 expect(vm.selectedSlice).toEqual('slice-a-1');
39 expect(vm.selectedTenant).toEqual('id-a-1');
40
Matteo Scandolo9db064f2016-02-08 14:17:42 -080041 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 Scandolo1b9ffac2015-12-14 17:36:09 -080046 });
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 Scandolo8420f622016-03-24 11:38:50 -070078 expect(vm.chartMeters[0].resource_id).toBe('fakeTenant')
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -080079 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 Scandolo8420f622016-03-24 11:38:50 -070089 expect(vm.chartMeters[1].resource_id).toBe('anotherTenant')
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -080090 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 Scandolo8420f622016-03-24 11:38:50 -0700101 expect(vm.chartMeters[0].resource_id).toBe('anotherTenant')
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -0800102 expect(vm.chartMeters[0].resource_name).toBe('anotherName')
103 });
Matteo Scandolo5074ccd2015-12-15 08:16:56 -0800104
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 Scandolo8420f622016-03-24 11:38:50 -0700109 {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 Scandolo5074ccd2015-12-15 08:16:56 -0800113 ];
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 Scandolo1b9ffac2015-12-14 17:36:09 -0800123});