-
Notifications
You must be signed in to change notification settings - Fork 8k
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
[SR] Component integration tests #36871
[SR] Component integration tests #36871
Conversation
Pinging @elastic/es-ui |
💔 Build Failed |
💔 Build Failed |
💔 Build Failed |
plugins: AppPlugins | ||
): Promise<void> => { | ||
render(<ReactApp core={core} plugins={plugins} />, elem); | ||
export const renderReact = async (elem: Element, core: AppCore, plugins: AppPlugins) => { |
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.
Instead of providing the dependencies through props, I made it through a Provider component. This made is easier to test as I could wrap the component under test with this Providers
Component.
export const useAppDependencies = () => useContext<AppDependencies>(DependenciesContext); | ||
export const setAppDependencies = (deps: AppDependencies) => { | ||
DependenciesContext = createContext<AppDependencies>(deps); | ||
return DependenciesContext.Provider; |
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.
Create the context and return the Provider for it.
@@ -30,7 +30,7 @@ export const sendRequest = async ({ | |||
try { | |||
const response = await httpService.httpClient[method](path, body); | |||
|
|||
if (!response.data) { | |||
if (typeof response.data === 'undefined') { |
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.
Had to change this as a 200 response with empty string ''
was taken as an error.
@@ -44,7 +44,7 @@ export const sendRequest = async ({ | |||
}; | |||
} catch (e) { | |||
return { | |||
error: e, | |||
error: e.response ? e.response : e, |
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.
Had to change this as the mocked error is under a "response" property.
}; | ||
|
||
const clickSnapshotAt = async (index: number) => { | ||
const { rows } = testBed.table.getMetaData(SNAPSHOT_TABLE); |
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.
nit: destructure testBed
const { table, router, component } = testBed
expect(exists('reloadButton')).toBe(true); | ||
|
||
await act(async () => { | ||
find('reloadButton').simulate('click'); |
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.
what do you think about adding this to the helpers file?
|
||
expect(server.requests.length).toBe(totalRequests + 1); | ||
expect(server.requests[server.requests.length - 1].url).toBe( | ||
'/api/snapshot_restore/repositories' |
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.
nit: you could import the API_BASE_PATH
const and use it here
${API_BASE_PATH}repositories
const repositoryName = rows[0].columns[1].value; | ||
|
||
expect(latestRequest.method).toBe('DELETE'); | ||
expect(latestRequest.url).toBe(`/api/snapshot_restore/repositories/${repositoryName}`); |
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.
same here
expect(find('repositoryDetail.title').text()).toEqual(repo1.name); | ||
}); | ||
|
||
test('should show a loading while fetching the repository', async () => { |
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.
nit: missing word here? maybe should show a loading state...
form.selectCheckBox('compressToggle'); | ||
|
||
const error = { | ||
statusCode: 400, |
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.
looks like setSaveRepositoryResponse
is actually checking for status
not statusCode
export const nextTick = (time = 0) => new Promise(resolve => setTimeout(resolve, time)); | ||
|
||
export const getRandomNumber = (range: { min: number; max: number } = { min: 1, max: 20 }) => |
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.
nit: should the getRandomString
util be added to this file as well, rather than in strings.ts
?
x-pack/test_utils/testbed/testbed.ts
Outdated
const navigateTo = (_url: string) => { | ||
const url = | ||
_url[0] === '#' | ||
? _url.replace('#', '') // remove the begging hash as the memory router does not understand them |
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.
nit: type begging
---> beginning
💔 Build Failed |
💔 Build Failed |
💔 Build Failed |
Version 0.19.0 has breaking change and does not work with the Sinon mock server Issue: axios/axios#2195
…_component_integration
💔 Build Failed |
retest |
💔 Build Failed |
This reverts commit 5ac4098.
💚 Build Succeeded |
@jen-huang @alisonelizabeth I have made the CR changes suggested. Could you have another look at the PR? Cheers! 😊 |
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.
Changes LGTM
💚 Build Succeeded |
This PR adds the component integration tests for Snapshot Repositories app.
While doing the tests I also updated the client side validation of the repository name and updated the Chrome extension to take into account all the different access paths to a DOM node.
E.g. Before, it only returned either the complete path or the leaf.
'grandParent.parent.child'
or'child'
Now it returns all the combination to access a node
'grandParent.parent.child'
,'grandParent.child'
,'grandParent.parent'
'parent.child'
&'child'
There is also now a "depth" config in the extension to limit the nested paths returned. 95% of the time a "parent -> child" access is enough to target a dom node.
Run the tests locally
In order to run the 3 component integration jest files, we need the latest react version
16.9.0
which is currently in alpha release. This next version brings asynchronous to theact()
method which is needed to test our "hooked" components...Dependencies
For now, in order to run the tests, make the following modifications in the package.json
root package.json
"react": "^16.8.0"
--->"react": "16.9.0-alpha.0"
"react-dom": "^16.8.0"
--->"react-dom": "16.9.0-alpha.0"
x-pack package.json
"react": "^16.8.0"
--->"react": "16.9.0-alpha.0"
"react-dom": "^16.8.0"
--->"react-dom": "16.9.0-alpha.0"
And then run
yarn install
in each folder.This implies that the CI will never turn green until we don't upgrade to
16.9.0
.Another note about dependencies: when running the tests we get the warning
Warning: componentWillMount is deprecated and will be removed in the next major version (...) Please update the following components: MemoryRouter, Route, Router, Switch
. Updating to react-routerv5.0.0
(which is backward compatible) removes the warning.... but break 3 of our apps (remote clusters, ccr and rollups) as they depend on the non-official old "Context" to access the router. The fix should not be too complex but maybe other plugins have the same issue and we probably want to make sure all our plugins are compatible withreact-router v5
and allow ourselves updating to react17.0.0
when needed (I know, this won't happen tomorrow 😊).@jen-huang @silne30 ready to review!
CC @elastic/kibana-platform for the dependencies note .
@elastic/kibana-qa team for a preview on what we'll discuss
@alisonelizabeth as you might use this as a starting point to test watcher.