mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Reporting] Fix missing force now behaviour for v2 reports (#114516)
* fix missing force now behaviour for v2 reports * added jest test * updated jest test snapshot to match removal of forceNow injection from locator params Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
4f89393124
commit
afe81bb1a2
8 changed files with 60 additions and 36 deletions
|
@ -12,7 +12,6 @@ export { omitBlockedHeaders } from './omit_blocked_headers';
|
|||
export { validateUrls } from './validate_urls';
|
||||
export { generatePngObservableFactory } from './generate_png';
|
||||
export { getCustomLogo } from './get_custom_logo';
|
||||
export { setForceNow } from './set_force_now';
|
||||
|
||||
export interface TimeRangeParams {
|
||||
min?: Date | string | number | null;
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* 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; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { LocatorParams } from '../../../common/types';
|
||||
|
||||
/**
|
||||
* Add `forceNow` to {@link LocatorParams['params']} to enable clients to set the time appropriately when
|
||||
* reporting navigates to the page in Chromium.
|
||||
*/
|
||||
export const setForceNow =
|
||||
(forceNow: string) =>
|
||||
(locator: LocatorParams): LocatorParams => {
|
||||
return {
|
||||
...locator,
|
||||
params: {
|
||||
...locator.params,
|
||||
forceNow,
|
||||
},
|
||||
};
|
||||
};
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { get } from 'lodash';
|
||||
import { ReportingConfig } from '../../../config/config';
|
||||
import { getFullRedirectAppUrl } from './get_full_redirect_app_url';
|
||||
|
||||
describe('getFullRedirectAppUrl', () => {
|
||||
let config: ReportingConfig;
|
||||
|
||||
beforeEach(() => {
|
||||
const values = {
|
||||
server: {
|
||||
basePath: 'test',
|
||||
},
|
||||
kibanaServer: {
|
||||
protocol: 'http',
|
||||
hostname: 'localhost',
|
||||
port: '1234',
|
||||
},
|
||||
};
|
||||
config = {
|
||||
get: jest.fn((...args: string[]) => get(values, args)),
|
||||
kbnConfig: {
|
||||
get: jest.fn((...args: string[]) => get(values, args)),
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
test('smoke test', () => {
|
||||
expect(getFullRedirectAppUrl(config, 'test', undefined)).toBe(
|
||||
'http://localhost:1234/test/s/test/app/management/insightsAndAlerting/reporting/r'
|
||||
);
|
||||
});
|
||||
|
||||
test('adding forceNow', () => {
|
||||
expect(getFullRedirectAppUrl(config, 'test', 'TEST with a space')).toBe(
|
||||
'http://localhost:1234/test/s/test/app/management/insightsAndAlerting/reporting/r?forceNow=TEST%20with%20a%20space'
|
||||
);
|
||||
});
|
||||
});
|
|
@ -10,7 +10,11 @@ import { ReportingConfig } from '../../..';
|
|||
import { getRedirectAppPath } from '../../../../common/constants';
|
||||
import { buildKibanaPath } from '../../../../common/build_kibana_path';
|
||||
|
||||
export function getFullRedirectAppUrl(config: ReportingConfig, spaceId?: string) {
|
||||
export function getFullRedirectAppUrl(
|
||||
config: ReportingConfig,
|
||||
spaceId?: string,
|
||||
forceNow?: string
|
||||
) {
|
||||
const [basePath, protocol, hostname, port] = [
|
||||
config.kbnConfig.get('server', 'basePath'),
|
||||
config.get('kibanaServer', 'protocol'),
|
||||
|
@ -29,5 +33,6 @@ export function getFullRedirectAppUrl(config: ReportingConfig, spaceId?: string)
|
|||
hostname,
|
||||
port,
|
||||
pathname: path,
|
||||
query: forceNow ? { forceNow } : undefined,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -102,12 +102,10 @@ test(`passes browserTimezone to generatePng`, async () => {
|
|||
"warning": [Function],
|
||||
},
|
||||
Array [
|
||||
"localhost:80undefined/app/management/insightsAndAlerting/reporting/r",
|
||||
"localhost:80undefined/app/management/insightsAndAlerting/reporting/r?forceNow=test",
|
||||
Object {
|
||||
"id": "test",
|
||||
"params": Object {
|
||||
"forceNow": "test",
|
||||
},
|
||||
"params": Object {},
|
||||
"version": "test",
|
||||
},
|
||||
],
|
||||
|
|
|
@ -16,7 +16,6 @@ import {
|
|||
getConditionalHeaders,
|
||||
omitBlockedHeaders,
|
||||
generatePngObservableFactory,
|
||||
setForceNow,
|
||||
} from '../common';
|
||||
import { getFullRedirectAppUrl } from '../common/v2/get_full_redirect_app_url';
|
||||
import { TaskPayloadPNGV2 } from './types';
|
||||
|
@ -38,8 +37,8 @@ export const runTaskFnFactory: RunTaskFnFactory<RunTaskFn<TaskPayloadPNGV2>> =
|
|||
map((decryptedHeaders) => omitBlockedHeaders(decryptedHeaders)),
|
||||
map((filteredHeaders) => getConditionalHeaders(config, filteredHeaders)),
|
||||
mergeMap((conditionalHeaders) => {
|
||||
const url = getFullRedirectAppUrl(config, job.spaceId);
|
||||
const [locatorParams] = job.locatorParams.map(setForceNow(job.forceNow));
|
||||
const url = getFullRedirectAppUrl(config, job.spaceId, job.forceNow);
|
||||
const [locatorParams] = job.locatorParams;
|
||||
|
||||
apmGetAssets?.end();
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ import {
|
|||
getConditionalHeaders,
|
||||
omitBlockedHeaders,
|
||||
getCustomLogo,
|
||||
setForceNow,
|
||||
} from '../common';
|
||||
import { generatePdfObservableFactory } from './lib/generate_pdf';
|
||||
import { TaskPayloadPDFV2 } from './types';
|
||||
|
@ -50,7 +49,7 @@ export const runTaskFnFactory: RunTaskFnFactory<RunTaskFn<TaskPayloadPDFV2>> =
|
|||
jobLogger,
|
||||
job,
|
||||
title,
|
||||
locatorParams.map(setForceNow(job.forceNow)),
|
||||
locatorParams,
|
||||
browserTimezone,
|
||||
conditionalHeaders,
|
||||
layout,
|
||||
|
|
|
@ -56,7 +56,10 @@ export async function generatePdfObservableFactory(reporting: ReportingCore) {
|
|||
/**
|
||||
* For each locator we get the relative URL to the redirect app
|
||||
*/
|
||||
const urls = locatorParams.map(() => getFullRedirectAppUrl(reporting.getConfig(), job.spaceId));
|
||||
const urls = locatorParams.map(() =>
|
||||
getFullRedirectAppUrl(reporting.getConfig(), job.spaceId, job.forceNow)
|
||||
);
|
||||
|
||||
const screenshots$ = getScreenshots$(captureConfig, browserDriverFactory, {
|
||||
logger,
|
||||
urlsOrUrlLocatorTuples: zip(urls, locatorParams) as UrlOrUrlLocatorTuple[],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue