blob: 3eeaf818e34ac8c06cbac325a14182ca64782842 [file] [log] [blame]
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -08001'use strict';
2
3describe('In Ceilometer View', () => {
Matteo Scandolo54bc5f72016-05-18 14:06:45 -07004
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -08005 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', () => {
Matteo Scandolo54bc5f72016-05-18 14:06:45 -070025 it('should append the list to the scope', inject(() => {
Matteo Scandolo9db064f2016-02-08 14:17:42 -080026 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 Scandolo54bc5f72016-05-18 14:06:45 -070029 }));
Matteo Scandolo9db064f2016-02-08 14:17:42 -080030 });
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
Matteo Scandolo54bc5f72016-05-18 14:06:45 -070067 xit('should add the comparable samples to the dropdown list', () => {
68 console.log(vm.sampleLabels);
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -080069 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 Scandolo8420f622016-03-24 11:38:50 -070079 expect(vm.chartMeters[0].resource_id).toBe('fakeTenant')
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -080080 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 Scandolo8420f622016-03-24 11:38:50 -070090 expect(vm.chartMeters[1].resource_id).toBe('anotherTenant')
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -080091 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 Scandolo8420f622016-03-24 11:38:50 -0700102 expect(vm.chartMeters[0].resource_id).toBe('anotherTenant')
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -0800103 expect(vm.chartMeters[0].resource_name).toBe('anotherName')
104 });
Matteo Scandolo5074ccd2015-12-15 08:16:56 -0800105
106 describe('The format sample labels method', () => {
Matteo Scandolo54bc5f72016-05-18 14:06:45 -0700107 xit('should create an array of unique labels', () => {
Matteo Scandolo5074ccd2015-12-15 08:16:56 -0800108 // unique because every resource has multiple samples (time-series)
109 const samples = [
Matteo Scandolo8420f622016-03-24 11:38:50 -0700110 {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 Scandolo5074ccd2015-12-15 08:16:56 -0800114 ];
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 Scandolo1b9ffac2015-12-14 17:36:09 -0800124});