-
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.
[APM] Refactoring service and transaction links (#86986)
* refactoring service and transaction links * refactoring links * addressing PR comments Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
f597119
commit 2d564dd
Showing
15 changed files
with
214 additions
and
113 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
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
87 changes: 87 additions & 0 deletions
87
...lugins/apm/public/components/shared/Links/apm/service_transactions_overview_link.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,87 @@ | ||
/* | ||
* 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 { render } from '@testing-library/react'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { createMemoryHistory } from 'history'; | ||
import React from 'react'; | ||
import { Router } from 'react-router-dom'; | ||
import { MockApmPluginContextWrapper } from '../../../../context/apm_plugin/mock_apm_plugin_context'; | ||
import { MockUrlParamsContextProvider } from '../../../../context/url_params_context/mock_url_params_context_provider'; | ||
import { | ||
ServiceOrTransactionsOverviewLink, | ||
useServiceOrTransactionsOverviewHref, | ||
} from './service_transactions_overview_link'; | ||
|
||
const history = createMemoryHistory(); | ||
|
||
function wrapper({ queryParams }: { queryParams?: Record<string, unknown> }) { | ||
return ({ children }: { children: React.ReactElement }) => ( | ||
<MockApmPluginContextWrapper> | ||
<Router history={history}> | ||
<MockUrlParamsContextProvider params={queryParams}> | ||
{children} | ||
</MockUrlParamsContextProvider> | ||
</Router> | ||
</MockApmPluginContextWrapper> | ||
); | ||
} | ||
|
||
describe('Service or transactions overview link', () => { | ||
describe('useServiceOrTransactionsOverviewHref', () => { | ||
it('returns service link', () => { | ||
const { result } = renderHook( | ||
() => useServiceOrTransactionsOverviewHref('foo'), | ||
{ wrapper: wrapper({}) } | ||
); | ||
expect(result.current).toEqual('/basepath/app/apm/services/foo'); | ||
}); | ||
|
||
it('returns service link with persisted query items', () => { | ||
const { result } = renderHook( | ||
() => useServiceOrTransactionsOverviewHref('foo'), | ||
{ wrapper: wrapper({ queryParams: { latencyAggregationType: 'avg' } }) } | ||
); | ||
expect(result.current).toEqual( | ||
'/basepath/app/apm/services/foo?latencyAggregationType=avg' | ||
); | ||
}); | ||
}); | ||
describe('ServiceOrTransactionsOverviewLink', () => { | ||
function getHref(container: HTMLElement) { | ||
return ((container as HTMLDivElement).children[0] as HTMLAnchorElement) | ||
.href; | ||
} | ||
it('returns service link', () => { | ||
const Component = wrapper({}); | ||
const { container } = render( | ||
<Component> | ||
<ServiceOrTransactionsOverviewLink serviceName="foo"> | ||
Service name | ||
</ServiceOrTransactionsOverviewLink> | ||
</Component> | ||
); | ||
expect(getHref(container)).toEqual( | ||
'http://localhost/basepath/app/apm/services/foo' | ||
); | ||
}); | ||
|
||
it('returns service link with persisted query items', () => { | ||
const Component = wrapper({ | ||
queryParams: { latencyAggregationType: 'avg' }, | ||
}); | ||
const { container } = render( | ||
<Component> | ||
<ServiceOrTransactionsOverviewLink serviceName="foo"> | ||
Service name | ||
</ServiceOrTransactionsOverviewLink> | ||
</Component> | ||
); | ||
expect(getHref(container)).toEqual( | ||
'http://localhost/basepath/app/apm/services/foo?latencyAggregationType=avg' | ||
); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.