Skip to content

Commit

Permalink
[QA][refactor] Use ui settings - discover histogram
Browse files Browse the repository at this point in the history
Use ui settings instead of setting absolute range
for timepicker.

Stacked on top of: #114530
  • Loading branch information
wayneseymour committed Oct 14, 2021
1 parent 1939f98 commit 2952863
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 33 deletions.
6 changes: 4 additions & 2 deletions test/functional/apps/discover/_discover_histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
'test/functional/fixtures/es_archiver/long_window_logstash_index_pattern'
);
await security.testUser.restoreDefaults();
await PageObjects.common.unsetTime();
});

async function prepareTest(fromTime: string, toTime: string, interval?: string) {
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
async function prepareTest(from: string, to: string, interval?: string) {
await PageObjects.common.time({ from, to });
await PageObjects.common.navigateToApp('discover');
await PageObjects.discover.waitUntilSearchingHasFinished();
if (interval) {
await PageObjects.discover.setChartInterval(interval);
Expand Down
43 changes: 12 additions & 31 deletions test/functional/apps/home/_sample_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const renderable = getService('renderable');
const dashboardExpect = getService('dashboardExpect');
const PageObjects = getPageObjects(['common', 'header', 'home', 'dashboard', 'timePicker']);
const kibanaServer = getService('kibanaServer');

interface UrlData {
appName: string;
subUrl: string;
opts: { useActualUrl: boolean };
}
const timeAndNav = (range: { from: string; to: string }) => (urlData: UrlData) => async () => {
await kibanaServer.uiSettings.replace({ 'timepicker:timeDefaults': JSON.stringify(range) });
await nav(urlData);

async function nav(urlObj: UrlData) {
const { appName, subUrl, opts } = urlObj;
const { useActualUrl } = opts;
await PageObjects.common.navigateToUrl(appName, subUrl, { useActualUrl });
}
};

const today = moment().format('MMM D, YYYY');
const from = `${today} @ 00:00:00.000`;
const to = `${today} @ 23:59:59.999`;

const navToday = timeAndNav({ from, to })({
appName: 'home',
subUrl: '/tutorial_directory/sampleData',
opts: { useActualUrl: true },
});

describe('sample data', function describeIndexTests() {
before(async () => {
Expand All @@ -58,7 +31,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

after(async () => {
await security.testUser.restoreDefaults();
await kibanaServer.uiSettings.unset('timepicker:timeDefaults');
await PageObjects.common.unsetTime();
});

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

it('should launch sample flights data set dashboard', async () => {
await navToday();
await timeNav();
await PageObjects.home.launchSampleDashboard('flights');
await PageObjects.header.waitUntilLoadingHasFinished();
await renderable.waitForRender();
Expand All @@ -134,7 +107,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});

it('should launch sample logs data set dashboard', async () => {
await navToday();
await timeNav();
await PageObjects.home.launchSampleDashboard('logs');
await PageObjects.header.waitUntilLoadingHasFinished();
await renderable.waitForRender();
Expand All @@ -143,7 +116,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});

it('should launch sample ecommerce data set dashboard', async () => {
await navToday();
await timeNav();
await PageObjects.home.launchSampleDashboard('ecommerce');
await PageObjects.header.waitUntilLoadingHasFinished();
await renderable.waitForRender();
Expand Down Expand Up @@ -179,5 +152,13 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(isInstalled).to.be(false);
});
});

async function timeNav() {
const today = moment().format('MMM D, YYYY');
const from = `${today} @ 00:00:00.000`;
const to = `${today} @ 23:59:59.999`;
await PageObjects.common.time({ from, to });
await PageObjects.common.navigateToApp('discover');
}
});
}
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 time(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 2952863

Please sign in to comment.