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 29, 2021
1 parent ef9fc2a commit 470199e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 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.setTime({ from, to });
await PageObjects.common.navigateToApp('discover');
await PageObjects.discover.waitUntilSearchingHasFinished();
if (interval) {
await PageObjects.discover.setChartInterval(interval);
Expand Down
22 changes: 1 addition & 21 deletions test/functional/page_objects/common_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import expect from '@kbn/expect';
// @ts-ignore
import fetch from 'node-fetch';
import { getUrl } from '@kbn/test';
import moment from 'moment';
import { FtrService } from '../ftr_provider_context';

interface NavigateProps {
Expand Down Expand Up @@ -503,30 +502,11 @@ export class CommonPageObject extends FtrService {
}
}

formatTime(time: TimeStrings, fmt: string = 'MMM D, YYYY @ HH:mm:ss.SSS') {
return Object.keys(time)
.map((x) => moment(time[x], [fmt]).format())
.reduce(
(acc, curr, idx) => {
if (idx === 0) acc.from = curr;
acc.to = curr;
return acc;
},
{ from: '', to: '' }
);
}

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

async unsetTime() {
await this.kibanaServer.uiSettings.unset('timepicker:timeDefaults');
}
}
export interface TimeStrings extends Record<string, any> {
from: string;
to: string;
}

0 comments on commit 470199e

Please sign in to comment.