forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
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
[APM] useFetcher (II): Add react-testing-library to better test hooks #11
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
62011f1
[APM] Add useFetcher to ServiceOverview, and add `react-testing-library`
sorenlouv 913fcee
Fix tests
sorenlouv 12571f5
Make spec descriptions more clear
sorenlouv 350b2fc
[APM] Add useFetcher to serviceDetailsView
sorenlouv 70c0fb6
Merge pull request #12 from sqren/use-fetcher-service-details-view
sorenlouv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
77 changes: 0 additions & 77 deletions
77
x-pack/plugins/apm/public/components/app/ServiceOverview/__test__/ServiceOverview.test.js
This file was deleted.
Oops, something went wrong.
132 changes: 132 additions & 0 deletions
132
x-pack/plugins/apm/public/components/app/ServiceOverview/__test__/ServiceOverview.test.tsx
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,132 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { render, wait, waitForElement } from 'react-testing-library'; | ||
import 'react-testing-library/cleanup-after-each'; | ||
import * as apmRestServices from 'x-pack/plugins/apm/public/services/rest/apm/services'; | ||
// @ts-ignore | ||
import configureStore from 'x-pack/plugins/apm/public/store/config/configureStore'; | ||
import * as statusCheck from '../../../../services/rest/apm/status_check'; | ||
import { ServiceOverview } from '../view'; | ||
|
||
function Comp() { | ||
const store = configureStore(); | ||
|
||
return ( | ||
<Provider store={store}> | ||
<ServiceOverview urlParams={{}} /> | ||
</Provider> | ||
); | ||
} | ||
|
||
describe('Service Overview -> View', () => { | ||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
// Suppress warnings about "act" until async/await syntax is supported: https://github.com/facebook/react/issues/14769 | ||
/* tslint:disable:no-console */ | ||
const originalError = console.error; | ||
beforeAll(() => { | ||
console.error = jest.fn(); | ||
}); | ||
afterAll(() => { | ||
console.error = originalError; | ||
}); | ||
|
||
it('should render services, when list is not empty', async () => { | ||
// mock rest requests | ||
const spy1 = jest | ||
.spyOn(statusCheck, 'loadAgentStatus') | ||
.mockResolvedValue(true); | ||
const spy2 = jest | ||
.spyOn(apmRestServices, 'loadServiceList') | ||
.mockResolvedValue([ | ||
{ | ||
serviceName: 'My Python Service', | ||
agentName: 'python', | ||
transactionsPerMinute: 100, | ||
errorsPerMinute: 200, | ||
avgResponseTime: 300 | ||
}, | ||
{ | ||
serviceName: 'My Go Service', | ||
agentName: 'go', | ||
transactionsPerMinute: 400, | ||
errorsPerMinute: 500, | ||
avgResponseTime: 600 | ||
} | ||
]); | ||
|
||
const { container, getByText } = render(<Comp />); | ||
|
||
// wait for requests to be made | ||
await wait( | ||
() => | ||
expect(spy1).toHaveBeenCalledTimes(1) && | ||
expect(spy2).toHaveBeenCalledTimes(1) | ||
); | ||
|
||
await waitForElement(() => getByText('My Python Service')); | ||
|
||
expect(container.querySelectorAll('.euiTableRow')).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render getting started message, when list is empty and no historical data is found', async () => { | ||
// mock rest requests | ||
const spy1 = jest | ||
.spyOn(statusCheck, 'loadAgentStatus') | ||
.mockResolvedValue(false); | ||
|
||
const spy2 = jest | ||
.spyOn(apmRestServices, 'loadServiceList') | ||
.mockResolvedValue([]); | ||
|
||
const { container, getByText } = render(<Comp />); | ||
|
||
// wait for requests to be made | ||
await wait( | ||
() => | ||
expect(spy1).toHaveBeenCalledTimes(1) && | ||
expect(spy2).toHaveBeenCalledTimes(1) | ||
); | ||
|
||
// wait for elements to be rendered | ||
await waitForElement(() => | ||
getByText( | ||
"Looks like you don't have any APM services installed. Let's add some!" | ||
) | ||
); | ||
|
||
expect(container.querySelectorAll('.euiTableRow')).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render empty message, when list is empty and historical data is found', async () => { | ||
// mock rest requests | ||
const spy1 = jest | ||
.spyOn(statusCheck, 'loadAgentStatus') | ||
.mockResolvedValue(true); | ||
const spy2 = jest | ||
.spyOn(apmRestServices, 'loadServiceList') | ||
.mockResolvedValue([]); | ||
|
||
const { container, getByText } = render(<Comp />); | ||
|
||
// wait for requests to be made | ||
await wait( | ||
() => | ||
expect(spy1).toHaveBeenCalledTimes(1) && | ||
expect(spy2).toHaveBeenCalledTimes(1) | ||
); | ||
|
||
// wait for elements to be rendered | ||
await waitForElement(() => getByText('No services found')); | ||
|
||
expect(container.querySelectorAll('.euiTableRow')).toMatchSnapshot(); | ||
}); | ||
}); | ||
43 changes: 0 additions & 43 deletions
43
...public/components/app/ServiceOverview/__test__/__snapshots__/ServiceOverview.test.js.snap
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm not by any means an expert in writing tests in this style, so feedback is welcome.