blob: c5bb850074b15cbc2e39974d98dd56bbbf8e0228 [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
24 describe('when loading meters', () => {
25 it('should group meters by services', () => {
26 expect(Object.keys(vm.projects).length).toBe(2);
27 });
28
29 it('should group services by slices', () => {
30 expect(Object.keys(vm.projects.service_2).length).toBe(2);
31 });
32
33 it('should group slices by resources', () => {
34 expect(Object.keys(vm.projects.service_2.slice_2).length).toBe(2);
35 });
36 });
37 });
38
39 describe('the sample view', () => {
40 beforeEach(inject(function($httpBackend, $compile, $stateParams){
41
42 $stateParams.name = 'fakeName';
43 $stateParams.tenant = 'fakeTenant';
44
45 element = angular.element('<ceilometer-samples></ceilometer-samples>');
46 $compile(element)(scope);
47 scope.$digest();
48 vm = element.isolateScope().vm;
49 httpBackend.flush();
50 }));
51
52 it('should group samples by resource_id', () => {
53 expect(Object.keys(vm.samplesList.fakeTenant).length).toBe(2)
54 expect(Object.keys(vm.samplesList.anotherTenant).length).toBe(3)
55 expect(Object.keys(vm.samplesList.thirdTenant).length).toBe(1)
56 });
57
58 it('should add the comparable samples to the dropdown list', () => {
59 expect(vm.sampleLabels[0].id).toEqual('anotherTenant')
60 expect(vm.sampleLabels[1].id).toEqual('thirdTenant')
61 });
62
63 it('should add the selected meter to the chart', () => {
64 expect(vm.chart.labels.length).toBe(2);
65 expect(vm.chart.series[0]).toBe('fakeTenant');
66 expect(vm.chart.data[0].length).toBe(2);
67 expect(vm.chart.data[0][0]).toBe(110);
68 expect(vm.chart.data[0][1]).toBe(120);
Matteo Scandolo6c6b9282015-12-15 14:37:27 -080069 expect(vm.chartMeters[0].project_id).toBe('fakeTenant')
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -080070 expect(vm.chartMeters[0].resource_name).toBe('fakeName')
71 });
72
73 it('should add a sample to the chart', () => {
74 vm.addMeterToChart('anotherTenant');
75 expect(vm.chart.labels.length).toBe(3);
76 expect(vm.chart.data[1].length).toBe(3);
77 expect(vm.chart.data[1][0]).toBe(210);
78 expect(vm.chart.data[1][1]).toBe(220);
79 expect(vm.chart.data[1][2]).toBe(230);
Matteo Scandolo6c6b9282015-12-15 14:37:27 -080080 expect(vm.chartMeters[1].project_id).toBe('anotherTenant')
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -080081 expect(vm.chartMeters[1].resource_name).toBe('anotherName')
82 });
83
84 it('should remove a sample from the chart', () => {
85 // for simplyvity add a tenant (it's tested)
86 vm.addMeterToChart('anotherTenant');
87 vm.removeFromChart(vm.chartMeters[0]);
88 expect(vm.chart.data[0].length).toBe(3);
89 expect(vm.chart.data[0][0]).toBe(210);
90 expect(vm.chart.data[0][1]).toBe(220);
91 expect(vm.chart.data[0][2]).toBe(230);
Matteo Scandolo6c6b9282015-12-15 14:37:27 -080092 expect(vm.chartMeters[0].project_id).toBe('anotherTenant')
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -080093 expect(vm.chartMeters[0].resource_name).toBe('anotherName')
94 });
Matteo Scandolo5074ccd2015-12-15 08:16:56 -080095
96 describe('The format sample labels method', () => {
97 it('should create an array of unique labels', () => {
98 // unique because every resource has multiple samples (time-series)
99 const samples = [
Matteo Scandolo6c6b9282015-12-15 14:37:27 -0800100 {project_id: 1, resource_name: 'fakeName'},
101 {project_id: 1, resource_name: 'fakeName'},
102 {project_id: 2, resource_name: 'anotherName'},
103 {project_id: 2, resource_name: 'anotherName'}
Matteo Scandolo5074ccd2015-12-15 08:16:56 -0800104 ];
105
106 const result = vm.formatSamplesLabels(samples);
107
108 expect(result.length).toBe(2);
109 expect(result[0]).toEqual({id: 1, name: 'fakeName'});
110 expect(result[1]).toEqual({id: 2, name: 'anotherName'});
111 });
112 });
113 });
114});
115
116describe('The orderObjectByKey filter', () => {
117 var $filter;
118
119 beforeEach(function () {
120 module('xos.ceilometerDashboard');
121
122 inject(function (_$filter_) {
123 $filter = _$filter_;
124 });
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -0800125 });
126
Matteo Scandolo5074ccd2015-12-15 08:16:56 -0800127 it('should order an object by the key value', function () {
128 // Arrange.
129 const list = {c: 3, b: 2, a: 1};
130
131 // call the filter function
132 const result = $filter('orderObjectByKey')(list);
133
134 // Assert.
135 expect(result).toEqual({a: 1, b: 2, c: 3});
136 });
Matteo Scandolo1b9ffac2015-12-14 17:36:09 -0800137});