forked from stakwork/sphinx-tribes-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request stakwork#16 from MirzaHanan/bounty-page-go-back-home
Fix(Bounty-Page): Enhanced Navigation for Direct Access to Bounty Pages
- Loading branch information
Showing
2 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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', async () => { | ||
(useIsMobile as jest.Mock).mockReturnValue(false); | ||
|
||
(useStores as jest.Mock).mockReturnValue({ | ||
main: { | ||
getBountyById: jest.fn(), | ||
getBountyIndexById: jest.fn() | ||
} | ||
}); | ||
|
||
render(<TicketModalPage setConnectPerson={jest.fn()} visible={true} />); | ||
|
||
// 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'); | ||
} | ||
}); | ||
}); |