-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
117 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/core_plugins/kbn_vislib_vis_types/public/editors/__tests__/point_series.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
2 changes: 0 additions & 2 deletions
2
src/core_plugins/kbn_vislib_vis_types/public/editors/point_series.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
<div> | ||
|
||
|
||
<!-- Global settings --> | ||
<div class="kuiSideBarSection"> | ||
<div class="kuiSideBarSectionTitle"> | ||
|