Skip to content

Commit

Permalink
[QA][refactor] Use ui settings - sample data (#114530)
Browse files Browse the repository at this point in the history
  • Loading branch information
wayneseymour authored Oct 19, 2021
1 parent f6a9afe commit c1b0565
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
21 changes: 9 additions & 12 deletions test/functional/apps/home/_sample_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

after(async () => {
await security.testUser.restoreDefaults();
await PageObjects.common.unsetTime();
});

it('should display registered flights sample data sets', async () => {
Expand Down Expand Up @@ -74,6 +75,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

describe('dashboard', () => {
beforeEach(async () => {
await time();
await PageObjects.common.navigateToUrl('home', '/tutorial_directory/sampleData', {
useActualUrl: true,
});
Expand All @@ -84,10 +86,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.home.launchSampleDashboard('flights');
await PageObjects.header.waitUntilLoadingHasFinished();
await renderable.waitForRender();
const todayYearMonthDay = moment().format('MMM D, YYYY');
const fromTime = `${todayYearMonthDay} @ 00:00:00.000`;
const toTime = `${todayYearMonthDay} @ 23:59:59.999`;
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.be(17);
});
Expand All @@ -112,10 +110,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.home.launchSampleDashboard('logs');
await PageObjects.header.waitUntilLoadingHasFinished();
await renderable.waitForRender();
const todayYearMonthDay = moment().format('MMM D, YYYY');
const fromTime = `${todayYearMonthDay} @ 00:00:00.000`;
const toTime = `${todayYearMonthDay} @ 23:59:59.999`;
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.be(13);
});
Expand All @@ -124,10 +118,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.home.launchSampleDashboard('ecommerce');
await PageObjects.header.waitUntilLoadingHasFinished();
await renderable.waitForRender();
const todayYearMonthDay = moment().format('MMM D, YYYY');
const fromTime = `${todayYearMonthDay} @ 00:00:00.000`;
const toTime = `${todayYearMonthDay} @ 23:59:59.999`;
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.be(15);
});
Expand Down Expand Up @@ -160,5 +150,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(isInstalled).to.be(false);
});
});

async function time() {
const today = moment().format('MMM D, YYYY');
const from = `${today} @ 00:00:00.000`;
const to = `${today} @ 23:59:59.999`;
await PageObjects.common.setTime({ from, to });
}
});
}
9 changes: 9 additions & 0 deletions test/functional/page_objects/common_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class CommonPageObject extends FtrService {
private readonly globalNav = this.ctx.getService('globalNav');
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly loginPage = this.ctx.getPageObject('login');
private readonly kibanaServer = this.ctx.getService('kibanaServer');

private readonly defaultTryTimeout = this.config.get('timeouts.try');
private readonly defaultFindTimeout = this.config.get('timeouts.find');
Expand Down Expand Up @@ -500,4 +501,12 @@ export class CommonPageObject extends FtrService {
await this.testSubjects.exists(validator);
}
}

async setTime(time: { from: string; to: string }) {
await this.kibanaServer.uiSettings.replace({ 'timepicker:timeDefaults': JSON.stringify(time) });
}

async unsetTime() {
await this.kibanaServer.uiSettings.unset('timepicker:timeDefaults');
}
}

0 comments on commit c1b0565

Please sign in to comment.