-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Uptime] Tests/uptime testing utils #87650
Changes from 9 commits
69628a5
afea632
0ec06b0
97d57a6
3294340
05b0b6b
959c45e
48f1536
5ade268
8f8af46
ae7406b
abf0e25
edc7423
8cf3403
1866c29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -5,28 +5,17 @@ | |||
*/ | ||||
|
||||
import React from 'react'; | ||||
import { coreMock } from 'src/core/public/mocks'; | ||||
import { renderWithRouter, shallowWithRouter } from '../../../lib'; | ||||
import { render } from '../../../lib'; | ||||
import { MLJobLink } from './ml_job_link'; | ||||
import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public'; | ||||
|
||||
const core = coreMock.createStart(); | ||||
describe('ML JobLink', () => { | ||||
it('shallow renders without errors', () => { | ||||
const wrapper = shallowWithRouter( | ||||
<MLJobLink dateRange={{ to: '', from: '' }} basePath="" monitorId="testMonitor" /> | ||||
); | ||||
expect(wrapper).toMatchSnapshot(); | ||||
}); | ||||
|
||||
it('renders without errors', () => { | ||||
const wrapper = renderWithRouter( | ||||
<KibanaContextProvider | ||||
services={{ ...core, triggersActionsUi: { getEditAlertFlyout: jest.fn() } }} | ||||
> | ||||
<MLJobLink dateRange={{ to: '', from: '' }} basePath="" monitorId="testMonitor" /> | ||||
</KibanaContextProvider> | ||||
const { asFragment } = render( | ||||
<MLJobLink dateRange={{ to: '', from: '' }} basePath="" monitorId="testMonitor" />, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an example where we needed to extend the core options. You can do so by passing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unable to figure out why this component needed to call |
||||
{ | ||||
coreOptions: { triggersActionsUi: { getEditAlertFlyout: jest.fn() } }, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think the test will succeed without this when we migrate to RTL. See revision in 8e35b6b. |
||||
} | ||||
); | ||||
expect(wrapper).toMatchSnapshot(); | ||||
expect(asFragment()).toMatchSnapshot(); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only changes this to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can improve this even more and remove the need for What do you think of 9728d3a? We're essentially testing the user-facing features of the component; specifically we ensure our text is displayed and the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's perfect. I wasn't sure how to format that full url lol. |
||||
}); | ||||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
import React from 'react'; | ||
import { ExecutedStep } from './executed_step'; | ||
import { Ping } from '../../../../common/runtime_types'; | ||
import { mountWithRouter } from '../../../lib'; | ||
import { mountWithRouter, render } from '../../../lib'; | ||
|
||
// FLAKY: https://github.com/elastic/kibana/issues/85899 | ||
describe.skip('ExecutedStep', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to cherry-pick this change to a separate branch and revert it here, since we're going to need to get approval to close the issue before we can remove the skip. I'm fine with keeping the test revision below since they're all skipped in |
||
|
@@ -35,32 +35,9 @@ describe.skip('ExecutedStep', () => { | |
}); | ||
|
||
it('renders correct step heading', () => { | ||
expect( | ||
mountWithRouter(<ExecutedStep index={3} step={step} checkGroup={'fake-group'} />).find( | ||
'EuiText' | ||
) | ||
).toMatchInlineSnapshot(` | ||
<EuiText> | ||
<div | ||
className="euiText euiText--medium" | ||
> | ||
<strong> | ||
<FormattedMessage | ||
defaultMessage="{stepNumber}. {stepName}" | ||
id="xpack.uptime.synthetics.executedStep.stepName" | ||
values={ | ||
Object { | ||
"stepName": "STEP_NAME", | ||
"stepNumber": 4, | ||
} | ||
} | ||
> | ||
4. STEP_NAME | ||
</FormattedMessage> | ||
</strong> | ||
</div> | ||
</EuiText> | ||
`); | ||
const { getByText } = render(<ExecutedStep index={3} step={step} checkGroup={'fake-group'} />); | ||
|
||
expect(getByText(`${step?.synthetics?.step?.index}. ${step?.synthetics?.step?.name}`)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is exactly what I was hoping to achieve when we talked about this test. It tests the same thing in a much cleaner format. |
||
}); | ||
|
||
it('renders a link to the step detail view', () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,7 @@ import { ChromeBreadcrumb } from 'kibana/public'; | |
import React from 'react'; | ||
import { Route } from 'react-router-dom'; | ||
import { of } from 'rxjs'; | ||
import { MountWithReduxProvider, mountWithRouter } from '../../../../lib'; | ||
import { KibanaContextProvider } from '../../../../../../../../src/plugins/kibana_react/public'; | ||
import { render } from '../../../../lib'; | ||
import { useMonitorBreadcrumb } from './use_monitor_breadcrumb'; | ||
import { OVERVIEW_ROUTE } from '../../../../../common/constants'; | ||
import { Ping } from '../../../../../common/runtime_types/ping'; | ||
|
@@ -27,14 +26,11 @@ describe('useMonitorBreadcrumbs', () => { | |
return <>Step Water Fall</>; | ||
}; | ||
|
||
mountWithRouter( | ||
<MountWithReduxProvider> | ||
<KibanaContextProvider services={{ ...core }}> | ||
<Route path={OVERVIEW_ROUTE}> | ||
<Component /> | ||
</Route> | ||
</KibanaContextProvider> | ||
</MountWithReduxProvider> | ||
render( | ||
<Route path={OVERVIEW_ROUTE}> | ||
<Component /> | ||
</Route>, | ||
{ kibanaProps: { services: { ...core } } } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an example of overwriting the entire Kibana context core. This is useful in this context to get access to a function for getting the breadcrumbs out of core. |
||
); | ||
|
||
expect(getBreadcrumbs()).toMatchInlineSnapshot(` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I noticed in practice when testing this out was my editor had some issue loading the typings for this function. Is this happening for you? When I edited the path to do a direct import it worked. I can't figure out why this would be a code-related problem, but I'm curious if it's happening with others.
Specifically, I didn't get any intellisense in VS Code for the
asFragment
function returned byrender
.We've had some issues with these types of import chains in the past. Not saying we should mandate always doing direct imports for this helper, but it might be helpful for some.