-
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.
[Synthetics] Check if license management plugin is enabled before lin…
…king (#178773) ## Summary Resolves #153030. Essentially, we add `licenseManagement` as an optional dep, and check if it's enabled before we link to it. --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
2f24c45
commit 5fbae0a
Showing
6 changed files
with
76 additions
and
5 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
57 changes: 57 additions & 0 deletions
57
...ility_solution/synthetics/public/apps/synthetics/hooks/use_synthetics_priviliges.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,57 @@ | ||
/* | ||
* 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 { renderHook } from '@testing-library/react-hooks'; | ||
import React from 'react'; | ||
import { render, WrappedHelper } from '../utils/testing'; | ||
import { useSyntheticsPrivileges } from './use_synthetics_priviliges'; | ||
|
||
jest.mock('../../../hooks/use_capabilities', () => ({ | ||
useCanReadSyntheticsIndex: jest.fn().mockReturnValue({ canRead: true, loading: false }), | ||
})); | ||
|
||
jest.mock('react-redux', () => { | ||
const actual = jest.requireActual('react-redux'); | ||
return { | ||
...actual, | ||
useSelector: jest.fn().mockReturnValue({ error: { body: { message: 'License not active' } } }), | ||
}; | ||
}); | ||
|
||
function wrapper({ children }: { children: React.ReactElement }) { | ||
return <WrappedHelper>{children}</WrappedHelper>; | ||
} | ||
|
||
describe('useSyntheticsPrivileges', () => { | ||
it.each([ | ||
[true, null], | ||
[false, ''], | ||
])( | ||
'should correctly set the disabled prop of the license nav button if `licenseManagement` enabled is %s', | ||
(enabled, expectedDisabledAttribute) => { | ||
const { | ||
result: { current }, | ||
} = renderHook(() => useSyntheticsPrivileges(), { wrapper }); | ||
|
||
expect(current).not.toBeUndefined(); | ||
|
||
const { getByLabelText } = render(current!, { | ||
core: { | ||
licenseManagement: { enabled }, | ||
}, | ||
}); | ||
|
||
const licenseNavButton = getByLabelText('Navigate to license management'); | ||
|
||
expect(licenseNavButton); | ||
|
||
// there should only be an href if the license management is enabled, otherwise we render a disabled button with no handler | ||
expect(!!licenseNavButton.getAttribute('href')).toEqual(enabled); | ||
expect(licenseNavButton.getAttribute('disabled')).toEqual(expectedDisabledAttribute); | ||
} | ||
); | ||
}); |
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