Skip to content

Commit

Permalink
[QA][refactor] cleanup discover test, add time format fn (#116617) (#…
Browse files Browse the repository at this point in the history
…117359)

* [QA][refactor] discover test

Drop two saved objects: search and idx pattern,
in the after method.

Add the formatting fn to the common page,
such that every time setTime is invoked, the time is
formatted to address: https://momentjs.com/guides/#/warnings/js-date/

* Add docs, per CR.

* Add docs, per CR.

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Tre <[email protected]>
  • Loading branch information
kibanamachine and wayneseymour authored Nov 3, 2021
1 parent e474a5d commit 04ad494
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
8 changes: 4 additions & 4 deletions test/functional/apps/discover/_discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
describe('discover test', function describeIndexTests() {
before(async function () {
log.debug('load kibana index with default index pattern');

await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover.json');

await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover');
// and load a set of makelogs data
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
await kibanaServer.uiSettings.replace(defaultSettings);
await PageObjects.common.navigateToApp('discover');
await PageObjects.timePicker.setDefaultAbsoluteRange();
});

after(async () => {
await kibanaServer.savedObjects.clean({ types: ['search', 'index-pattern'] });
});
describe('query', function () {
const queryName1 = 'Query # 1';

Expand Down
41 changes: 39 additions & 2 deletions test/functional/page_objects/common_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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 @@ -502,11 +503,47 @@ export class CommonPageObject extends FtrService {
}
}

async setTime(time: { from: string; to: string }) {
await this.kibanaServer.uiSettings.replace({ 'timepicker:timeDefaults': JSON.stringify(time) });
/**
* Due to a warning thrown, documented at:
* https://github.com/elastic/kibana/pull/114997#issuecomment-950823874
* this fn formats time in a format specified, or defaulted
* to the same format in
* [getTimeDurationInHours()](https://github.com/elastic/kibana/blob/main/test/functional/page_objects/time_picker.ts#L256)
* @param time
* @param fmt
*/
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: '' }
);
}

/**
* Previously, many tests were using the time picker.
* To speed things up, we are now setting time here.
* The formatting fn is called here, such that the tests
* that were using the time picker can use the same time
* parameters as before, but they are auto-formatted.
* @param time
*/
async setTime(time: TimeStrings) {
await this.kibanaServer.uiSettings.replace({
'timepicker:timeDefaults': JSON.stringify(this.formatTime(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 04ad494

Please sign in to comment.