forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Reporting] Add new
data-render-error
attribute (elastic#114472)
* added new data-render-error attribute, read it and store it on job object * added data-render-error to the example app * added jest test * address pr feedback - make renderErrors optional in interfaces - create separate selectors for data render error selector/attr - Tidy up mergeMap behaviour * fix observable.test.ts snapshots and browser driver mock * updated jest snapshots Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
1a14d5c
commit b3f1973
Showing
14 changed files
with
191 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
x-pack/plugins/reporting/server/lib/screenshots/get_render_errors.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* 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 { HeadlessChromiumDriver } from '../../browsers'; | ||
import { | ||
createMockBrowserDriverFactory, | ||
createMockConfig, | ||
createMockConfigSchema, | ||
createMockLayoutInstance, | ||
createMockLevelLogger, | ||
createMockReportingCore, | ||
} from '../../test_helpers'; | ||
import { CaptureConfig } from '../../types'; | ||
import { LayoutInstance } from '../layouts'; | ||
import { LevelLogger } from '../level_logger'; | ||
import { getRenderErrors } from './get_render_errors'; | ||
|
||
describe('getRenderErrors', () => { | ||
let captureConfig: CaptureConfig; | ||
let layout: LayoutInstance; | ||
let logger: jest.Mocked<LevelLogger>; | ||
let browser: HeadlessChromiumDriver; | ||
|
||
beforeEach(async () => { | ||
const schema = createMockConfigSchema(); | ||
const config = createMockConfig(schema); | ||
const core = await createMockReportingCore(schema); | ||
|
||
captureConfig = config.get('capture'); | ||
layout = createMockLayoutInstance(captureConfig); | ||
logger = createMockLevelLogger(); | ||
|
||
await createMockBrowserDriverFactory(core, logger, { | ||
evaluate: jest.fn( | ||
async <T extends (...args: unknown[]) => unknown>({ | ||
fn, | ||
args, | ||
}: { | ||
fn: T; | ||
args: Parameters<T>; | ||
}) => fn(...args) | ||
), | ||
getCreatePage: (driver) => { | ||
browser = driver; | ||
|
||
return jest.fn(); | ||
}, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
document.body.innerHTML = ''; | ||
}); | ||
|
||
it('should extract the error messages', async () => { | ||
document.body.innerHTML = ` | ||
<div dataRenderErrorSelector="a test error" /> | ||
<div dataRenderErrorSelector="a test error" /> | ||
<div dataRenderErrorSelector="a test error" /> | ||
<div dataRenderErrorSelector="a test error" /> | ||
`; | ||
|
||
await expect(getRenderErrors(browser, layout, logger)).resolves.toEqual([ | ||
'a test error', | ||
'a test error', | ||
'a test error', | ||
'a test error', | ||
]); | ||
}); | ||
|
||
it('should extract the error messages, even when there are none', async () => { | ||
document.body.innerHTML = ` | ||
<renderedSelector /> | ||
`; | ||
|
||
await expect(getRenderErrors(browser, layout, logger)).resolves.toEqual(undefined); | ||
}); | ||
}); |
53 changes: 53 additions & 0 deletions
53
x-pack/plugins/reporting/server/lib/screenshots/get_render_errors.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
import type { HeadlessChromiumDriver } from '../../browsers'; | ||
import type { LayoutInstance } from '../layouts'; | ||
import { LevelLogger, startTrace } from '../'; | ||
import { CONTEXT_GETRENDERERRORS } from './constants'; | ||
|
||
export const getRenderErrors = async ( | ||
browser: HeadlessChromiumDriver, | ||
layout: LayoutInstance, | ||
logger: LevelLogger | ||
): Promise<undefined | string[]> => { | ||
const endTrace = startTrace('get_render_errors', 'read'); | ||
logger.debug('reading render errors'); | ||
const errorsFound: undefined | string[] = await browser.evaluate( | ||
{ | ||
fn: (errorSelector, errorAttribute) => { | ||
const visualizations: Element[] = Array.from(document.querySelectorAll(errorSelector)); | ||
const errors: string[] = []; | ||
|
||
visualizations.forEach((visualization) => { | ||
const errorMessage = visualization.getAttribute(errorAttribute); | ||
if (errorMessage) { | ||
errors.push(errorMessage); | ||
} | ||
}); | ||
|
||
return errors.length ? errors : undefined; | ||
}, | ||
args: [layout.selectors.renderError, layout.selectors.renderErrorAttribute], | ||
}, | ||
{ context: CONTEXT_GETRENDERERRORS }, | ||
logger | ||
); | ||
endTrace(); | ||
|
||
if (errorsFound?.length) { | ||
logger.warning( | ||
i18n.translate('xpack.reporting.screencapture.renderErrorsFound', { | ||
defaultMessage: 'Found {count} error messages. See report object for more information.', | ||
values: { count: errorsFound.length }, | ||
}) | ||
); | ||
} | ||
|
||
return errorsFound; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters