Skip to content

Commit

Permalink
Merge pull request #6 from w33ble/functional-tests-settings-bdd
Browse files Browse the repository at this point in the history
Functional tests switched to bdd syntax
  • Loading branch information
w33ble committed Nov 3, 2015
2 parents 1213afe + d42f54b commit 77103b0
Show file tree
Hide file tree
Showing 17 changed files with 694 additions and 664 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ target
.idea
*.iml
*.log
screenshot*.png
/esvm
.htpasswd
.eslintcache
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/__tests__/scenarioManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('scenario manager', function () {
});


it('should load if the index is empty', function () {
it('should not load if the index is not empty', function () {
var load = sinon.stub(manager, 'load', Promise.resolve);
var returnOne = sinon.stub(manager.client, 'count', function () {
return Promise.resolve({
Expand Down
38 changes: 20 additions & 18 deletions test/fixtures/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ var path = require('path');
var rootDir = path.join(__dirname, 'scenarios');

module.exports = {
makelogs: {
baseDir: path.join(rootDir, 'makelogs'),
bulk: [{
indexDefinition: 'makelogsIndexDefinition.js',
indexName: 'logstash-2015.09.17',
source: 'logstash-2015.09.17.js'
}, {
indexDefinition: 'makelogsIndexDefinition.js',
indexName: 'logstash-2015.09.18',
source: 'logstash-2015.09.18.js'
}]
},
emptyKibana: {
baseDir: path.join(rootDir, 'emptyKibana'),
bulk: [{
indexName: '.kibana',
source: 'kibana.js'
}]
scenarios: {
makelogs: {
baseDir: path.join(rootDir, 'makelogs'),
bulk: [{
indexDefinition: 'makelogsIndexDefinition.js',
indexName: 'logstash-2015.09.17',
source: 'logstash-2015.09.17.js'
}, {
indexDefinition: 'makelogsIndexDefinition.js',
indexName: 'logstash-2015.09.18',
source: 'logstash-2015.09.18.js'
}]
},
emptyKibana: {
baseDir: path.join(rootDir, 'emptyKibana'),
bulk: [{
indexName: '.kibana',
source: 'kibana.js'
}]
}
}
};
3 changes: 1 addition & 2 deletions test/fixtures/scenarioManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var path = require('path');
var config = require('./config');
var config = require('./config').scenarios;
var elasticsearch = require('elasticsearch');

function ScenarioManager(server) {
Expand Down Expand Up @@ -37,7 +37,6 @@ ScenarioManager.prototype.load = function (id) {
body: require(path.join(scenario.baseDir, bulk.source)),
});
});

}));
};

Expand Down
37 changes: 37 additions & 0 deletions test/functional/apps/settings/_create_button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
define(function (require) {
var Common = require('../../../support/pages/Common');
var SettingsPage = require('../../../support/pages/SettingsPage');
var expect = require('intern/dojo/node!expect.js');

return function (bdd) {
bdd.describe('create button states', function () {
var common;
var settingsPage;

bdd.before(function () {
common = new Common(this.remote);
settingsPage = new SettingsPage(this.remote);
});

bdd.it('should not be initially enabled', function () {
return settingsPage.getCreateButton().isEnabled()
.then(function (enabled) {
expect(enabled).to.not.be.ok();
})
.catch(common.handleError(this));
});

bdd.it('should be enabled after selecting time field option', function () {
// select a time field and check that Create button is enabled
return settingsPage.selectTimeFieldOption('@timestamp')
.then(function () {
return settingsPage.getCreateButton().isEnabled()
.then(function (enabled) {
expect(enabled).to.be.ok();
});
})
.catch(common.handleError(this));
});
});
};
});
109 changes: 109 additions & 0 deletions test/functional/apps/settings/_index_pattern_create_delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
define(function (require) {
var Common = require('../../../support/pages/Common');
var SettingsPage = require('../../../support/pages/SettingsPage');
var expect = require('intern/dojo/node!expect.js');
var Promise = require('bluebird');

return function (bdd) {
bdd.describe('creating and deleting default index', function describeIndexTests() {
var common;
var settingsPage;
var remote;

bdd.before(function () {
common = new Common(this.remote);
settingsPage = new SettingsPage(this.remote);
remote = this.remote;
});


bdd.describe('index pattern creation', function indexPatternCreation() {
bdd.beforeEach(function be() {
return settingsPage.createIndex();
});

bdd.afterEach(function ae() {
var expectedAlertText = 'Are you sure you want to remove this index pattern?';
return settingsPage.removeIndex()
.then(function (alertText) {
expect(alertText).to.be(expectedAlertText);
});
});

bdd.it('should have index pattern in page header', function pageHeader() {
return settingsPage.getIndexPageHeading().getVisibleText()
.then(function (patternName) {
expect(patternName).to.be('logstash-*');
})
.catch(common.handleError(this));
});

bdd.it('should have index pattern in url', function url() {
return common.tryForTime(5000, function () {
return remote.getCurrentUrl()
.then(function (currentUrl) {
expect(currentUrl).to.contain('logstash-*');
});
})
.catch(common.handleError(this));
});

bdd.it('should have expected table headers', function checkingHeader() {
return settingsPage.getTableHeader()
.then(function (headers) {
var expectedHeaders = [
'name',
'type',
'format',
'analyzed',
'indexed',
'controls'
];

// 6 name type format analyzed indexed controls
expect(headers.length).to.be(expectedHeaders.length);

var comparedHeaders = headers.map(function compareHead(header, i) {
return header.getVisibleText()
.then(function (text) {
expect(text).to.be(expectedHeaders[i]);
});
});

return Promise.all(comparedHeaders);
})
.catch(common.handleError(this));
});
});


bdd.describe('index pattern deletion', function indexDelete() {

bdd.beforeEach(function be() {
return settingsPage.createIndex()
.then(function () {
return settingsPage.removeIndex();
});
});

bdd.it('should return to index pattern creation page', function returnToPage() {
return common.tryForTime(5000, function () {
return settingsPage.getCreateButton();
})
.catch(common.handleError(this));
});

bdd.it('should remove index pattern from url', function indexNotInUrl() {
return common.tryForTime(3000, function () {
return remote.getCurrentUrl()
.then(function (currentUrl) {
expect(currentUrl).to.not.contain('logstash-*');
});
})
.catch(common.handleError(this));
});
});

});
};
});
109 changes: 109 additions & 0 deletions test/functional/apps/settings/_index_pattern_popularity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
define(function (require) {
var Common = require('../../../support/pages/Common');
var SettingsPage = require('../../../support/pages/SettingsPage');
var expect = require('intern/dojo/node!expect.js');
//var Promise = require('bluebird');

return function (bdd) {
bdd.describe('index result popularity', function describeIndexTests() {
var common;
var settingsPage;
var remote;

bdd.before(function () {
common = new Common(this.remote);
settingsPage = new SettingsPage(this.remote);
remote = this.remote;
});

bdd.beforeEach(function be() {
return settingsPage.createIndex();
});

bdd.afterEach(function ae() {
return settingsPage.removeIndex();
});

bdd.describe('change popularity', function indexPatternCreation() {
var fieldName = 'geo.coordinates';

// set the page size to All again, https://github.com/elastic/kibana/issues/5030
// TODO: remove this after #5030 is closed
function fix5030() {
return settingsPage.setPageSize('All')
.then(function () {
return common.sleep(1000);
});
}

bdd.beforeEach(function () {
// increase Popularity of geo.coordinates
return settingsPage.setPageSize('All')
.then(function () {
return common.sleep(1000);
})
.then(function openControlsByName() {
return settingsPage.openControlsByName(fieldName);
})
.then(function increasePopularity() {
return settingsPage.increasePopularity();
});
});

bdd.afterEach(function () {
// Cancel saving the popularity change (we didn't make a change in this case, just checking the value)
return settingsPage.controlChangeCancel();
});

bdd.it('should update the popularity input', function () {
return settingsPage.getPopularity()
.then(function (popularity) {
expect(popularity).to.be('1');
})
.catch(common.handleError(this));
});

bdd.it('should be reset on cancel', function pageHeader() {
// Cancel saving the popularity change

return settingsPage.controlChangeCancel()
.then(function () {
return fix5030();
})
.then(function openControlsByName() {
return settingsPage.openControlsByName(fieldName);
})
// check that its 0 (previous increase was cancelled)
.then(function getPopularity() {
return settingsPage.getPopularity()
})
.then(function (popularity) {
expect(popularity).to.be('0');
})
.catch(common.handleError(this));
});

bdd.it('can be saved', function pageHeader() {
// Saving the popularity change
return settingsPage.controlChangeSave()
.then(function () {
return fix5030();
})
.then(function openControlsByName() {
return settingsPage.openControlsByName(fieldName);
})
// check that its 0 (previous increase was cancelled)
.then(function getPopularity() {
return settingsPage.getPopularity();
})
.then(function (popularity) {
expect(popularity).to.be('1');
})
.catch(common.handleError(this));
});

}); // end 'change popularity'

}); // end index result popularity
};
});
Loading

0 comments on commit 77103b0

Please sign in to comment.