-
Notifications
You must be signed in to change notification settings - Fork 3
Improvement/artesca 15276 remove dataservice artesca plus veeam #875
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
Merged
bert-e
merged 4 commits into
development/3.2
from
improvement/ARTESCA-15276-remove-dataservice-artesca-plus-veeam
May 21, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a2f910b
remove dataservices routes and dataservices link from sidebar when in…
JeanMarcMilletScality c08cf43
Add tests for PrivateRoutes and InternalRoutes components
JeanMarcMilletScality b903f08
Remove unused debug import from Routes.test.tsx
JeanMarcMilletScality 1b0ae6a
Change test labeling
JeanMarcMilletScality 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 hidden or 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,200 @@ | ||
import { screen, waitFor } from '@testing-library/react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { useIsVeeamVBROnly } from './ISV/hooks/useIsVeeamVBROnly'; | ||
import InternalRoutes, { PrivateRoutes } from './Routes'; | ||
import { renderWithRouterMatch } from './utils/testUtil'; | ||
|
||
// Mock useIsVeeamVBROnly as it comes from ShellHooks | ||
jest.mock('./ISV/hooks/useIsVeeamVBROnly'); | ||
jest.mock('react-redux', () => ({ | ||
...jest.requireActual('react-redux'), | ||
useSelector: jest.fn(), | ||
useDispatch: jest.fn(), | ||
})); | ||
|
||
describe('Routes component', () => { | ||
const mockUseIsVeeamVBROnly = useIsVeeamVBROnly as jest.Mock; | ||
const mockUseSelector = useSelector as jest.Mock; | ||
const mockUseDispatch = useDispatch as jest.Mock; | ||
const selectors = { | ||
loadingAccounts: () => screen.queryByText(/Loading accounts/i), | ||
loadingDataServices: () => screen.queryByText(/Loading Data Services/i), | ||
createDataService: () => screen.queryByText(/Create new Data Service/i), | ||
loadingClients: () => screen.queryByText(/Loading clients/i), | ||
dataServicesLink: () => screen.queryByText(/Data Services/i), | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
|
||
// Default mock implementations | ||
mockUseDispatch.mockReturnValue(jest.fn()); | ||
|
||
// Setup the default state for useSelector | ||
mockUseSelector.mockImplementation((selector) => { | ||
// Create a mock state that has the necessary fields | ||
const mockState = { | ||
auth: { | ||
isClientsLoaded: true, | ||
config: { | ||
managementEndpoint: 'http://test-endpoint.com', | ||
}, | ||
oidcLogout: jest.fn(), | ||
}, | ||
oidc: { | ||
user: { | ||
access_token: 'mock-token', | ||
expired: false, | ||
expires_at: Date.now() / 1000 + 3600, // 1 hour from now | ||
}, | ||
}, | ||
configuration: { | ||
latest: { | ||
version: 1, | ||
}, | ||
}, | ||
}; | ||
|
||
// Pass the mock state to the selector function | ||
return selector(mockState); | ||
}); | ||
}); | ||
|
||
it('should show loading state when isClientsLoaded is false', async () => { | ||
// Override the default mock to set isClientsLoaded to false | ||
mockUseSelector.mockImplementation((selector) => { | ||
const mockState = { | ||
auth: { | ||
isClientsLoaded: false, | ||
config: { | ||
managementEndpoint: 'http://test-endpoint.com', | ||
}, | ||
}, | ||
oidc: { | ||
user: { | ||
access_token: 'mock-token', | ||
expired: false, | ||
}, | ||
}, | ||
}; | ||
return selector(mockState); | ||
}); | ||
|
||
// Render the PrivateRoutes component | ||
renderWithRouterMatch(<PrivateRoutes />, { | ||
path: '/*', | ||
route: '/accounts', | ||
}); | ||
|
||
// Verify that loading state is shown | ||
await waitFor(() => { | ||
expect(selectors.loadingClients()).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should render the Create Data Service page in standard configuration', async () => { | ||
// Mock the hook to return false | ||
mockUseIsVeeamVBROnly.mockReturnValue(false); | ||
|
||
// Render with the create-dataservice route | ||
renderWithRouterMatch(<PrivateRoutes />, { | ||
path: '/*', | ||
route: '/create-dataservice', | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(selectors.createDataService()).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should not render the Create Data Service page in ARTESCA+VEEAM configuration', async () => { | ||
// Mock the hook to return true | ||
mockUseIsVeeamVBROnly.mockReturnValue(true); | ||
|
||
// Render with the create-dataservice route | ||
renderWithRouterMatch(<PrivateRoutes />, { | ||
path: '/*', | ||
route: '/create-dataservice', | ||
}); | ||
|
||
// Verify that it redirects to accounts | ||
await waitFor(() => { | ||
expect(selectors.createDataService()).not.toBeInTheDocument(); | ||
expect(selectors.loadingAccounts()).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should render the Data Services page in standard configuration', async () => { | ||
// Mock the hook to return false | ||
mockUseIsVeeamVBROnly.mockReturnValue(false); | ||
|
||
// Render with the dataservices route | ||
renderWithRouterMatch(<PrivateRoutes />, { | ||
path: '/*', | ||
route: '/dataservices', | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(selectors.loadingDataServices()).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should not render the Data Services page in ARTESCA+VEEAM configuration', async () => { | ||
// Mock the hook to return true | ||
mockUseIsVeeamVBROnly.mockReturnValue(true); | ||
|
||
// Render with the dataservices route | ||
renderWithRouterMatch(<PrivateRoutes />, { | ||
path: '/*', | ||
route: '/dataservices', | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(selectors.loadingDataServices()).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
it('should redirect incorrect routes to Accounts page', async () => { | ||
renderWithRouterMatch(<PrivateRoutes />, { | ||
path: '/*', | ||
route: '/incorrect-route', | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(selectors.loadingAccounts()).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe('sidebar entries', () => { | ||
it('should hide Data Services from sidebar in ARTESCA+VEEAM configuration', async () => { | ||
// Mock the hook to return true | ||
mockUseIsVeeamVBROnly.mockReturnValue(true); | ||
|
||
// Render InternalRoutes with any route | ||
renderWithRouterMatch(<InternalRoutes />, { | ||
path: '/*', | ||
route: '/accounts', | ||
}); | ||
|
||
// Check that Data Services link is not in the sidebar | ||
await waitFor(() => { | ||
expect(selectors.dataServicesLink()).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should show Data Services in sidebar in standard configuration', async () => { | ||
// Mock the hook to return false | ||
mockUseIsVeeamVBROnly.mockReturnValue(false); | ||
|
||
// Render InternalRoutes with any route | ||
renderWithRouterMatch(<InternalRoutes />, { | ||
path: '/*', | ||
route: '/accounts', | ||
}); | ||
|
||
// Check that Data Services link is in the sidebar | ||
await waitFor(() => { | ||
expect(selectors.dataServicesLink()).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains hidden or 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 |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
|
||
import { useConfig } from './next-architecture/ui/ConfigProvider'; | ||
import { useAuthGroups } from './utils/hooks'; | ||
import NoMatch from './NoMatch'; | ||
import Accounts from './account/Accounts'; | ||
import { Locations } from './locations/Locations'; | ||
import Endpoints from './endpoint/Endpoints'; | ||
|
@@ -46,6 +46,7 @@ | |
import AccountCreateUser from './account/AccountCreateUser'; | ||
import CreateAccountPolicy from './account/CreateAccountPolicy'; | ||
import { ISVSteps } from './ISV/components/ISVSteps'; | ||
import { useIsVeeamVBROnly } from './ISV/hooks/useIsVeeamVBROnly'; | ||
|
||
export const RemoveTrailingSlash = ({ ...rest }) => { | ||
const location = useLocation(); | ||
|
@@ -97,13 +98,15 @@ | |
} | ||
}; | ||
|
||
function PrivateRoutes() { | ||
export function PrivateRoutes() { | ||
const dispatch = useDispatch(); | ||
const isClientsLoaded = useSelector( | ||
(state: AppState) => state.auth.isClientsLoaded, | ||
); | ||
const user = useSelector((state: AppState) => state.oidc.user); | ||
const config = useConfig(); | ||
const isArtescaPlusVeeamEnabled = useIsVeeamVBROnly(); | ||
|
||
const managementEndpoint = useSelector( | ||
(state: AppState) => state.auth?.config?.managementEndpoint, | ||
); | ||
|
@@ -208,22 +211,26 @@ | |
</DataServiceRoleProvider> | ||
} | ||
/> | ||
<Route | ||
path="create-dataservice/*" | ||
element={ | ||
<DataServiceRoleProvider> | ||
<EndpointCreate /> | ||
</DataServiceRoleProvider> | ||
} | ||
/> | ||
<Route | ||
path="dataservices/*" | ||
element={ | ||
<DataServiceRoleProvider> | ||
<Endpoints /> | ||
</DataServiceRoleProvider> | ||
} | ||
/> | ||
{!isArtescaPlusVeeamEnabled && ( | ||
<> | ||
<Route | ||
path="create-dataservice/*" | ||
element={ | ||
<DataServiceRoleProvider> | ||
<EndpointCreate /> | ||
</DataServiceRoleProvider> | ||
} | ||
/> | ||
<Route | ||
path="dataservices/*" | ||
element={ | ||
<DataServiceRoleProvider> | ||
<Endpoints /> | ||
</DataServiceRoleProvider> | ||
} | ||
/> | ||
</> | ||
)} | ||
<Route | ||
path="locations/*" | ||
element={ | ||
|
@@ -386,6 +393,7 @@ | |
const { isStorageManager } = useAuthGroups(); | ||
const config = useConfig(); | ||
const navigate = useBasenameRelativeNavigate(); | ||
const isArtescaPlusVeeamEnabled = useIsVeeamVBROnly(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] This hook is called in both Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
|
||
const doesRouteMatch = useCallback( | ||
(paths: string | string[]) => { | ||
|
@@ -475,14 +483,18 @@ | |
}, | ||
active: doesRouteMatch('/locations'), | ||
}, | ||
{ | ||
label: 'Data Services', | ||
icon: <Icon name="Cubes" />, | ||
onClick: () => { | ||
navigate('/dataservices'); | ||
}, | ||
active: doesRouteMatch('/dataservices'), | ||
}, | ||
...(isArtescaPlusVeeamEnabled | ||
? [] | ||
: [ | ||
{ | ||
label: 'Data Services', | ||
icon: <Icon name="Cubes" />, | ||
onClick: () => { | ||
navigate('/dataservices'); | ||
}, | ||
active: doesRouteMatch('/dataservices'), | ||
}, | ||
]), | ||
] | ||
: []), | ||
], | ||
|
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.
[nitpick] The React fragment here wraps only a single
<Route>
component. You can remove the fragment to simplify the JSX.Copilot uses AI. Check for mistakes.