-
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.
Signed-off-by: Duncan Ragsdale <[email protected]>
- Loading branch information
1 parent
4129ca3
commit 381bdb3
Showing
7 changed files
with
129 additions
and
46 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,5 +1,7 @@ | ||
// This file is used to run all the tests in the application | ||
import AppTests from '../components/App/App.testsuite.js'; | ||
import DashboardTests from '../components/Analyses/Analyses.tests.js'; | ||
|
||
// This is the exported function that checks the main app page | ||
AppTests(); | ||
DashboardTests(); |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from 'react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import '@testing-library/jest-dom'; | ||
import { | ||
render, screen, cleanup, waitForElementToBeRemoved, waitFor, fireEvent, getByTestId, findByTestId, | ||
} from '@testing-library/react'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import * as router from 'react-router'; | ||
import Dashboard from './Analyses.jsx'; | ||
|
||
// Mock window.location.hostname | ||
global.window = Object.create(window); | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
hostname: 'localhost', | ||
}, | ||
}); | ||
|
||
// Mock the DashboardService module | ||
jest.mock('../../services/dashboard_service.js', () => ({ | ||
useGetAnalysisSet: jest.fn(() => [false, false, [{ id: 'development', title: 'Dev Analysis' }]]), | ||
})); | ||
|
||
// This is the exported function that contains all the tests | ||
export default function DashboardTests() { | ||
// Cleanup after each test | ||
afterEach(cleanup); | ||
|
||
describe('Analyses component', () => { | ||
it('renders without crashing', () => { | ||
render(<Dashboard />, { wrapper: BrowserRouter }); | ||
}); | ||
|
||
it('displays circular progress bar while loading', () => { | ||
render(<Dashboard />, { wrapper: BrowserRouter }); | ||
expect(screen.getByRole('progressbar')).toBeInTheDocument(); | ||
}); | ||
|
||
it('updates card once loading is done', async () => { | ||
render(<Dashboard />, { wrapper: BrowserRouter }); | ||
await waitForElementToBeRemoved(() => screen.getByRole('progressbar')); | ||
expect(screen.getByText('Dev Analysis')).toBeInTheDocument(); | ||
}); | ||
}); | ||
/* | ||
This test needs to be fixed/completed when I have more time. Its... tricky. | ||
describe('Analysis Cards', () => { | ||
it('Should navigate to each analysis page when the card was clicked', async () => { | ||
render(<Dashboard />, { wrapper: BrowserRouter }); | ||
const navigate = jest.fn(); | ||
jest.spyOn(router, 'useNavigate').mockImplementation(() => navigate); | ||
// Wait for the progress bar to be removed | ||
await waitForElementToBeRemoved(() => screen.getByRole('progressbar')); | ||
// Find the card by its analysis_name | ||
const card = screen.getByTestId('analysis-card0'); | ||
// Simulate a user clicking the card | ||
await userEvent.click(card); | ||
console.log("here", navigate); | ||
// Check if navigation was called | ||
await waitFor(() => expect(navigate).toHaveBeenCalled()); | ||
}); | ||
}); | ||
*/ | ||
} |