-
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.
[test(global)][index/app]: setup initial testing environment
DESCRIPTION: This commit sets up the initial testing environment for the application. BREAKING_CHANGE: Error caused by react/swiper import not being found causes breaking change for tests.
- Loading branch information
Showing
50 changed files
with
475 additions
and
714 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
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 @@ | ||
module.exports = 'test-file-stub'; |
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,9 @@ | ||
// <rootDir>/__mocks__/swiper/react.js | ||
import React from 'react'; | ||
|
||
export const Swiper = ({ children }) => ( | ||
<div className="mock-swiper">{children}</div> | ||
); | ||
export const SwiperSlide = ({ children }) => ( | ||
<div className="mock-swiper-slide">{children}</div> | ||
); |
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,2 @@ | ||
import '@testing-library/jest-dom/extend-expect'; | ||
// Directly in your test file or in src/setupTests.js |
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,63 @@ | ||
// App.test.js | ||
import React from 'react'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
import App from 'App'; | ||
|
||
// Mocking modules and context | ||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useNavigate: () => jest.fn(), | ||
})); | ||
jest.mock('context', () => ({ | ||
useManageCookies: () => ({ | ||
getCookie: jest.fn().mockReturnValue({ authUser: null, isLoggedIn: false }), | ||
}), | ||
})); | ||
jest.mock('context', () => ({ | ||
useMode: () => ({ theme: {} }), | ||
})); | ||
jest.mock('context', () => ({ | ||
useAuthManager: () => ({ | ||
logout: jest.fn(), | ||
}), | ||
})); | ||
jest.mock('context', () => ({ | ||
useConfigurator: () => ({ | ||
isConfiguratorOpen: false, | ||
}), | ||
})); | ||
jest.mock('layout/dialogs/LoginDialog', () => () => <div>LoginDialog</div>); | ||
jest.mock('layout/navigation', () => () => <div>Navigation</div>); | ||
jest.mock('layout/REUSABLE_COMPONENTS/Configurator', () => () => ( | ||
<div>Configurator</div> | ||
)); | ||
jest.mock('layout/REUSABLE_COMPONENTS', () => () => ( | ||
<div>LoadingOverlay</div> | ||
)); | ||
jest.mock('layout/REUSABLE_COMPONENTS', () => () => ( | ||
<div>PageLayout</div> | ||
)); | ||
|
||
// Helper to wrap component with router context | ||
const renderWithRouter = (ui, { route = '/' } = {}) => { | ||
window.history.pushState({}, 'Test page', route); | ||
return render(ui, { wrapper: Router }); | ||
}; | ||
|
||
describe('App Component', () => { | ||
it('should redirect to login if not authenticated', async () => { | ||
renderWithRouter(<App />); | ||
await waitFor(() => | ||
expect(screen.getByText('LoginDialog')).toBeInTheDocument() | ||
); | ||
}); | ||
|
||
it('should display the navigation and page layout', () => { | ||
renderWithRouter(<App />); | ||
expect(screen.getByText('Navigation')).toBeInTheDocument(); | ||
expect(screen.getByText('PageLayout')).toBeInTheDocument(); | ||
}); | ||
|
||
// Add more tests as needed for different scenarios | ||
}); |
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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// hooks/useDialogState.js | ||
import { useState, useCallback } from 'react'; | ||
|
||
const useDialogState = () => { | ||
|
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
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
Oops, something went wrong.