From 4e24eb5e436a2c97a1751497c713fbb2e674fd94 Mon Sep 17 00:00:00 2001 From: MirzaHanan Date: Wed, 24 Jan 2024 19:20:17 +0500 Subject: [PATCH 1/3] fix(bounty-page): fixed bounty page go back to the home page --- src/pages/tickets/TicketModalPage.tsx | 18 +++++- .../__tests__/TicketModalPage.spec.tsx | 59 +++++++++++++++++++ 2 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 src/pages/tickets/__tests__/TicketModalPage.spec.tsx diff --git a/src/pages/tickets/TicketModalPage.tsx b/src/pages/tickets/TicketModalPage.tsx index 9ca485c5..a5919fbe 100644 --- a/src/pages/tickets/TicketModalPage.tsx +++ b/src/pages/tickets/TicketModalPage.tsx @@ -15,6 +15,7 @@ const focusedDesktopModalStyles = widgetConfigs.wanted.modalStyle; type Props = { setConnectPerson: (p: any) => void; + visible?: boolean; }; export const TicketModalPage = observer(({ setConnectPerson }: Props) => { @@ -28,7 +29,7 @@ export const TicketModalPage = observer(({ setConnectPerson }: Props) => { const [activeListIndex, setActiveListIndex] = useState(0); const [publicFocusIndex, setPublicFocusIndex] = useState(0); const [removeNextAndPrev, setRemoveNextAndPrev] = useState(false); - const { bountyId } = useParams<{ uuid: string; bountyId: string }>(); + const { uuid, bountyId } = useParams<{ uuid: string; bountyId: string }>(); const [activeBounty, setActiveBounty] = useState([]); const [visible, setVisible] = useState(false); const [isDeleted, setisDeleted] = useState(false); @@ -73,10 +74,21 @@ export const TicketModalPage = observer(({ setConnectPerson }: Props) => { getBounty(); }, [getBounty, removeNextAndPrev]); - const goBack = async () => { + const isDirectAccess = useCallback( + () => !document.referrer && location.pathname.includes('/bounty/'), + [location.pathname] + ); + + const goBack = () => { setVisible(false); setisDeleted(false); - history.goBack(); + + if (isDirectAccess()) { + const homePageUrl = uuid ? `/org/bounties/${uuid}` : '/bounties'; + history.push(homePageUrl); + } else { + history.goBack(); + } }; const directionHandler = (person: any, body: any) => { diff --git a/src/pages/tickets/__tests__/TicketModalPage.spec.tsx b/src/pages/tickets/__tests__/TicketModalPage.spec.tsx new file mode 100644 index 00000000..e3a9e3c2 --- /dev/null +++ b/src/pages/tickets/__tests__/TicketModalPage.spec.tsx @@ -0,0 +1,59 @@ +import React from 'react'; +import { render, fireEvent, screen, waitFor } from '@testing-library/react'; +import { useIsMobile } from 'hooks'; +import { useStores } from 'store'; +import { TicketModalPage } from '../TicketModalPage.tsx'; + +jest.mock('hooks', () => ({ + useIsMobile: jest.fn() +})); + +jest.mock('store', () => ({ + useStores: jest.fn() +})); + +const mockPush = jest.fn(); +const mockGoBack = jest.fn(); + +jest.mock('react-router-dom', () => ({ + ...jest.requireActual('react-router-dom'), + useHistory: () => ({ + push: mockPush, + goBack: mockGoBack + }), + useLocation: () => ({ + pathname: '/bounty/1239', + search: '', + state: {} + }), + useParams: () => ({ + uuid: 'ck95pe04nncjnaefo08g', + bountyId: '1239' + }) +})); + +describe('TicketModalPage Component', () => { + it('should redirect to the appropriate page on close based on the route and referrer', async () => { + // Mocking the useIsMobile hook + (useIsMobile as jest.Mock).mockReturnValue(false); + + (useStores as jest.Mock).mockReturnValue({ + main: { + getBountyById: jest.fn(), + getBountyIndexById: jest.fn() + } + }); + + render(); + + // eslint-disable-next-line @typescript-eslint/no-empty-function + await waitFor(() => {}); + + const closeButton = screen.queryByTestId('close-btn'); + if (closeButton) { + fireEvent.click(closeButton); + + expect(mockPush).toHaveBeenCalledWith('/bounties'); + } + }); +}); From 32a6e5b3a12d4b107c0355c8ce02858ef313cca8 Mon Sep 17 00:00:00 2001 From: MirzaHanan Date: Wed, 24 Jan 2024 20:27:40 +0500 Subject: [PATCH 2/3] fix(bounty-page): fixed prettier format --- src/pages/tickets/__tests__/TicketModalPage.spec.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/tickets/__tests__/TicketModalPage.spec.tsx b/src/pages/tickets/__tests__/TicketModalPage.spec.tsx index e3a9e3c2..86f8bdc0 100644 --- a/src/pages/tickets/__tests__/TicketModalPage.spec.tsx +++ b/src/pages/tickets/__tests__/TicketModalPage.spec.tsx @@ -34,7 +34,6 @@ jest.mock('react-router-dom', () => ({ describe('TicketModalPage Component', () => { it('should redirect to the appropriate page on close based on the route and referrer', async () => { - // Mocking the useIsMobile hook (useIsMobile as jest.Mock).mockReturnValue(false); (useStores as jest.Mock).mockReturnValue({ From e395c7d1755d9e1b7ad065dcc01511c757f05d4a Mon Sep 17 00:00:00 2001 From: Mirza Hanan <100023456+MirzaHanan@users.noreply.github.com> Date: Thu, 25 Jan 2024 00:58:56 +0500 Subject: [PATCH 3/3] Just trigger our github actions workflows for testing --- src/pages/tickets/__tests__/TicketModalPage.spec.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/tickets/__tests__/TicketModalPage.spec.tsx b/src/pages/tickets/__tests__/TicketModalPage.spec.tsx index 86f8bdc0..0866e505 100644 --- a/src/pages/tickets/__tests__/TicketModalPage.spec.tsx +++ b/src/pages/tickets/__tests__/TicketModalPage.spec.tsx @@ -33,7 +33,7 @@ jest.mock('react-router-dom', () => ({ })); describe('TicketModalPage Component', () => { - it('should redirect to the appropriate page on close based on the route and referrer', async () => { + it('should redirect to the appropriate page on close based on the route', async () => { (useIsMobile as jest.Mock).mockReturnValue(false); (useStores as jest.Mock).mockReturnValue({