-
Notifications
You must be signed in to change notification settings - Fork 3
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 #57 from BUMETCS673/fix_frontend_test
fixed the frontend test and added serverRequest test
- Loading branch information
Showing
3 changed files
with
43 additions
and
17 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 |
---|---|---|
@@ -1,15 +1,35 @@ | ||
import apiClient from '../services/apiClient.js' | ||
// frontend.test.js | ||
import { render, screen } from '@testing-library/react'; | ||
import App from '../App'; | ||
|
||
// tests | ||
// test('test connection to server', async () => { | ||
// const response = await apiClient.get('/check-connection'); | ||
// expect(response.status).toBe(200); | ||
// }) | ||
|
||
test('renders home text', () => { | ||
render(<App />); | ||
const homeElement = screen.getByText(/welcome to the home page/i); // case-insensitive due to the regular expression /i | ||
expect(homeElement).toBeInTheDocument(); | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import App from '../App.js'; | ||
// import { authenticated } from '../utils/authenticate.js'; | ||
|
||
// Mock the charts | ||
jest.mock('react-chartjs-2', () => ({ | ||
Line: () => <div>Mocked Line Chart</div>, | ||
})); | ||
|
||
// Mock the authenticated function to prevent redirection | ||
jest.mock('../utils/authenticate.js', () => ({ | ||
authenticated: jest.fn(), | ||
})); | ||
|
||
beforeEach(() => { | ||
// Simulate authenticated user | ||
localStorage.setItem('authToken', 'mock-token'); | ||
}); | ||
|
||
afterEach(() => { | ||
// Cleanup localStorage | ||
localStorage.removeItem('authToken'); | ||
}); | ||
|
||
test('renders home page with mocked charts', () => { | ||
render( | ||
<App RouterComponent={MemoryRouter} /> | ||
); | ||
|
||
const mockCharts = screen.getAllByText(/Mocked Line Chart/i); | ||
expect(mockCharts[0]).toBeInTheDocument(); | ||
expect(mockCharts).toHaveLength(5); // Adjust based on the number of charts expected | ||
}); |
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,7 @@ | ||
import apiClient from '../services/apiClient.js' | ||
|
||
|
||
test('test connection to server', async () => { | ||
const response = await apiClient.get('/'); | ||
expect(response.status).toBe(200); | ||
}) |