Skip to content

Commit

Permalink
Use concrete assertions, not exists (elastic#23271) (elastic#23392)
Browse files Browse the repository at this point in the history
  • Loading branch information
stacey-gammon authored Sep 24, 2018
1 parent b3778f9 commit 5cbc278
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
3 changes: 1 addition & 2 deletions test/functional/apps/dashboard/_dashboard_clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ export default function ({ getService, getPageObjects }) {

it('and warns on duplicate name', async function () {
await PageObjects.dashboard.confirmClone();
const isWarningDisplayed = await PageObjects.dashboard.isDuplicateTitleWarningDisplayed();
expect(isWarningDisplayed).to.equal(true);
await PageObjects.dashboard.expectDuplicateTitleWarningDisplayed({ displayed: true });
});

it('and doesn\'t save', async () => {
Expand Down
25 changes: 7 additions & 18 deletions test/functional/apps/dashboard/_dashboard_save.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

import expect from 'expect.js';

export default function ({ getService, getPageObjects }) {
const retry = getService('retry');
export default function ({ getPageObjects }) {
const PageObjects = getPageObjects(['dashboard', 'header']);

describe('dashboard save', function describeIndexTests() {
Expand All @@ -38,15 +37,12 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.dashboard.clickNewDashboard();
await PageObjects.dashboard.saveDashboard(dashboardName);

let isWarningDisplayed = await PageObjects.dashboard.isDuplicateTitleWarningDisplayed();
expect(isWarningDisplayed).to.equal(false);
await PageObjects.dashboard.expectDuplicateTitleWarningDisplayed({ displayed: false });

await PageObjects.dashboard.gotoDashboardLandingPage();
await PageObjects.dashboard.clickNewDashboard();
await PageObjects.dashboard.enterDashboardTitleAndClickSave(dashboardName);

isWarningDisplayed = await PageObjects.dashboard.isDuplicateTitleWarningDisplayed();
expect(isWarningDisplayed).to.equal(true);
await PageObjects.dashboard.expectDuplicateTitleWarningDisplayed({ displayed: true });
});

it('does not save on reject confirmation', async function () {
Expand Down Expand Up @@ -79,37 +75,30 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.dashboard.switchToEditMode();
await PageObjects.dashboard.saveDashboard(dashboardName);

const isWarningDisplayed = await PageObjects.dashboard.isDuplicateTitleWarningDisplayed();
expect(isWarningDisplayed).to.equal(false);
await PageObjects.dashboard.expectDuplicateTitleWarningDisplayed({ displayed: false });
}
);

it('Warns you when you Save as New Dashboard, and the title is a duplicate', async function () {
await PageObjects.dashboard.switchToEditMode();
await PageObjects.dashboard.enterDashboardTitleAndClickSave(dashboardName, { saveAsNew: true });

const isWarningDisplayed = await PageObjects.dashboard.isDuplicateTitleWarningDisplayed();
expect(isWarningDisplayed).to.equal(true);
await PageObjects.dashboard.expectDuplicateTitleWarningDisplayed({ displayed: true });

await PageObjects.dashboard.cancelSave();
});

it('Does not warn when only the prefix matches', async function () {
await PageObjects.dashboard.saveDashboard(dashboardName.split(' ')[0]);

const isWarningDisplayed = await PageObjects.dashboard.isDuplicateTitleWarningDisplayed();
expect(isWarningDisplayed).to.equal(false);
await PageObjects.dashboard.expectDuplicateTitleWarningDisplayed({ displayed: false });
});

it('Warns when case is different', async function () {
await PageObjects.dashboard.switchToEditMode();
await PageObjects.dashboard.enterDashboardTitleAndClickSave(dashboardName.toUpperCase());

// We expect isWarningDisplayed to be open, hence the retry if not found.
await retry.try(async () => {
const isWarningDisplayed = await PageObjects.dashboard.isDuplicateTitleWarningDisplayed();
expect(isWarningDisplayed).to.equal(true);
});
await PageObjects.dashboard.expectDuplicateTitleWarningDisplayed({ displayed: true });

await PageObjects.dashboard.cancelSave();
});
Expand Down
12 changes: 10 additions & 2 deletions test/functional/page_objects/dashboard_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,16 @@ export function DashboardPageProvider({ getService, getPageObjects }) {
await testSubjects.setValue('clonedDashboardTitle', title);
}

async isDuplicateTitleWarningDisplayed() {
return await testSubjects.exists('titleDupicateWarnMsg');
/**
* Asserts that the duplicate title warning is either displayed or not displayed.
* @param { displayed: boolean }
*/
async expectDuplicateTitleWarningDisplayed({ displayed }) {
if (displayed) {
await testSubjects.existOrFail('titleDupicateWarnMsg');
} else {
await testSubjects.missingOrFail('titleDupicateWarnMsg');
}
}

async switchToEditMode() {
Expand Down

0 comments on commit 5cbc278

Please sign in to comment.