mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +02:00
refactor(gitops): migrate git form to react [EE-4849] (#8268)
This commit is contained in:
parent
afe6cd6df0
commit
273a3f9a10
130 changed files with 3194 additions and 1190 deletions
39
app/react/test-utils/withUserProvider.tsx
Normal file
39
app/react/test-utils/withUserProvider.tsx
Normal file
|
@ -0,0 +1,39 @@
|
|||
import { ComponentType, useMemo } from 'react';
|
||||
|
||||
import { UserContext } from '@/react/hooks/useUser';
|
||||
import { User } from '@/portainer/users/types';
|
||||
|
||||
const mockUser: User = {
|
||||
EndpointAuthorizations: [],
|
||||
Id: 1,
|
||||
Role: 1,
|
||||
Username: 'mock',
|
||||
ThemeSettings: {
|
||||
color: 'auto',
|
||||
subtleUpgradeButton: false,
|
||||
},
|
||||
};
|
||||
|
||||
export function withUserProvider<T>(
|
||||
WrappedComponent: ComponentType<T>,
|
||||
user = mockUser
|
||||
): ComponentType<T> {
|
||||
// Try to create a nice displayName for React Dev Tools.
|
||||
const displayName =
|
||||
WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
||||
|
||||
function WrapperComponent(props: T) {
|
||||
const state = useMemo(() => ({ user }), []);
|
||||
|
||||
return (
|
||||
<UserContext.Provider value={state}>
|
||||
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
|
||||
<WrappedComponent {...props} />
|
||||
</UserContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
WrapperComponent.displayName = `withUserProvider(${displayName})`;
|
||||
|
||||
return WrapperComponent;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue