Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-set default index pattern in navigateToApp #8125

Merged
merged 9 commits into from
Aug 30, 2016
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,13 @@ import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logsta

let $parentScope;
let $scope;
let config;
let hits;
let indexPattern;
let indexPatternList;
let shortDotsValue;

// Sets up the directive, take an element, and a list of properties to attach to the parent scope.
const init = function ($elem, props) {
ngMock.inject(function ($rootScope, $compile, $timeout, _config_) {
shortDotsValue = _config_.get('shortDots:enable');
config = _config_;
config.set('shortDots:enable', false);
ngMock.inject(function ($rootScope, $compile, $timeout) {
$parentScope = $rootScope;
_.assign($parentScope, props);
$compile($elem)($parentScope);
Expand All @@ -39,7 +34,6 @@ const init = function ($elem, props) {
const destroy = function () {
$scope.$destroy();
$parentScope.$destroy();
config.set('shortDots:enable', shortDotsValue);
};

describe('discover field chooser directives', function () {
Expand All @@ -56,7 +50,21 @@ describe('discover field chooser directives', function () {
'</disc-field-chooser>'
);

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.module('kibana', ($provide) => {
$provide.decorator('config', ($delegate) => {
// disable shortDots for these tests
$delegate.get = _.wrap($delegate.get, function (origGet, name) {
if (name === 'shortDots:enable') {
return false;
} else {
return origGet.call(this, name);
}
});

return $delegate;
});
}));

beforeEach(ngMock.inject(function (Private) {
hits = Private(FixturesHitsProvider);
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
Expand Down
4 changes: 2 additions & 2 deletions test/functional/apps/discover/_collapse_expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bdd.describe('discover tab', function describeIndexTests() {
return PageObjects.discover.getSidebarWidth()
.then(function (width) {
PageObjects.common.debug('expanded sidebar width = ' + width);
expect(width > 180).to.be(true);
expect(width > 20).to.be(true);
});
});

Expand All @@ -66,7 +66,7 @@ bdd.describe('discover tab', function describeIndexTests() {
})
.then(function (width) {
PageObjects.common.debug('expanded sidebar width = ' + width);
expect(width > 180).to.be(true);
expect(width > 20).to.be(true);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_tile_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ bdd.describe('visualize app', function describeIndexTests() {
});
});

bdd.it('"Fit data bounds" should zoom to level 3', function pageHeader() {
bdd.it('Fit data bounds should zoom to level 3', function pageHeader() {
var expectedPrecision2ZoomCircles = [ { color: '#750000', radius: 192 },
{ color: '#750000', radius: 191 },
{ color: '#750000', radius: 177 },
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bdd.describe('visualize app', function () {

bdd.before(function () {
var self = this;
remote.setWindowSize(1200,800);
remote.setWindowSize(1280,800);

PageObjects.common.debug('Starting visualize before method');
var logstash = scenarioManager.loadIfEmpty('logstashFunctional');
Expand Down
25 changes: 21 additions & 4 deletions test/support/page_objects/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ import {
import util from 'util';

import getUrl from '../../utils/get_url';

import {
config,
defaultTryTimeout,
defaultFindTimeout,
remote,
shieldPage
shieldPage,
esClient
} from '../index';

import {
Log,
Try,
Try
} from '../utils';

const mkdirpAsync = promisify(mkdirp);
Expand Down Expand Up @@ -83,8 +85,23 @@ export default class Common {
function navigateTo(url) {
return self.try(function () {
// since we're using hash URLs, always reload first to force re-render
self.debug('navigate to: ' + url);
return self.remote.get(url)
return esClient.getDefaultIndex()
.then(function (defaultIndex) {
if (appName === 'discover' || appName === 'visualize' || appName === 'dashboard') {
if (!defaultIndex) {
// https://github.com/elastic/kibana/issues/7496
// Even though most tests are using esClient to set the default index, sometimes Kibana clobbers
// that change. If we got here, fix it.
self.debug(' >>>>>>>> WARNING Navigating to [' + appName + '] with defaultIndex=' + defaultIndex);
self.debug(' >>>>>>>> Setting defaultIndex to "logstash-*""');
return esClient.updateConfigDoc({'dateFormat:tz':'UTC', 'defaultIndex':'logstash-*'});
}
}
})
.then(function () {
self.debug('navigate to: ' + url);
return self.remote.get(url);
})
.then(function () {
return self.sleep(700);
})
Expand Down
25 changes: 20 additions & 5 deletions test/support/page_objects/discover_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export default class DiscoverPage {
return this.clickLoadSavedSearchButton()
.then(() => {
this.findTimeout.findByLinkText(searchName).click();
})
.then(() => {
return PageObjects.header.getSpinnerDone();
});
}

Expand Down Expand Up @@ -79,8 +82,11 @@ export default class DiscoverPage {
}

getBarChartData() {
return this.findTimeout
.findAllByCssSelector('rect[data-label="Count"]')
return PageObjects.header.getSpinnerDone()
.then(() => {
return this.findTimeout
.findAllByCssSelector('rect[data-label="Count"]');
})
.then(function (chartData) {

function getChartData(chart) {
Expand Down Expand Up @@ -128,13 +134,19 @@ export default class DiscoverPage {
return this.findTimeout
.findByCssSelector('option[label="' + interval + '"]')
.click();
})
.then(() => {
return PageObjects.header.getSpinnerDone();
});
}

getHitCount() {
return this.findTimeout
.findByCssSelector('strong.discover-info-hits')
.getVisibleText();
return PageObjects.header.getSpinnerDone()
.then(() => {
return this.findTimeout
.findByCssSelector('strong.discover-info-hits')
.getVisibleText();
});
}

query(queryString) {
Expand All @@ -146,6 +158,9 @@ export default class DiscoverPage {
return this.findTimeout
.findByCssSelector('button[aria-label="Search"]')
.click();
})
.then(() => {
return PageObjects.header.getSpinnerDone();
});
}

Expand Down
29 changes: 28 additions & 1 deletion test/support/utils/es_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,39 @@ export default (function () {
);
} else {
configId = response.hits.hits[0]._id;
Log.debug('config._id =' + configId);
Log.debug('config._id = ' + configId);
return configId;
}
});
},

/*
** Gets defaultIndex from the config doc.
*/
getDefaultIndex: function () {
var defaultIndex;

return this.client.search({
index: '.kibana',
type: 'config'
})
.then(function (response) {
if (response.errors) {
throw new Error(
'get config failed\n' +
response.items
.map(i => i[Object.keys(i)[0]].error)
.filter(Boolean)
.map(err => ' ' + JSON.stringify(err))
.join('\n')
);
} else {
defaultIndex = response.hits.hits[0]._source.defaultIndex;
Log.debug('config.defaultIndex = ' + defaultIndex);
return defaultIndex;
}
});
},

/**
* Add fields to the config doc (like setting timezone and defaultIndex)
Expand Down