Skip to content

Commit

Permalink
Revert "fixed redirect issue when already logged in#1646"
Browse files Browse the repository at this point in the history
This reverts commit 1cbeae2.
  • Loading branch information
kanhaiya04 committed Mar 5, 2024
1 parent b3f3341 commit 4ecd3e8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 49 deletions.
47 changes: 1 addition & 46 deletions src/screens/LoginPage/LoginPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { MockedProvider } from '@apollo/react-testing';
import { act, render, screen, fireEvent } from '@testing-library/react';
import { Provider } from 'react-redux';
import { BrowserRouter, MemoryRouter } from 'react-router-dom';
import { BrowserRouter } from 'react-router-dom';
import userEvent from '@testing-library/user-event';
import { I18nextProvider } from 'react-i18next';
import 'jest-localstorage-mock';
Expand All @@ -17,7 +17,6 @@ import {
import { store } from 'state/store';
import i18nForTest from 'utils/i18nForTest';
import { BACKEND_URL } from 'Constant/constant';
import useLocalStorage from 'utils/useLocalstorage';

const MOCKS = [
{
Expand Down Expand Up @@ -80,7 +79,6 @@ const MOCKS = [
];

const link = new StaticMockLink(MOCKS, true);
const mockHistoryPush = jest.fn();

async function wait(ms = 100): Promise<void> {
await act(() => {
Expand Down Expand Up @@ -778,46 +776,3 @@ describe('Testing Login Page Screen', () => {
}
});
});

describe('Testing redirect if already logged in', () => {
test('Logged in as USER', async () => {
const { setItem } = useLocalStorage();
setItem('IsLoggedIn', 'TRUE');
setItem('UserType', 'USER');
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<MemoryRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<LoginPage />
</I18nextProvider>
</Provider>
</MemoryRouter>
</BrowserRouter>
</MockedProvider>,
);
await wait();
expect(mockHistoryPush).toHaveBeenCalledWith('/user/organizations');
});
test('Logged as in Admin or SuperAdmin', async () => {
const { setItem } = useLocalStorage();
setItem('IsLoggedIn', 'TRUE');
setItem('UserType', 'ADMIN');
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<MemoryRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<LoginPage />
</I18nextProvider>
</Provider>
</MemoryRouter>
</BrowserRouter>
</MockedProvider>,
);
await wait();
expect(mockHistoryPush).toHaveBeenCalledWith('/orglist');
});
});
4 changes: 1 addition & 3 deletions src/screens/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ const loginPage = (): JSX.Element => {
useEffect(() => {
const isLoggedIn = getItem('IsLoggedIn');
if (isLoggedIn == 'TRUE') {
history.push(
getItem('UserType') === 'USER' ? '/user/organizations' : '/orglist',
);
history.push(role === 'admin' ? '/orglist' : '/user/organizations');
}
setComponentLoader(false);
}, []);
Expand Down

0 comments on commit 4ecd3e8

Please sign in to comment.