Skip to content

Commit

Permalink
stabilize listing page object (elastic#66564) (elastic#66882)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored May 18, 2020
1 parent 6f57df4 commit a0ee6df
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 95 deletions.
19 changes: 3 additions & 16 deletions test/functional/apps/dashboard/dashboard_clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ export default function({ getService, getPageObjects }) {
await PageObjects.dashboard.clickClone();
await PageObjects.dashboard.confirmClone();
await PageObjects.dashboard.gotoDashboardLandingPage();
const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
clonedDashboardName
);

expect(countOfDashboards).to.equal(1);
await listingTable.searchAndExpectItemsCount('dashboard', clonedDashboardName, 1);
});

it('the copy should have all the same visualizations', async function() {
Expand Down Expand Up @@ -75,11 +70,7 @@ export default function({ getService, getPageObjects }) {
await PageObjects.dashboard.cancelClone();
await PageObjects.dashboard.gotoDashboardLandingPage();

const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
dashboardName
);
expect(countOfDashboards).to.equal(1);
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 1);
});

it('Clones on confirm duplicate title warning', async function() {
Expand All @@ -92,11 +83,7 @@ export default function({ getService, getPageObjects }) {
await PageObjects.dashboard.waitForRenderComplete();
await PageObjects.dashboard.gotoDashboardLandingPage();

const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
dashboardName + ' Copy'
);
expect(countOfDashboards).to.equal(2);
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName + ' Copy', 2);
});
});
}
42 changes: 10 additions & 32 deletions test/functional/apps/dashboard/dashboard_listing.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ export default function({ getService, getPageObjects }) {
await PageObjects.dashboard.saveDashboard(dashboardName);

await PageObjects.dashboard.gotoDashboardLandingPage();
const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
dashboardName
);
expect(countOfDashboards).to.equal(1);
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 1);
});

it('is not shown when there is a dashboard', async function() {
Expand All @@ -55,11 +51,7 @@ export default function({ getService, getPageObjects }) {
});

it('is not shown when there are no dashboards shown during a search', async function() {
const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
'gobeldeguck'
);
expect(countOfDashboards).to.equal(0);
await listingTable.searchAndExpectItemsCount('dashboard', 'gobeldeguck', 0);

const promptExists = await PageObjects.dashboard.getCreateDashboardPromptExists();
expect(promptExists).to.be(false);
Expand All @@ -78,11 +70,7 @@ export default function({ getService, getPageObjects }) {

await PageObjects.common.expectConfirmModalOpenState(false);

const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
dashboardName
);
expect(countOfDashboards).to.equal(1);
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 1);
});

it('succeeds on confirmation press', async function() {
Expand All @@ -91,11 +79,7 @@ export default function({ getService, getPageObjects }) {

await PageObjects.common.clickConfirmOnModal();

const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
dashboardName
);
expect(countOfDashboards).to.equal(0);
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 0);
});
});

Expand All @@ -109,38 +93,32 @@ export default function({ getService, getPageObjects }) {

it('matches on the first word', async function() {
await listingTable.searchForItemWithName('Two');
const countOfDashboards = await listingTable.getItemsCount('dashboard');
expect(countOfDashboards).to.equal(1);
await listingTable.expectItemsCount('dashboard', 1);
});

it('matches the second word', async function() {
await listingTable.searchForItemWithName('Words');
const countOfDashboards = await listingTable.getItemsCount('dashboard');
expect(countOfDashboards).to.equal(1);
await listingTable.expectItemsCount('dashboard', 1);
});

it('matches the second word prefix', async function() {
await listingTable.searchForItemWithName('Wor');
const countOfDashboards = await listingTable.getItemsCount('dashboard');
expect(countOfDashboards).to.equal(1);
await listingTable.expectItemsCount('dashboard', 1);
});

it('does not match mid word', async function() {
await listingTable.searchForItemWithName('ords');
const countOfDashboards = await listingTable.getItemsCount('dashboard');
expect(countOfDashboards).to.equal(0);
await listingTable.expectItemsCount('dashboard', 0);
});

it('is case insensitive', async function() {
await listingTable.searchForItemWithName('two words');
const countOfDashboards = await listingTable.getItemsCount('dashboard');
expect(countOfDashboards).to.equal(1);
await listingTable.expectItemsCount('dashboard', 1);
});

it('is using AND operator', async function() {
await listingTable.searchForItemWithName('three words');
const countOfDashboards = await listingTable.getItemsCount('dashboard');
expect(countOfDashboards).to.equal(0);
await listingTable.expectItemsCount('dashboard', 0);
});
});

Expand Down
20 changes: 3 additions & 17 deletions test/functional/apps/dashboard/dashboard_save.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

import expect from '@kbn/expect';

export default function({ getPageObjects, getService }) {
const PageObjects = getPageObjects(['dashboard', 'header']);
const listingTable = getService('listingTable');
Expand Down Expand Up @@ -50,11 +48,7 @@ export default function({ getPageObjects, getService }) {
await PageObjects.dashboard.cancelSave();
await PageObjects.dashboard.gotoDashboardLandingPage();

const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
dashboardName
);
expect(countOfDashboards).to.equal(1);
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 1);
});

it('Saves on confirm duplicate title warning', async function() {
Expand All @@ -73,11 +67,7 @@ export default function({ getPageObjects, getService }) {
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.dashboard.gotoDashboardLandingPage();

const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
dashboardName
);
expect(countOfDashboards).to.equal(2);
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 2);
});

it('Does not warn when you save an existing dashboard with the title it already has, and that title is a duplicate', async function() {
Expand Down Expand Up @@ -128,11 +118,7 @@ export default function({ getPageObjects, getService }) {
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.dashboard.gotoDashboardLandingPage();

const countOfDashboards = await listingTable.searchAndGetItemsCount(
'dashboard',
dashboardNameEnterKey
);
expect(countOfDashboards).to.equal(1);
await listingTable.searchAndExpectItemsCount('dashboard', dashboardNameEnterKey, 1);
});
});
}
29 changes: 9 additions & 20 deletions test/functional/apps/visualize/_visualize_listing.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

import expect from '@kbn/expect';

export default function({ getService, getPageObjects }) {
const PageObjects = getPageObjects(['visualize', 'visEditor']);
const listingTable = getService('listingTable');
Expand All @@ -37,21 +35,18 @@ export default function({ getService, getPageObjects }) {
// type markdown is used for simplicity
await PageObjects.visualize.createSimpleMarkdownViz(vizName);
await PageObjects.visualize.gotoVisualizationLandingPage();
const visCount = await listingTable.getItemsCount('visualize');
expect(visCount).to.equal(1);
await listingTable.expectItemsCount('visualize', 1);
});

it('delete all viz', async function() {
await PageObjects.visualize.createSimpleMarkdownViz(vizName + '1');
await PageObjects.visualize.createSimpleMarkdownViz(vizName + '2');
await PageObjects.visualize.gotoVisualizationLandingPage();

let visCount = await listingTable.getItemsCount('visualize');
expect(visCount).to.equal(3);
await listingTable.expectItemsCount('visualize', 3);

await PageObjects.visualize.deleteAllVisualizations();
visCount = await listingTable.getItemsCount('visualize');
expect(visCount).to.equal(0);
await listingTable.expectItemsCount('visualize', 0);
});
});

Expand All @@ -69,38 +64,32 @@ export default function({ getService, getPageObjects }) {

it('matches on the first word', async function() {
await listingTable.searchForItemWithName('Hello');
const itemCount = await listingTable.getItemsCount('visualize');
expect(itemCount).to.equal(1);
await listingTable.expectItemsCount('visualize', 1);
});

it('matches the second word', async function() {
await listingTable.searchForItemWithName('World');
const itemCount = await listingTable.getItemsCount('visualize');
expect(itemCount).to.equal(1);
await listingTable.expectItemsCount('visualize', 1);
});

it('matches the second word prefix', async function() {
await listingTable.searchForItemWithName('Wor');
const itemCount = await listingTable.getItemsCount('visualize');
expect(itemCount).to.equal(1);
await listingTable.expectItemsCount('visualize', 1);
});

it('does not match mid word', async function() {
await listingTable.searchForItemWithName('orld');
const itemCount = await listingTable.getItemsCount('visualize');
expect(itemCount).to.equal(0);
await listingTable.expectItemsCount('visualize', 0);
});

it('is case insensitive', async function() {
await listingTable.searchForItemWithName('hello world');
const itemCount = await listingTable.getItemsCount('visualize');
expect(itemCount).to.equal(1);
await listingTable.expectItemsCount('visualize', 1);
});

it('is using AND operator', async function() {
await listingTable.searchForItemWithName('hello banana');
const itemCount = await listingTable.getItemsCount('visualize');
expect(itemCount).to.equal(0);
await listingTable.expectItemsCount('visualize', 0);
});
});
});
Expand Down
29 changes: 19 additions & 10 deletions test/functional/services/listing_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../ftr_provider_context';

export function ListingTableProvider({ getService, getPageObjects }: FtrProviderContext) {
Expand Down Expand Up @@ -85,11 +86,13 @@ export function ListingTableProvider({ getService, getPageObjects }: FtrProvider
* Returns items count on landing page
* @param appName 'visualize' | 'dashboard'
*/
public async getItemsCount(appName: 'visualize' | 'dashboard'): Promise<number> {
const elements = await find.allByCssSelector(
`[data-test-subj^="${prefixMap[appName]}ListingTitleLink"]`
);
return elements.length;
public async expectItemsCount(appName: 'visualize' | 'dashboard', count: number) {
await retry.try(async () => {
const elements = await find.allByCssSelector(
`[data-test-subj^="${prefixMap[appName]}ListingTitleLink"]`
);
expect(elements.length).to.equal(count);
});
}

/**
Expand All @@ -116,12 +119,18 @@ export function ListingTableProvider({ getService, getPageObjects }: FtrProvider
* @param appName 'visualize' | 'dashboard'
* @param name item name
*/
public async searchAndGetItemsCount(appName: 'visualize' | 'dashboard', name: string) {
public async searchAndExpectItemsCount(
appName: 'visualize' | 'dashboard',
name: string,
count: number
) {
await this.searchForItemWithName(name);
const links = await testSubjects.findAll(
`${prefixMap[appName]}ListingTitleLink-${name.replace(/ /g, '-')}`
);
return links.length;
await retry.try(async () => {
const links = await testSubjects.findAll(
`${prefixMap[appName]}ListingTitleLink-${name.replace(/ /g, '-')}`
);
expect(links.length).to.equal(count);
});
}

public async clickDeleteSelected() {
Expand Down

0 comments on commit a0ee6df

Please sign in to comment.