forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Obs Alerting] View in apm button - add defensive code (elastic#184236)
## Summary Resolves elastic#184204 The page can break when the share plugin is undefined. This PR adds defensive code to prevent errors when `share` is undefined. ![image](https://github.com/elastic/kibana/assets/11356435/538a73e1-e8b5-4743-8a01-f723695dcf86) ![image](https://github.com/elastic/kibana/assets/11356435/4a3a606e-4aa0-4aed-a644-83cdf3965dbd) ### Testing Generate some mock APM data with ```node scripts/synthtrace.js simple_trace --live``` Create an APM latency rule Wait for the rule to be triggered, then navigate to the alert details page The alert details page should load properly
- Loading branch information
1 parent
61a28e7
commit 107075c
Showing
6 changed files
with
56 additions
and
12 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
49 changes: 49 additions & 0 deletions
49
...c/components/alerting/ui_components/alert_details_app_section/view_in_apm_button.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,49 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { ViewInAPMButton } from './view_in_apm_button'; | ||
import * as apmContext from '../../../../context/apm_plugin/use_apm_plugin_context'; | ||
|
||
describe('ViewInApmButton', () => { | ||
const config = { | ||
serviceName: 'testService', | ||
environment: 'testEnvironment', | ||
transactionName: 'testTransaction', | ||
transactionType: 'testTransactionType', | ||
from: 'now-15m', | ||
to: 'now', | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('hides button when share plugin is not available', () => { | ||
const { queryByText } = render(<ViewInAPMButton {...config} />); | ||
|
||
expect(queryByText('View in APM')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('reners correctly', () => { | ||
jest.spyOn(apmContext, 'useApmPluginContext').mockReturnValue({ | ||
share: { | ||
url: { | ||
locators: { | ||
// @ts-ignore | ||
get: () => ({ | ||
navigate: jest.fn(), | ||
}), | ||
}, | ||
}, | ||
}, | ||
}); | ||
const { getByText } = render(<ViewInAPMButton {...config} />); | ||
|
||
expect(getByText('View in APM')).toBeInTheDocument(); | ||
}); | ||
}); |
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