Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GlenDsza committed May 7, 2024
1 parent ccaba46 commit aa444c2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
5 changes: 1 addition & 4 deletions src/components/EventDashboardScreen/EventDashboardScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean | null>(null);
const { orgId } = useParams();
Expand Down
30 changes: 28 additions & 2 deletions src/components/EventListCard/EventListCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ const renderEventListCard = (
path="/event/:orgId/"
element={<EventListCard {...props} />}
/>
<Route path="/event/:orgId/:eventId" element={<></>} />
<Route
path="/event/:orgId/:eventId"
element={<div>Event Dashboard (Admin)</div>}
/>
<Route
path="/user/event/:orgId/:eventId"
element={<div>Event Dashboard (User)</div>}
/>
</Routes>
</I18nextProvider>
</LocalizationProvider>
Expand Down Expand Up @@ -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'));
Expand All @@ -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();
});
});

Expand Down
3 changes: 2 additions & 1 deletion src/components/EventListCard/EventListCardModals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
if (!isRegistered) {
Expand Down Expand Up @@ -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}`);
};

Expand Down

0 comments on commit aa444c2

Please sign in to comment.