Skip to content

Commit

Permalink
Make sure async functions are awaited on.
Browse files Browse the repository at this point in the history
  • Loading branch information
stacey-gammon committed Jul 25, 2017
1 parent 72390a8 commit 5aade92
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 67 deletions.
15 changes: 6 additions & 9 deletions test/functional/apps/management/_creation_form_changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ export default function ({ getService, getPageObjects }) {
});
});

it('should enable creation after selecting time field', function () {
it('should enable creation after selecting time field', async function () {
// select a time field and check that Create button is enabled
return PageObjects.settings.selectTimeFieldOption('@timestamp')
.then(function () {
return PageObjects.settings.getCreateButton().isEnabled()
.then(function (enabled) {
screenshots.take('Settings-indices-enable-creation');
expect(enabled).to.be.ok();
});
});
await PageObjects.settings.selectTimeFieldOption('@timestamp');
const createButton = await PageObjects.settings.getCreateButton();
const enabled = await createButton.isEnabled();
screenshots.take('Settings-indices-enable-creation');
expect(enabled).to.be.ok();
});
});
}
11 changes: 5 additions & 6 deletions test/functional/apps/management/_index_pattern_create_delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ export default function ({ getService, getPageObjects }) {
.then(id => indexPatternId = id);
});

it('should have index pattern in page header', function () {
return PageObjects.settings.getIndexPageHeading().getVisibleText()
.then(function (patternName) {
screenshots.take('Settings-indices-new-index-pattern');
expect(patternName).to.be('logstash-*');
});
it('should have index pattern in page header', async function () {
const indexPageHeading = await PageObjects.settings.getIndexPageHeading();
const patternName = await indexPageHeading.getVisibleText();
screenshots.take('Settings-indices-new-index-pattern');
expect(patternName).to.be('logstash-*');
});

it('should have index pattern in url', function url() {
Expand Down
29 changes: 13 additions & 16 deletions test/functional/apps/management/_initial_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,25 @@ export default function ({ getService, getPageObjects }) {
});
});

it('should contain default index pattern', function () {
it('should contain default index pattern', async function () {
const defaultPattern = 'logstash-*';

return PageObjects.settings.getIndexPatternField().getProperty('value')
.then(function (pattern) {
expect(pattern).to.be(defaultPattern);
});
const indexPatternField = await PageObjects.settings.getIndexPatternField();
const pattern = await indexPatternField.getProperty('value');
expect(pattern).to.be(defaultPattern);
});

it('should not select the time field', function () {
return PageObjects.settings.getTimeFieldNameField().isSelected()
.then(function (timeFieldIsSelected) {
log.debug('timeField isSelected = ' + timeFieldIsSelected);
expect(timeFieldIsSelected).to.not.be.ok();
});
it('should not select the time field', async function () {
const timeFieldNameField = await PageObjects.settings.getTimeFieldNameField();
const timeFieldIsSelected = await timeFieldNameField.isSelected();
log.debug('timeField isSelected = ' + timeFieldIsSelected);
expect(timeFieldIsSelected).to.not.be.ok();
});

it('should not enable creation', function () {
return PageObjects.settings.getCreateIndexPatternButton().isEnabled()
.then(function (enabled) {
expect(enabled).to.not.be.ok();
});
it('should not enable creation', async function () {
const createIndexPatternButton = await PageObjects.settings.getCreateIndexPatternButton();
const enabled = await createIndexPatternButton.isEnabled();
expect(enabled).to.not.be.ok();
});
});
}
17 changes: 7 additions & 10 deletions test/functional/page_objects/dashboard_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,15 @@ export function DashboardPageProvider({ getService, getPageObjects }) {
});
}

getPanelTitles() {
async getPanelTitles() {
log.debug('in getPanelTitles');
return testSubjects.findAll('dashboardPanelTitle')
.then(function (titleObjects) {

function getTitles(chart) {
return chart.getVisibleText();
}
const titleObjects = await testSubjects.findAll('dashboardPanelTitle');

const getTitlePromises = titleObjects.map(getTitles);
return Promise.all(getTitlePromises);
});
function getTitles(chart) {
return chart.getVisibleText();
}
const getTitlePromises = titleObjects.map(getTitles);
return Promise.all(getTitlePromises);
}

async getDashboardPanels() {
Expand Down
8 changes: 4 additions & 4 deletions test/functional/page_objects/discover_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ export function DiscoverPageProvider({ getService, getPageObjects }) {
return await testSubjects.exists('discoverNoResults');
}

getNoResultsTimepicker() {
return testSubjects.find('discoverNoResultsTimefilter');
async getNoResultsTimepicker() {
return await testSubjects.find('discoverNoResultsTimefilter');
}

hasNoResultsTimepicker() {
Expand All @@ -240,8 +240,8 @@ export function DiscoverPageProvider({ getService, getPageObjects }) {
.catch(() => false);
}

clickFieldListItem(field) {
return testSubjects.click(`field-${field}`);
async clickFieldListItem(field) {
return await testSubjects.click(`field-${field}`);
}

async clickFieldListItemAdd(field) {
Expand Down
45 changes: 25 additions & 20 deletions test/functional/page_objects/settings_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export function SettingsPageProvider({ getService, getPageObjects }) {
const retry = getService('retry');
const config = getService('config');
const remote = getService('remote');
const find = getService('find');
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects(['header', 'common']);

Expand Down Expand Up @@ -61,40 +62,43 @@ export function SettingsPageProvider({ getService, getPageObjects }) {
await PageObjects.common.navigateToApp('settings');
}

getIndexPatternField() {
return testSubjects.find('createIndexPatternNameInput');
async getIndexPatternField() {
return await testSubjects.find('createIndexPatternNameInput');
}

getTimeFieldNameField() {
return testSubjects.find('createIndexPatternTimeFieldSelect');
async clickTimeFieldNameField() {
return await testSubjects.click('createIndexPatternTimeFieldSelect');
}

async getTimeFieldNameField() {
return await testSubjects.find('createIndexPatternTimeFieldSelect');
}

async selectTimeFieldOption(selection) {
// open dropdown
(await this.getTimeFieldNameField()).click();
await this.clickTimeFieldNameField();
// close dropdown, keep focus
(await this.getTimeFieldNameField()).click();
await this.clickTimeFieldNameField();
await PageObjects.header.waitUntilLoadingHasFinished();
await retry.try(async () => {
return await retry.try(async () => {
log.debug(`selectTimeFieldOption(${selection})`);
(await this.getTimeFieldOption(selection)).click();
const selected = (await this.getTimeFieldOption(selection)).isSelected();
const timeFieldOption = await this.getTimeFieldOption(selection);
await timeFieldOption.click();
const selected = await timeFieldOption.isSelected();
if (!selected) throw new Error('option not selected: ' + selected);
});
}

getTimeFieldOption(selection) {
return remote.setFindTimeout(defaultFindTimeout)
.findDisplayedByCssSelector('option[label="' + selection + '"]');
async getTimeFieldOption(selection) {
return await find.displayedByCssSelector('option[label="' + selection + '"]');
}

getCreateIndexPatternButton() {
return testSubjects.find('createIndexPatternCreateButton');
async getCreateIndexPatternButton() {
return await testSubjects.find('createIndexPatternCreateButton');
}

getCreateButton() {
return remote.setFindTimeout(defaultFindTimeout)
.findDisplayedByCssSelector('[type="submit"]');
async getCreateButton() {
return await find.displayedByCssSelector('[type="submit"]');
}

async clickDefaultIndexButton() {
Expand All @@ -106,8 +110,8 @@ export function SettingsPageProvider({ getService, getPageObjects }) {
await testSubjects.click('deleteIndexPatternButton');
}

getIndexPageHeading() {
return testSubjects.find('indexPatternTitle');
async getIndexPageHeading() {
return await testSubjects.find('indexPatternTitle');
}

getConfigureHeader() {
Expand Down Expand Up @@ -274,7 +278,8 @@ export function SettingsPageProvider({ getService, getPageObjects }) {
await this.clickKibanaIndices();
await this.setIndexPatternField(indexPatternName);
await this.selectTimeFieldOption(timefield);
await this.getCreateButton().click();
const createButton = await this.getCreateButton();
await createButton.click();
});
await PageObjects.header.waitUntilLoadingHasFinished();
await retry.try(async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/functional/services/doc_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export function DocTableProvider({ getService }) {
const testSubjects = getService('testSubjects');

class DocTable {
getTable() {
return testSubjects.find('docTable');
async getTable() {
return await testSubjects.find('docTable');
}

async getBodyRows(table) {
Expand Down

0 comments on commit 5aade92

Please sign in to comment.