-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfedd45
commit c6e630e
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
frontend/app/src/pages/tickets/tickets/TicketModalPage.spec.tsx
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, screen, fireEvent, waitFor } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { TicketModalPage } from '../TicketModalPage'; // Adjust the import path as needed | ||
import { BrowserRouter } from 'react-router-dom'; | ||
|
||
// Mocks | ||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useHistory: jest.fn(), | ||
useLocation: jest.fn(), | ||
useParams: jest.fn() | ||
})); | ||
|
||
const mockedHistoryPush = jest.fn(); | ||
const mockedUseHistory = require('react-router-dom').useHistory; | ||
const mockedUseLocation = require('react-router-dom').useLocation; | ||
const mockedUseParams = require('react-router-dom').useParams; | ||
|
||
describe('TicketModalPage', () => { | ||
beforeEach(() => { | ||
mockedUseHistory.mockReturnValue({ push: mockedHistoryPush }); | ||
mockedUseLocation.mockReturnValue({ | ||
pathname: '/bounty/1203', | ||
search: '' | ||
}); | ||
mockedUseParams.mockReturnValue({ uuid: 'ck1p7l6a5fdlqdgmmnpg', bountyId: '1203' }); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('redirects to home page on direct access to bounty page', async () => { | ||
// Arrange: Set up conditions for a direct access | ||
Object.defineProperty(window, 'referrer', { | ||
configurable: true, | ||
value: '' | ||
}); | ||
|
||
// Act: Render the component and simulate closing the modal | ||
render( | ||
<BrowserRouter> | ||
<TicketModalPage setConnectPerson={() => {}} /> | ||
</BrowserRouter> | ||
); | ||
const goBackButton = await waitFor(() => screen.findByTestId('testid-modal'), { | ||
timeout: 10000 | ||
}); | ||
|
||
fireEvent.click(goBackButton); | ||
|
||
// Assert: Expect to be redirected to the home page | ||
expect(mockedHistoryPush).toHaveBeenCalledWith('/bounties'); | ||
}); | ||
|
||
// Other tests for different scenarios... | ||
}); |