Skip to content

Commit

Permalink
Usertype removal - part 1 (PalisadoesFoundation#1858)
Browse files Browse the repository at this point in the history
* delete org fix

* refactor duplicate code files

* refactor userType code in Users.tsx

* userType fix App.test

* fix leftdrawer

* settings test

* events n profile dropdown

* rename file

* Fix import casing in OrganizationScreen and SuperAdminScreen

* Rename profileDropdown.module.css to ProfileDropdown.module.css

* Rename profileDropdown.test.tsx to ProfileDropdown.test.tsx

* Rename profileDropdown.tsx to ProfileDropdown.tsx

* variable rename

* remove unused code

* fix test and remove userType in OrgSettings

* Remove unnecessary beforeEach block in LeftDrawerOrg.test.tsx

* superadmin screen test

* unused code

* login test data fix

* unused

* unused

* fixed userType to userRole

* Remove InterfaceQueryRequestListItem interface

* deleteOrg test fix

* typos

* Update OrganizationDashboard.test.tsx

* added files with eslint issue

* Update pre-commit
  • Loading branch information
pranshugupta54 committed Apr 3, 2024
1 parent c328cfc commit 1d057d9
Show file tree
Hide file tree
Showing 24 changed files with 53 additions and 247 deletions.
1 change: 0 additions & 1 deletion src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const MOCKS = [
phone: {
mobile: '+8912313112',
},
userType: 'SUPERADMIN',
},
},
},
Expand Down
12 changes: 6 additions & 6 deletions src/components/DeleteOrg/DeleteOrg.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ afterEach(() => {
describe('Delete Organization Component', () => {
test('should be able to Toggle Delete Organization Modal', async () => {
mockURL = '456';
setItem('UserType', 'SUPERADMIN');
setItem('SuperAdmin', true);
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
Expand All @@ -140,7 +140,7 @@ describe('Delete Organization Component', () => {

test('should be able to Toggle Delete Organization Modal When Organization is Sample Organization', async () => {
mockURL = '123';
setItem('UserType', 'SUPERADMIN');
setItem('SuperAdmin', true);
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
Expand All @@ -164,7 +164,7 @@ describe('Delete Organization Component', () => {

test('Delete organization functionality should work properly', async () => {
mockURL = '456';
setItem('UserType', 'SUPERADMIN');
setItem('SuperAdmin', true);
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
Expand All @@ -183,7 +183,7 @@ describe('Delete Organization Component', () => {

test('Delete organization functionality should work properly for sample org', async () => {
mockURL = '123';
setItem('UserType', 'SUPERADMIN');
setItem('SuperAdmin', true);
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
Expand All @@ -204,7 +204,7 @@ describe('Delete Organization Component', () => {

test('Error handling for IS_SAMPLE_ORGANIZATION_QUERY mock', async () => {
mockURL = '123';
setItem('UserType', 'SUPERADMIN');
setItem('SuperAdmin', true);
jest.spyOn(toast, 'error');
render(
<MockedProvider addTypename={false} link={link2}>
Expand All @@ -228,7 +228,7 @@ describe('Delete Organization Component', () => {

test('Error handling for DELETE_ORGANIZATION_MUTATION mock', async () => {
mockURL = '456';
setItem('UserType', 'SUPERADMIN');
setItem('SuperAdmin', true);
render(
<MockedProvider addTypename={false} link={link2}>
<BrowserRouter>
Expand Down
4 changes: 2 additions & 2 deletions src/components/DeleteOrg/DeleteOrg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function deleteOrg(): JSX.Element {
const navigate = useNavigate();
const [showDeleteModal, setShowDeleteModal] = useState(false);
const { getItem } = useLocalStorage();
const canDelete = getItem('UserType') === 'SUPERADMIN';
const canDelete = getItem('SuperAdmin');
const toggleDeleteModal = (): void => setShowDeleteModal(!showDeleteModal);

const [del] = useMutation(DELETE_ORGANIZATION_MUTATION);
Expand Down Expand Up @@ -55,7 +55,7 @@ function deleteOrg(): JSX.Element {
},
});
navigate('/orglist');
} catch (error: any) {
} catch (error) {
errorHandler(t, error);
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/components/LeftDrawer/LeftDrawer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ afterEach(() => {
});

describe('Testing Left Drawer component for SUPERADMIN', () => {
beforeEach(() => {
setItem('UserType', 'SUPERADMIN');
});
test('Component should be rendered properly', () => {
setItem('UserImage', '');
setItem('UserImage', '');
Expand Down Expand Up @@ -134,9 +131,6 @@ describe('Testing Left Drawer component for SUPERADMIN', () => {
});

describe('Testing Left Drawer component for ADMIN', () => {
beforeEach(() => {
setItem('UserType', 'ADMIN');
});
test('Components should be rendered properly', () => {
render(
<MockedProvider addTypename={false} link={link}>
Expand Down
1 change: 0 additions & 1 deletion src/components/LeftDrawer/LeftDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const leftDrawer = ({ hideDrawer }: InterfaceLeftDrawerProps): JSX.Element => {
const { t } = useTranslation('translation', { keyPrefix: 'leftDrawer' });

const { getItem } = useLocalStorage();
const userType = getItem('UserType');
const superAdmin = getItem('SuperAdmin');
const role = superAdmin ? 'SuperAdmin' : 'Admin';

Expand Down
4 changes: 0 additions & 4 deletions src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,6 @@ const linkImage = new StaticMockLink(MOCKS_WITH_IMAGE, true);
const linkEmpty = new StaticMockLink(MOCKS_EMPTY, true);

describe('Testing LeftDrawerOrg component for SUPERADMIN', () => {
beforeEach(() => {
setItem('UserType', 'SUPERADMIN');
});

test('Component should be rendered properly', async () => {
setItem('UserImage', '');
setItem('SuperAdmin', true);
Expand Down
2 changes: 1 addition & 1 deletion src/components/OrganizationScreen/OrganizationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { updateTargets } from 'state/action-creators';
import type { RootState } from 'state/reducers';
import type { TargetsType } from 'state/reducers/routesReducer';
import styles from './OrganizationScreen.module.css';
import ProfileDropdown from 'components/ProfileDropdown/profileDropdown';
import ProfileDropdown from 'components/ProfileDropdown/ProfileDropdown';

const OrganizationScreen = (): JSX.Element => {
const location = useLocation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { act, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { BrowserRouter } from 'react-router-dom';
import ProfileDropdown from './profileDropdown';
import ProfileDropdown from './ProfileDropdown';
import 'jest-localstorage-mock';
import { MockedProvider } from '@apollo/react-testing';
import { REVOKE_REFRESH_TOKEN } from 'GraphQl/Mutations/mutations';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Avatar from 'components/Avatar/Avatar';
import React from 'react';
import { ButtonGroup, Dropdown } from 'react-bootstrap';
import { useNavigate, useParams } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import useLocalStorage from 'utils/useLocalstorage';
import styles from './profileDropdown.module.css';
import styles from './ProfileDropdown.module.css';
import { REVOKE_REFRESH_TOKEN } from 'GraphQl/Mutations/mutations';
import { useMutation } from '@apollo/client';

Expand All @@ -12,7 +12,7 @@ const profileDropdown = (): JSX.Element => {
const { getItem } = useLocalStorage();
const superAdmin = getItem('SuperAdmin');
const adminFor = getItem('AdminFor');
const userType = superAdmin
const userRole = superAdmin
? 'SuperAdmin'
: adminFor?.length > 0
? 'Admin'
Expand Down Expand Up @@ -67,7 +67,7 @@ const profileDropdown = (): JSX.Element => {
{displayedName}
</span>
<span className={styles.secondaryText} data-testid="display-type">
{`${userType}`}
{`${userRole}`}
</span>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jest.mock('react-toastify', () => ({
}));

beforeEach(() => {
setItem('UserType', 'ADMIN');
setItem('id', '123');
});

Expand Down
2 changes: 0 additions & 2 deletions src/components/SuperAdminScreen/SuperAdminScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ const clickToggleMenuBtn = (toggleButton: HTMLElement): void => {

describe('Testing LeftDrawer in SuperAdminScreen', () => {
test('Testing LeftDrawer in page functionality', async () => {
setItem('UserType', 'SUPERADMIN');

render(
<MockedProvider addTypename={false}>
<BrowserRouter>
Expand Down
7 changes: 5 additions & 2 deletions src/components/SuperAdminScreen/SuperAdminScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Button from 'react-bootstrap/Button';
import { useTranslation } from 'react-i18next';
import { Outlet, useLocation } from 'react-router-dom';
import styles from './SuperAdminScreen.module.css';
import ProfileDropdown from 'components/ProfileDropdown/profileDropdown';
import ProfileDropdown from 'components/ProfileDropdown/ProfileDropdown';

const superAdminScreen = (): JSX.Element => {
const location = useLocation();
Expand Down Expand Up @@ -71,7 +71,10 @@ const superAdminScreen = (): JSX.Element => {

export default superAdminScreen;

const map: any = {
const map: Record<
string,
'orgList' | 'requests' | 'users' | 'memberDetail' | 'communityProfile'
> = {
orglist: 'orgList',
requests: 'requests',
users: 'users',
Expand Down
6 changes: 4 additions & 2 deletions src/components/UserPortal/Login/Login.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ const MOCKS = [
login: {
user: {
_id: '1',
userType: 'ADMIN',
adminApproved: false,
firstName: 'firstname',
lastName: 'secondname',
email: '[email protected]',
image: 'image',
},
appUserProfile: {
adminFor: {},
isSuperAdmin: false,
},
accessToken: 'accessToken',
refreshToken: 'refreshToken',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ const renderStartPostModal = (
lastName: 'dsza',
email: '[email protected]',
appLanguageCode: 'en',
userType: 'USER',
pluginCreationAllowed: true,
adminApproved: true,
createdAt: '2023-02-18T09:22:27.969Z',
Expand Down
47 changes: 0 additions & 47 deletions src/screens/MemberDetail/MemberDetail.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import { BrowserRouter } from 'react-router-dom';
import { Provider } from 'react-redux';
import { store } from 'state/store';
import { I18nextProvider } from 'react-i18next';
import {
ADD_ADMIN_MUTATION,
UPDATE_USERTYPE_MUTATION,
UPDATE_USER_MUTATION,
} from 'GraphQl/Mutations/mutations';
import { USER_DETAILS } from 'GraphQl/Queries/Queries';
import i18nForTest from 'utils/i18nForTest';
import { StaticMockLink } from 'utils/StaticMockLink';
Expand Down Expand Up @@ -120,20 +115,6 @@ const MOCKS1 = [
},
},
},
{
request: {
query: ADD_ADMIN_MUTATION,
variables: {
userid: '123',
orgid: '456',
},
},
result: {
data: {
success: true,
},
},
},
];

const MOCKS2 = [
Expand Down Expand Up @@ -224,20 +205,6 @@ const MOCKS2 = [
},
},
},
{
request: {
query: ADD_ADMIN_MUTATION,
variables: {
userid: '123',
orgid: '456',
},
},
result: {
data: {
success: true,
},
},
},
];
const MOCKS3 = [
{
Expand Down Expand Up @@ -327,20 +294,6 @@ const MOCKS3 = [
},
},
},
{
request: {
query: ADD_ADMIN_MUTATION,
variables: {
userid: '123',
orgid: '456',
},
},
result: {
data: {
success: true,
},
},
},
];

const link1 = new StaticMockLink(MOCKS1, true);
Expand Down
2 changes: 1 addition & 1 deletion src/screens/MemberDetail/MemberDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
maritalStatusEnum,
genderEnum,
employmentStatusEnum,
} from 'utils/memberFields';
} from 'utils/formEnumFields';
import DynamicDropDown from 'components/DynamicDropDown/DynamicDropDown';

type MemberDetailProps = {
Expand Down
4 changes: 2 additions & 2 deletions src/screens/OrgSettings/OrgSettings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('Organisation Settings Page', () => {

test('should render props and text elements test for the screen', async () => {
window.location.assign('/orgsetting/id=123');
setItem('UserType', 'SUPERADMIN');
setItem('SuperAdmin', true);
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('Organisation Settings Page', () => {

test('should render appropriate settings based on the orgSetting state', async () => {
window.location.assign('/orgsetting/id=123');
setItem('UserType', 'SUPERADMIN');
setItem('SuperAdmin', true);

const { queryByText } = render(
<MockedProvider addTypename={false} link={link}>
Expand Down
8 changes: 7 additions & 1 deletion src/screens/OrganizationEvents/OrganizationEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ function organizationEvents(): JSX.Element {
});

const userId = getItem('id') as string;
const userRole = getItem('UserType') as string;
const superAdmin = getItem('SuperAdmin');
const adminFor = getItem('AdminFor');
const userRole = superAdmin
? 'SUPERADMIN'
: adminFor?.length > 0
? 'ADMIN'
: 'USER';

const [create, { loading: loading2 }] = useMutation(CREATE_EVENT_MUTATION);

Expand Down
1 change: 0 additions & 1 deletion src/screens/Requests/Requests.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ describe('Testing Requests screen', () => {

test(`Component should be rendered properly when user is not Admin
and or userId does not exists in localstorage`, async () => {
setItem('UserType', 'SUPERADMIN');
setItem('id', '');
render(
<MockedProvider addTypename={false} link={link}>
Expand Down
2 changes: 0 additions & 2 deletions src/screens/UserPortal/Settings/Settings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const Mocks1 = [
mobile: '+174567890',
},
image: 'https://api.dicebear.com/5.x/initials/svg?seed=John%20Doe',
userType: 'user',
_id: '65ba1621b7b00c20e5f1d8d2',
},
},
Expand Down Expand Up @@ -98,7 +97,6 @@ const Mocks2 = [
mobile: '',
},
image: '',
userType: 'user',
_id: '65ba1621b7b00c20e5f1d8d2',
},
},
Expand Down
Loading

0 comments on commit 1d057d9

Please sign in to comment.