-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba9bf3d
commit 6486856
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
x-pack/plugins/reporting/server/lib/screenshots/get_render_error.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 = ` | ||
<renderedSelector data-render-error="a test error" /> | ||
<renderedSelector data-render-error="a test error" /> | ||
<renderedSelector data-render-error="a test error" /> | ||
<renderedSelector data-render-error="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([]); | ||
}); | ||
}); |