Skip to content

Commit

Permalink
adding visualize editor unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed Feb 15, 2017
1 parent d00dc51 commit 5e76d9c
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
>
<span
aria-hidden="true"
ng-class="{ 'fa-caret-down': isCategoryAxisOpen, 'fa-caret-right': !isCategoryAxisOpen }"
ng-class="{ 'fa-caret-down': isGridOpen, 'fa-caret-right': !isGridOpen }"
class="fa fa-caret-right kuiSideBarCollapsibleTitle__caret"
></span>
<span class="kuiSideBarCollapsibleTitle__text">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ module.directive('vislibValueAxes', function ($parse, $compile) {
};

$scope.removeValueAxis = function (axis) {
_.remove($scope.vis.params.valueAxes, function (valAxis) {
return valAxis.id === axis.id;
});
if ($scope.vis.params.valueAxes.length > 1) {
_.remove($scope.vis.params.valueAxes, function (valAxis) {
return valAxis.id === axis.id;
});
}
};

$scope.updateExtents = function (axis) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import angular from 'angular';
import _ from 'lodash';
import expect from 'expect.js';
import ngMock from 'ng_mock';
import $ from 'jquery';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import pointSeriesEditorHTML from 'plugins/kbn_vislib_vis_types/editors/point_series.html';
import LineVisTypeProvider from 'plugins/kbn_vislib_vis_types/line';
import VisProvider from 'ui/vis';
import AggConfigProvider from 'ui/vis/agg_config';

describe('point series editor', function () {
let $parentScope;
let $scope;
let $container;
let $elem;
let lineVisType;
let Vis;
let indexPattern;
let AggConfig;

function makeConfig() {
return {
type: 'line',
params: lineVisType.params.defaults,
aggs: [
{ type: 'count', schema: 'metric', params: { field: 'bytes' } },
{ type: 'terms', schema: 'segment', params: { field: 'machine.os' } },
],
listeners: { click: _.noop }
};
}

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function ($rootScope, $compile, Private) {
AggConfig = Private(AggConfigProvider);
lineVisType = Private(LineVisTypeProvider);
Vis = Private(VisProvider);
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
$parentScope = $rootScope;
$parentScope.vis = new Vis(indexPattern, makeConfig());
$parentScope.savedVis = {};

// share the scope
//_.defaults($parentScope, $rootScope, Object.getPrototypeOf($rootScope));

$container = $(document.createElement('div'))
.appendTo('body');
// make the element
$elem = angular.element(pointSeriesEditorHTML);
$container.append($elem);

// compile the html
$compile($elem)($parentScope);

// Digest everything
$elem.scope().$digest();

// give us a scope to work with
$scope = $elem.isolateScope();
}));

afterEach(function () {
$container.remove();
});

it('should show correct series', function () {
expect($parentScope.vis.params.seriesParams.length).to.be(1);
expect($parentScope.vis.params.seriesParams[0].data.label).to.be('Count');
});

it('should update series when new agg is added', function () {
const aggConfig = new AggConfig($parentScope.vis, { type: 'avg', schema: 'metric', params: { field: 'bytes' } });
$parentScope.vis.aggs.push(aggConfig);
$parentScope.$digest();
expect($parentScope.vis.params.seriesParams.length).to.be(2);
});

it('should only allow left and right value axis position when category axis is horizontal', function () {
expect($parentScope.isPositionDisabled('top')).to.be(true);
expect($parentScope.isPositionDisabled('bottom')).to.be(true);
expect($parentScope.isPositionDisabled('left')).to.be(false);
expect($parentScope.isPositionDisabled('right')).to.be(false);
});

it('should only allow top and bottom value axis position when category axis is vertical', function () {
$parentScope.vis.params.categoryAxes[0].position = 'left';
$parentScope.$digest();
expect($parentScope.vis.params.valueAxes[0].position).to.be('bottom');
expect($parentScope.isPositionDisabled('top')).to.be(false);
expect($parentScope.isPositionDisabled('bottom')).to.be(false);
expect($parentScope.isPositionDisabled('left')).to.be(true);
expect($parentScope.isPositionDisabled('right')).to.be(true);
});

it('should add value axis', function () {
$parentScope.addValueAxis();
expect($parentScope.vis.params.valueAxes.length).to.be(2);
});

it('should remove value axis', function () {
$parentScope.addValueAxis();
$parentScope.removeValueAxis({ id: 'ValueAxis-2' });
expect($parentScope.vis.params.valueAxes.length).to.be(1);
});

it('should not allow to remove the last value axis', function () {
$parentScope.removeValueAxis({ id: 'ValueAxis-1' });
expect($parentScope.vis.params.valueAxes.length).to.be(1);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<div>


<!-- Global settings -->
<div class="kuiSideBarSection">
<div class="kuiSideBarSectionTitle">
Expand Down

0 comments on commit 5e76d9c

Please sign in to comment.