Skip to content
Snippets Groups Projects
Commit a1670473 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

redirect to admin page using href (route uses invalid base url)

parent dcc42dcf
No related branches found
No related tags found
2 merge requests!223reset the pin numbers before search results are fetch (so the results will be...,!213Plugins should always receive reaction from new api
......@@ -3,11 +3,9 @@ import {
InitialStoreState,
getReduxStoreWithActionsListener,
} from '@/utils/testing/getReduxStoreActionsListener';
import mockRouter from 'next-router-mock';
import { fireEvent, render, screen } from '@testing-library/react';
import { MockStoreEnhanced } from 'redux-mock-store';
import { FIRST_ARRAY_ELEMENT } from '@/constants/common';
import { projectFixture } from '@/models/fixtures/projectFixture';
import { LoggedInMenuModal } from './LoggedInMenuModal.component';
const renderComponent = (
......@@ -41,22 +39,4 @@ describe('LoggedInMenuModal component', () => {
const actions = store.getActions();
expect(actions[FIRST_ARRAY_ELEMENT].type).toBe('modal/closeModal');
});
it('redirects to the admin panel when "Go to the admin panel" button is clicked', () => {
const routerPushSpy = jest.spyOn(mockRouter, 'push');
renderComponent({
project: {
data: projectFixture,
loading: 'succeeded',
error: { message: '', name: '' },
projectId: '',
},
});
fireEvent.click(screen.getByText('Go to the admin panel'));
expect(routerPushSpy).toHaveBeenCalledWith(
`https://lux1.atcomp.pl/minerva/admin.xhtml?id=pdmap_appu_test`,
);
});
});
......@@ -2,19 +2,17 @@ import { CURRENT_PROJECT_ADMIN_PANEL_URL } from '@/constants';
import { useAppDispatch } from '@/redux/hooks/useAppDispatch';
import { closeModal } from '@/redux/modal/modal.slice';
import { Button } from '@/shared/Button';
import { useRouter } from 'next/router';
import React from 'react';
export const LoggedInMenuModal = (): React.ReactNode => {
const dispatch = useAppDispatch();
const router = useRouter();
const closeLoggedInMenuModal = (): void => {
dispatch(closeModal());
};
const goToTheAdminPanel = (): void => {
router.push(CURRENT_PROJECT_ADMIN_PANEL_URL);
window.location.href = CURRENT_PROJECT_ADMIN_PANEL_URL;
};
return (
<div className="flex justify-center gap-5 border border-t-[#E1E0E6] bg-white p-6">
......
......@@ -6,8 +6,6 @@ import { USER_INITIAL_STATE_MOCK } from '@/redux/user/user.mock';
import { mockNetworkResponse } from '@/utils/mockNetworkResponse';
import { apiPath } from '@/redux/apiPath';
import { HttpStatusCode } from 'axios';
import mockRouter from 'next-router-mock';
import { projectFixture } from '@/models/fixtures/projectFixture';
import { oauthFixture } from '@/models/fixtures/oauthFixture';
import { User } from './User.component';
......@@ -160,39 +158,6 @@ describe('AuthenticatedUser component', () => {
expect(modalState.isOpen).toBeTruthy();
expect(modalState.modalName).toBe('login');
});
it('should change site to admin panel if go to the admin panel is pressed', async () => {
const routerPushSpy = jest.spyOn(mockRouter, 'push');
renderComponent({
project: {
data: projectFixture,
loading: 'succeeded',
error: { message: '', name: '' },
projectId: '',
},
user: {
...USER_INITIAL_STATE_MOCK,
authenticated: true,
login: 'name',
role: 'admin',
},
});
const button = screen.getByTestId('authenticated-button');
await waitFor(() => {
button.click();
});
const adminPanelButton = screen.getByText('Go to the admin panel');
await waitFor(() => {
adminPanelButton.click();
});
expect(routerPushSpy).toHaveBeenCalledWith(
`https://lux1.atcomp.pl/minerva/admin.xhtml?id=pdmap_appu_test`,
);
});
});
describe('UnauthenticatedUser component', () => {
......
......@@ -4,7 +4,6 @@ import { openLoginModal } from '@/redux/modal/modal.slice';
import { userRoleSelector } from '@/redux/user/user.selectors';
import { logout } from '@/redux/user/user.thunks';
import { IconTypes } from '@/types/iconTypes';
import { useRouter } from 'next/router';
import { USER_ROLE } from '@/constants/user';
import { useMemo } from 'react';
import { CURRENT_PROJECT_ADMIN_PANEL_URL } from '@/constants';
......@@ -21,7 +20,6 @@ type UseUserActionsReturnType = {
export const useUserActions = (): UseUserActionsReturnType => {
const dispatch = useAppDispatch();
const userRole = useAppSelector(userRoleSelector);
const router = useRouter();
const actions = useMemo(() => {
return userRole === USER_ROLE.ADMIN || userRole === USER_ROLE.CURATOR
......@@ -43,7 +41,7 @@ export const useUserActions = (): UseUserActionsReturnType => {
};
const goToThePanelAdmin = (): void => {
router.push(CURRENT_PROJECT_ADMIN_PANEL_URL);
window.location.href = CURRENT_PROJECT_ADMIN_PANEL_URL;
};
const handleActionClick = (action: string): void => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment