Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed Sep 11, 2017
1 parent 96b2dd8 commit fdcdad0
Showing 1 changed file with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ describe('Controller', function () {
let Vis;
let fixtures;
let AppState;
let tabify;

beforeEach(ngMock.module('kibana', 'kibana/table_vis'));
beforeEach(ngMock.inject(function ($injector) {
Private = $injector.get('Private');
tabify = Private(AggResponseTabifyProvider);
$rootScope = $injector.get('$rootScope');
$compile = $injector.get('$compile');
fixtures = require('fixtures/fake_hierarchical_data');
Expand Down Expand Up @@ -70,7 +72,7 @@ describe('Controller', function () {

// put a response into the controller
function attachEsResponseToScope(resp) {
$rootScope.esResponse = resp || fixtures.oneRangeBucket;
$rootScope.esResponse = resp;
$rootScope.$apply();
}

Expand All @@ -81,12 +83,13 @@ describe('Controller', function () {
}

it('exposes #tableGroups and #hasSomeRows when a response is attached to scope', function () {
initController(new OneRangeVis());
const vis = new OneRangeVis();
initController(vis);

expect(!$scope.tableGroups).to.be.ok();
expect(!$scope.hasSomeRows).to.be.ok();

attachEsResponseToScope(fixtures.oneRangeBucket);
attachEsResponseToScope(tabify(vis, fixtures.oneRangeBucket));

expect($scope.hasSomeRows).to.be(true);
expect($scope.tableGroups).to.have.property('tables');
Expand All @@ -96,9 +99,10 @@ describe('Controller', function () {
});

it('clears #tableGroups and #hasSomeRows when the response is removed', function () {
initController(new OneRangeVis());
const vis = new OneRangeVis();
initController(vis);

attachEsResponseToScope(fixtures.oneRangeBucket);
attachEsResponseToScope(tabify(vis, fixtures.oneRangeBucket));
removeEsResponseFromScope();

expect(!$scope.hasSomeRows).to.be.ok();
Expand All @@ -110,26 +114,28 @@ describe('Controller', function () {
columnIndex: 1,
direction: 'asc'
};
initController(new OneRangeVis({ sort: sortObj }));
const vis = new OneRangeVis({ sort: sortObj });
initController(vis);

// modify the data to not have any buckets
const resp = _.cloneDeep(fixtures.oneRangeBucket);
resp.aggregations.agg_2.buckets = {};

attachEsResponseToScope(resp);
attachEsResponseToScope(tabify(vis, resp));

expect($scope.sort.columnIndex).to.equal(sortObj.columnIndex);
expect($scope.sort.direction).to.equal(sortObj.direction);
});

it('sets #hasSomeRows properly if the table group is empty', function () {
initController(new OneRangeVis());
const vis = new OneRangeVis();
initController(vis);

// modify the data to not have any buckets
const resp = _.cloneDeep(fixtures.oneRangeBucket);
resp.aggregations.agg_2.buckets = {};

attachEsResponseToScope(resp);
attachEsResponseToScope(tabify(vis, resp));

expect($scope.hasSomeRows).to.be(false);
expect(!$scope.tableGroups).to.be.ok();
Expand All @@ -142,10 +148,10 @@ describe('Controller', function () {

const vis = new OneRangeVis({ showPartialRows: true });
initController(vis);
attachEsResponseToScope(fixtures.oneRangeBucket);
attachEsResponseToScope(spiedTabify(vis, fixtures.oneRangeBucket));

expect(spiedTabify).to.have.property('callCount', 1);
expect(spiedTabify.firstCall.args[2]).to.have.property('partialRows', true);
expect(spiedTabify.firstCall.args[0].isHierarchical()).to.equal(true);
});

it('passes partialRows:false to tabify based on the vis params', function () {
Expand All @@ -155,9 +161,9 @@ describe('Controller', function () {

const vis = new OneRangeVis({ showPartialRows: false });
initController(vis);
attachEsResponseToScope(fixtures.oneRangeBucket);
attachEsResponseToScope(spiedTabify(vis, fixtures.oneRangeBucket));

expect(spiedTabify).to.have.property('callCount', 1);
expect(spiedTabify.firstCall.args[2]).to.have.property('partialRows', false);
expect(spiedTabify.firstCall.args[0].isHierarchical()).to.equal(false);
});
});

0 comments on commit fdcdad0

Please sign in to comment.