tested ceilometer view
diff --git a/xos/core/xoslib/ngXosViews/ceilometerDashboard/spec/ceilometer.test.js b/xos/core/xoslib/ngXosViews/ceilometerDashboard/spec/ceilometer.test.js
index 8274853..9bfb5b6 100644
--- a/xos/core/xoslib/ngXosViews/ceilometerDashboard/spec/ceilometer.test.js
+++ b/xos/core/xoslib/ngXosViews/ceilometerDashboard/spec/ceilometer.test.js
@@ -92,6 +92,46 @@
expect(vm.chartMeters[0].resource_id).toBe('anotherTenant')
expect(vm.chartMeters[0].resource_name).toBe('anotherName')
});
+
+ describe('The format sample labels method', () => {
+ it('should create an array of unique labels', () => {
+ // unique because every resource has multiple samples (time-series)
+ const samples = [
+ {resource_id: 1, resource_name: 'fakeName'},
+ {resource_id: 1, resource_name: 'fakeName'},
+ {resource_id: 2, resource_name: 'anotherName'},
+ {resource_id: 2, resource_name: 'anotherName'}
+ ];
+
+ const result = vm.formatSamplesLabels(samples);
+
+ expect(result.length).toBe(2);
+ expect(result[0]).toEqual({id: 1, name: 'fakeName'});
+ expect(result[1]).toEqual({id: 2, name: 'anotherName'});
+ });
+ });
+ });
+});
+
+describe('The orderObjectByKey filter', () => {
+ var $filter;
+
+ beforeEach(function () {
+ module('xos.ceilometerDashboard');
+
+ inject(function (_$filter_) {
+ $filter = _$filter_;
+ });
});
+ it('should order an object by the key value', function () {
+ // Arrange.
+ const list = {c: 3, b: 2, a: 1};
+
+ // call the filter function
+ const result = $filter('orderObjectByKey')(list);
+
+ // Assert.
+ expect(result).toEqual({a: 1, b: 2, c: 3});
+ });
});
\ No newline at end of file
diff --git a/xos/core/xoslib/ngXosViews/ceilometerDashboard/src/js/main.js b/xos/core/xoslib/ngXosViews/ceilometerDashboard/src/js/main.js
index 9506139..58033e9 100644
--- a/xos/core/xoslib/ngXosViews/ceilometerDashboard/src/js/main.js
+++ b/xos/core/xoslib/ngXosViews/ceilometerDashboard/src/js/main.js
@@ -271,13 +271,14 @@
this.formatSamplesLabels = (samples) => {
- return lodash.uniq(samples.reduce((labels, item) => {
+ return lodash.uniq(samples, 'resource_id')
+ .reduce((labels, item) => {
labels.push({
id: item.resource_id,
name: item.resource_name
});
return labels;
- }, []), item => item.id);
+ }, []);
}