-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/npm_and_yarn/main/testing-library…
…/react-16.0.0
- Loading branch information
Showing
16 changed files
with
421 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Build and Push to Greenbone Registry | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
tags: ["v*"] | ||
pull_request: | ||
branches: [ main ] | ||
workflow_dispatch: | ||
inputs: | ||
ref-name: | ||
type: string | ||
description: "The ref to build a container image from. For example a tag v23.0.0." | ||
required: true | ||
|
||
jobs: | ||
build: | ||
name: Build and Push to Greenbone Registry | ||
uses: greenbone/workflows/.github/workflows/container-build-push-2nd-gen.yml@main | ||
with: | ||
image-url: community/gsa | ||
image-labels: | | ||
org.opencontainers.image.vendor=Greenbone | ||
org.opencontainers.image.base.name=greenbone/gsad | ||
ref-name: ${{ inputs.ref-name }} | ||
secrets: inherit |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* SPDX-FileCopyrightText: 2024 Greenbone AG | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import PropTypes from 'prop-types'; | ||
|
||
import {Route, Redirect} from 'react-router-dom'; | ||
import useCapabilities from 'web/hooks/useCapabilities'; | ||
|
||
const ConditionalRoute = ({component: Component, feature, ...rest}) => { | ||
const capabilities = useCapabilities(); | ||
const isEnabled = capabilities.featureEnabled(feature); | ||
|
||
return ( | ||
<Route | ||
render={props => | ||
isEnabled ? <Component {...props} /> : <Redirect to="/notfound" /> | ||
} | ||
{...rest} | ||
/> | ||
); | ||
}; | ||
|
||
ConditionalRoute.propTypes = { | ||
component: PropTypes.elementType.isRequired, | ||
feature: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default ConditionalRoute; |
47 changes: 47 additions & 0 deletions
47
src/web/components/conditionalRoute/__tests__/ConditionalRoute.jsx
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,47 @@ | ||
/* SPDX-FileCopyrightText: 2024 Greenbone AG | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import {describe, test, expect} from '@gsa/testing'; | ||
import {screen, rendererWith} from 'web/utils/testing'; | ||
import {Route, MemoryRouter} from 'react-router-dom'; | ||
import ConditionalRoute from 'web/components/conditionalRoute/ConditionalRoute'; | ||
import Capabilities from 'gmp/capabilities/capabilities'; | ||
|
||
const MockComponent = () => <div>Mock Component</div>; | ||
|
||
describe('ConditionalRoute', () => { | ||
const featureList = [ | ||
{name: 'ENABLED_FEATURE', _enabled: 1}, | ||
{name: 'DISABLED_FEATURE', _enabled: 0}, | ||
]; | ||
const capabilities = new Capabilities(['everything'], featureList); | ||
const {render} = rendererWith({capabilities, router: true}); | ||
test.each([ | ||
{ | ||
feature: 'ENABLED_FEATURE', | ||
expectedText: 'Mock Component', | ||
description: 'renders the component when the feature is enabled', | ||
}, | ||
{ | ||
feature: 'DISABLED_FEATURE', | ||
expectedText: 'Not Found', | ||
description: 'redirects when the feature is disabled', | ||
}, | ||
{ | ||
feature: 'unknown-feature', | ||
expectedText: 'Not Found', | ||
description: 'does not render the component for an unknown feature', | ||
}, | ||
])('$description', ({feature, expectedText}) => { | ||
render( | ||
<MemoryRouter> | ||
<ConditionalRoute component={MockComponent} feature={feature} /> | ||
<Route path="/notfound" render={() => <div>Not Found</div>} /> | ||
</MemoryRouter>, | ||
); | ||
|
||
expect(screen.getByText(expectedText)).toBeVisible(); | ||
}); | ||
}); |
Oops, something went wrong.