From aa444c29d0538c58af3a7fd1367fda7ab4675d1f Mon Sep 17 00:00:00 2001 From: Glen Date: Tue, 7 May 2024 23:21:45 +0530 Subject: [PATCH] Update tests --- .../EventDashboardScreen.tsx | 5 +--- .../EventListCard/EventListCard.test.tsx | 30 +++++++++++++++++-- .../EventListCard/EventListCardModals.tsx | 3 +- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/components/EventDashboardScreen/EventDashboardScreen.tsx b/src/components/EventDashboardScreen/EventDashboardScreen.tsx index 3ff980730a..9b518f5e0b 100644 --- a/src/components/EventDashboardScreen/EventDashboardScreen.tsx +++ b/src/components/EventDashboardScreen/EventDashboardScreen.tsx @@ -14,11 +14,8 @@ const EventDashboardScreen = (): JSX.Element => { const { getItem } = useLocalStorage(); const isLoggedIn = getItem('IsLoggedIn'); const adminFor = getItem('AdminFor'); - const userId = getItem('userId'); const location = useLocation(); - const titleKey: string | undefined = !userId - ? map[location.pathname.split('/')[1]] - : map[location.pathname.split('/')[2]]; + const titleKey: string | undefined = map[location.pathname.split('/')[2]]; const { t } = useTranslation('translation', { keyPrefix: titleKey }); const [hideDrawer, setHideDrawer] = useState(null); const { orgId } = useParams(); diff --git a/src/components/EventListCard/EventListCard.test.tsx b/src/components/EventListCard/EventListCard.test.tsx index cf321fa4b1..a75b1bdb48 100644 --- a/src/components/EventListCard/EventListCard.test.tsx +++ b/src/components/EventListCard/EventListCard.test.tsx @@ -68,7 +68,14 @@ const renderEventListCard = ( path="/event/:orgId/" element={} /> - } /> + Event Dashboard (Admin)} + /> + Event Dashboard (User)} + /> @@ -287,7 +294,7 @@ describe('Testing Event List Card', () => { }); }); - test('Should navigate to event dashboard when clicked', async () => { + test('Should navigate to event dashboard when clicked (For Admin)', async () => { renderEventListCard(props[1]); userEvent.click(screen.getByTestId('card')); @@ -300,6 +307,25 @@ describe('Testing Event List Card', () => { await waitFor(() => { expect(screen.queryByTestId('card')).not.toBeInTheDocument(); + expect(screen.queryByText('Event Dashboard (Admin)')).toBeInTheDocument(); + }); + }); + + test('Should navigate to event dashboard when clicked (For User)', async () => { + setItem('userId', '123'); + renderEventListCard(props[2]); + + userEvent.click(screen.getByTestId('card')); + + await waitFor(() => { + expect(screen.getByTestId('showEventDashboardBtn')).toBeInTheDocument(); + }); + + userEvent.click(screen.getByTestId('showEventDashboardBtn')); + + await waitFor(() => { + expect(screen.queryByTestId('card')).not.toBeInTheDocument(); + expect(screen.queryByText('Event Dashboard (User)')).toBeInTheDocument(); }); }); diff --git a/src/components/EventListCard/EventListCardModals.tsx b/src/components/EventListCard/EventListCardModals.tsx index e8e2f069e9..69c102910c 100644 --- a/src/components/EventListCard/EventListCardModals.tsx +++ b/src/components/EventListCard/EventListCardModals.tsx @@ -322,7 +322,7 @@ function EventListCardModals({ (registrant) => registrant._id === userId, ); const [registerEventMutation] = useMutation(REGISTER_EVENT); - const [isRegistered, setIsRegistered] = React.useState(isInitiallyRegistered); + const [isRegistered, setIsRegistered] = useState(isInitiallyRegistered); const registerEventHandler = async (): Promise => { if (!isRegistered) { @@ -353,6 +353,7 @@ function EventListCardModals({ const openEventDashboard = (): void => { const userPath = eventListCardProps.userRole === Role.USER ? 'user/' : ''; + console.log(`/${userPath}event/${orgId}/${eventListCardProps.id}`); navigate(`/${userPath}event/${orgId}/${eventListCardProps.id}`); };