mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
@maximpn brought up the issues caused by the types required by the rison-node package, which attempted to communicate that "encoded values must be primitive values, or recursive arrays/object of primitive values". This isn't actually expressible in TypeScript, which lead to many instances of `rison.encode(value as unknown as RisonValue)` which is useless. Additionally, the rison-node library actually supports any value and will either produce valid rison or `undefined` for that value. To address this I'm adding a wrapper function which accepts `any` and returns a `string`. If rison-node is totally unable to produce any rison for the value (because the value is `undefined` or some other type like Symbol or BigInt) the `encode()` function will throw. If you're accepting arbitrary input you can use the `encodeUnknown()` function, which will return a string or undefined, if the value you provided has zero rison representation. Like JSON.stringify() any non-circular primitive, object, or array can be encoded with either function. If the values within those objects are not encodable (functions, RegExps, etc) then they will be skipped. Any object/array with the `toJSON()` method will be converted to JSON first, and if the prototype of the object has the `encode_rison()` method it will be used to convert he value into rison. The changes in this PR are mostly updating usage of rison-node to use `@kbn/rison` (which is also enforced by eslint). There are also several changes which remove unnecessary casting.
98 lines
3.6 KiB
TypeScript
98 lines
3.6 KiB
TypeScript
/*
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
* Side Public License, v 1.
|
|
*/
|
|
|
|
import rison from '@kbn/rison';
|
|
import { getUrl } from '@kbn/test';
|
|
import { FtrService } from '../ftr_provider_context';
|
|
|
|
const DEFAULT_INITIAL_STATE = {
|
|
columns: ['@message'],
|
|
};
|
|
|
|
export class ContextPageObject extends FtrService {
|
|
private readonly browser = this.ctx.getService('browser');
|
|
private readonly config = this.ctx.getService('config');
|
|
private readonly retry = this.ctx.getService('retry');
|
|
private readonly testSubjects = this.ctx.getService('testSubjects');
|
|
private readonly header = this.ctx.getPageObject('header');
|
|
private readonly common = this.ctx.getPageObject('common');
|
|
private readonly log = this.ctx.getService('log');
|
|
|
|
public async navigateTo(indexPattern: string, anchorId: string, overrideInitialState = {}) {
|
|
const initialState = rison.encode({
|
|
...DEFAULT_INITIAL_STATE,
|
|
...overrideInitialState,
|
|
});
|
|
const contextHash = this.config.get('apps.context.hash');
|
|
const appUrl = getUrl.noAuth(this.config.get('servers.kibana'), {
|
|
...this.config.get('apps.context'),
|
|
hash: `${contextHash}/${indexPattern}/${anchorId}?_a=${initialState}`,
|
|
});
|
|
|
|
this.log.debug(`browser.get(${appUrl})`);
|
|
|
|
await this.browser.get(appUrl);
|
|
await this.header.awaitGlobalLoadingIndicatorHidden();
|
|
await this.waitUntilContextLoadingHasFinished();
|
|
// For lack of a better way, using a sleep to ensure page is loaded before proceeding
|
|
await this.common.sleep(1000);
|
|
}
|
|
|
|
public async getPredecessorCountPicker() {
|
|
return await this.testSubjects.find('predecessorsCountPicker');
|
|
}
|
|
|
|
public async getSuccessorCountPicker() {
|
|
return await this.testSubjects.find('successorsCountPicker');
|
|
}
|
|
|
|
public async getPredecessorLoadMoreButton() {
|
|
return await this.testSubjects.find('predecessorsLoadMoreButton');
|
|
}
|
|
|
|
public async getSuccessorLoadMoreButton() {
|
|
return await this.testSubjects.find('successorsLoadMoreButton');
|
|
}
|
|
|
|
public async clickPredecessorLoadMoreButton() {
|
|
this.log.debug('Click Predecessor Load More Button');
|
|
await this.retry.try(async () => {
|
|
const predecessorButton = await this.getPredecessorLoadMoreButton();
|
|
await predecessorButton.click();
|
|
});
|
|
await this.waitUntilContextLoadingHasFinished();
|
|
await this.header.waitUntilLoadingHasFinished();
|
|
}
|
|
|
|
public async clickSuccessorLoadMoreButton() {
|
|
this.log.debug('Click Successor Load More Button');
|
|
await this.retry.try(async () => {
|
|
const sucessorButton = await this.getSuccessorLoadMoreButton();
|
|
await sucessorButton.click();
|
|
});
|
|
await this.waitUntilContextLoadingHasFinished();
|
|
await this.header.waitUntilLoadingHasFinished();
|
|
}
|
|
|
|
public async waitUntilContextLoadingHasFinished() {
|
|
return await this.retry.try(async () => {
|
|
const successorLoadMoreButton = await this.getSuccessorLoadMoreButton();
|
|
const predecessorLoadMoreButton = await this.getPredecessorLoadMoreButton();
|
|
if (
|
|
!(
|
|
(await successorLoadMoreButton.isEnabled()) &&
|
|
(await successorLoadMoreButton.isDisplayed()) &&
|
|
(await predecessorLoadMoreButton.isEnabled()) &&
|
|
(await predecessorLoadMoreButton.isDisplayed())
|
|
)
|
|
) {
|
|
throw new Error('loading context rows');
|
|
}
|
|
});
|
|
}
|
|
}
|