Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
jest.mock('react-redux');
const testProj = {
key: 'testproj',
name: 'Test Project',
description: 'A description about Test Project.',
collaborationLink: 'https://testlab.test-datalabs.nerc.ac.uk',
};
const currentProject = { fetching: false, value: testProj };
const projectUsers = { fetching: false, value: [{ userId: 'user1', name: 'user1@test', role: 'user' }] };
const dispatchMock = jest.fn().mockName('dispatch');
useCurrentProject.mockReturnValue(currentProject);
useProjectUsers.mockReturnValue(projectUsers);
useDispatch.mockReturnValue(dispatchMock);
describe('ProjectInfoContainer', () => {
it('renders correctly passing correct props to children', () => {
expect(shallow()).toMatchSnapshot();
});
});
describe('PureProjectInfoContainer', () => {
describe('renders correctly to match snapshot', () => {
it('when there is a collaboration link', () => {
expect(
shallow(),
).toMatchSnapshot();
});
it('when there is not a collaboration link', () => {
describe('AddUserPermissions', () => {
let shallow;
const dispatchMock = jest.fn().mockName('dispatch');
useDispatch.mockReturnValue(dispatchMock);
useUsers.mockReturnValue('users');
useCurrentUserId.mockReturnValue('current-user-id');
useCurrentUserSystemAdmin.mockReturnValue('current-user-system-admin');
useCurrentProjectKey.mockReturnValue({ value: 'testproj' });
beforeEach(() => {
shallow = createShallow({ dive: true });
});
it('renders pure component with correct props', () => {
expect(shallow()).toMatchSnapshot();
});
});
describe('ProjectSwitcher', () => {
const dispatchMock = jest.fn().mockName('dispatch');
useDispatch.mockReturnValue(dispatchMock);
useCurrentProject.mockReturnValue(state.currentProject);
useProjectsArray.mockReturnValue(state.projects);
beforeEach(() => {
jest.clearAllMocks();
});
it('renders to match snapshot passing correct parameters to children', () => {
expect(shallow().dive()).toMatchSnapshot();
});
});
describe('UserPermissionsTable', () => {
let shallow;
const dispatchMock = jest.fn().mockName('dispatch');
useDispatch.mockReturnValue(dispatchMock);
useProjectUsers.mockReturnValue('users');
useCurrentUserId.mockReturnValue('current-user-id');
useCurrentUserSystemAdmin.mockReturnValue('current-user-system-admin');
useCurrentProjectKey.mockReturnValue({ value: 'testproj' });
beforeEach(() => {
shallow = createShallow({ dive: true });
});
it('renders pure component with correct props', () => {
expect(shallow()).toMatchSnapshot();
});
});
jest.mock('../../auth/auth');
jest.mock('../../hooks/authHooks');
jest.mock('../../actions/authActions');
const isAuthenticated = jest.fn();
const getCurrentSession = jest.fn();
getAuth.mockImplementation(() => ({
isAuthenticated,
getCurrentSession,
}));
useCurrentUserPermissions.mockReturnValue({ fetching: false, value: ['permission'] });
useCurrentUserTokens.mockReturnValue({ token: 'expectedUserToken' });
const mockDispatch = jest.fn().mockName('dispatch');
useDispatch.mockReturnValue(mockDispatch);
describe('RequireAuth', () => {
let shallow;
beforeEach(() => {
shallow = createShallow();
});
const shallowRender = (props = {}) => {
const defaultProps = {
PrivateComponent: jest.fn().mockName('privateComponent'),
PublicComponent: jest.fn().mockName('publicComponent'),
path: '/path',
exact: true,
strict: true,
};