From fdcdad04f2e69572d9173896edf16db8a821518c Mon Sep 17 00:00:00 2001 From: ppisljar Date: Mon, 11 Sep 2017 11:34:50 +0200 Subject: [PATCH] fixing tests --- .../public/__tests__/_table_vis_controller.js | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/core_plugins/table_vis/public/__tests__/_table_vis_controller.js b/src/core_plugins/table_vis/public/__tests__/_table_vis_controller.js index 4500b8d6f21dd8f..81c4290a7b1da2c 100644 --- a/src/core_plugins/table_vis/public/__tests__/_table_vis_controller.js +++ b/src/core_plugins/table_vis/public/__tests__/_table_vis_controller.js @@ -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'); @@ -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(); } @@ -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'); @@ -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(); @@ -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(); @@ -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 () { @@ -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); }); });