Skip to content

Commit

Permalink
added analysis dashboard test
Browse files Browse the repository at this point in the history
Signed-off-by: Duncan Ragsdale <[email protected]>
  • Loading branch information
Thistleman committed Feb 28, 2024
1 parent 4129ca3 commit 381bdb3
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 46 deletions.
4 changes: 2 additions & 2 deletions doc/updateProcess.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ The current process is to add all the analysis files into our pvhb s3 bucket and
#!/bin/bash

API_URL="http://api:8005/analysis/create/"
ANALYSIS_NAME="Time Shift Analysis"
analysis_name="Time Shift Analysis"
EVALUATION_SCRIPT_PATH="/pv-validation-hub-bucket/evaluation_scripts/3/pvinsight-time-shift-runner.py"
MAX_CONCURRENT_SUBMISSION_EVALUATION="100"

curl -X POST -H "Content-Type: multipart/form-data" \
-F "analysis_name=$ANALYSIS_NAME" \
-F "analysis_name=$analysis_name" \
-F "evaluation_script=@$EVALUATION_SCRIPT_PATH" \
-F "max_concurrent_submission_evaluation=$MAX_CONCURRENT_SUBMISSION_EVALUATION" \
$API_URL
Expand Down
58 changes: 49 additions & 9 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"react-frame-component": "^5.2.3",
"react-markdown": "^8.0.7",
"react-modal": "^3.16.1",
"react-router": "^6.22.1",
"react-router-dom": "^6.4.2",
"react-scripts": "^5.0.1",
"react-share": "^4.4.1",
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/__tests__/test.js
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();
10 changes: 6 additions & 4 deletions frontend/src/components/Analyses/Analyses.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ import { isDevelopment } from '../../config/environment.js';

export default function Dashboard() {
const navigate = useNavigate();
const [analysis_id, setAnalysisId] = useState();
const [analysis_id, setanalysis_id] = useState();

useEffect(() => {
if (analysis_id !== null && analysis_id !== undefined) {
navigate(`/analysis/${analysis_id}`);
}
}, [analysis_id, navigate]);

const handleCardClick = (card_id, card_title) => {
setAnalysisId(card_id);
const handleCardClick = (cardId, cardTitle) => {
setanalysis_id(cardId);
};

const [isLoading, isError, cardDetails] = DashboardService.useGetAnalysisSet('/analysis/home');
Expand Down Expand Up @@ -81,6 +81,7 @@ export default function Dashboard() {
index={index}
card={card}
onClick={handleCardClick}
testId={`analysis-card${index}`}
/>
))
}
Expand All @@ -92,7 +93,7 @@ export default function Dashboard() {
);
}

function CustomizedCard({ index, card, onClick }) {
function CustomizedCard({ index, card, onClick, testId }) {
const [shortDescription, setShortDescription] = useState('');
const [cardDir, setCardDir] = useState('');

Expand All @@ -113,6 +114,7 @@ function CustomizedCard({ index, card, onClick }) {
sx={{ maxWidth: 345, height: 380 }}
key={card.analysis_id}
onClick={() => onClick(card.analysis_id, card.analysis_name)}
data-testid={testId}
>
<CardHeader
sx={{ height: 61 }}
Expand Down
31 changes: 0 additions & 31 deletions frontend/src/components/Analyses/Analyses.test.js

This file was deleted.

69 changes: 69 additions & 0 deletions frontend/src/components/Analyses/Analyses.tests.js
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());
});
});
*/
}

0 comments on commit 381bdb3

Please sign in to comment.