Skip to content

Commit

Permalink
Use mock base API URL
Browse files Browse the repository at this point in the history
  • Loading branch information
thisusernameisnowtaken committed Nov 28, 2023
1 parent a2938c0 commit b95d849
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions app/src/components/generic/backButton/BackButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,21 @@ import { routes } from '../../../types/generic/routes';
import { endpoints } from '../../../types/generic/endpoints';
import { useBaseAPIUrl } from '../../../providers/configProvider/ConfigProvider';


jest.mock('../../../providers/configProvider/ConfigProvider');
const mockUseBaseAPIUrl = useBaseAPIUrl as jest.Mock;
const testUrl = '/test'

describe('BackButton', () => {

beforeEach(() => {
process.env.REACT_APP_ENVIRONMENT = 'jest';
mockUseBaseAPIUrl.mockReturnValue(testUrl);
});
afterEach(() => {
jest.clearAllMocks();
});

it('navigates to previous page when clicking the back buttonand not on the search pages', async () => {
const history = createMemoryHistory({
initialEntries: ['/', '/example'],
Expand All @@ -28,8 +42,6 @@ describe('BackButton', () => {
});

it('calls the login handler when clicking the back button on the upload search page', async () => {
const test_location_prefix = useBaseAPIUrl();

const history = createMemoryHistory({
initialEntries: ['/', '/example'],
initialIndex: 1,
Expand All @@ -53,13 +65,11 @@ describe('BackButton', () => {
userEvent.click(screen.getByText('Back'));

await waitFor(() => {
expect(window.location.replace).toBeCalledWith(test_location_prefix + endpoints.LOGIN);
expect(window.location.replace).toBeCalledWith(testUrl + endpoints.LOGIN);
});
});

it('calls the login handler when clicking the back button on the download search page', async () => {
const test_location_prefix = useBaseAPIUrl();

const history = createMemoryHistory({
initialEntries: ['/', '/example'],
initialIndex: 1,
Expand All @@ -83,7 +93,7 @@ describe('BackButton', () => {
userEvent.click(screen.getByText('Back'));

await waitFor(() => {
expect(window.location.replace).toBeCalledWith(test_location_prefix + endpoints.LOGIN);
expect(window.location.replace).toBeCalledWith(testUrl + endpoints.LOGIN);
});
});
});

0 comments on commit b95d849

Please sign in to comment.