[QA][refactor] cleanup discover test, add time format fn (#116617) (#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 <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Tre <wayne.seymour@elastic.co>
This commit is contained in:
Kibana Machine 2021-11-03 13:50:37 -04:00 committed by GitHub
parent e474a5dbd1
commit 04ad4948de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 6 deletions

View file

@ -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';

View file

@ -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 {
@ -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;
}