Skip to content

Commit 9323599

Browse files
committed
Add dashboard tests for defect configs
1 parent 89a001f commit 9323599

File tree

3 files changed

+29
-275
lines changed

3 files changed

+29
-275
lines changed

frontend/src/__tests__/Dashboard.test.js

+29-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import React from 'react';
2-
import { render, screen } from '@testing-library/react';
2+
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
33
import '@testing-library/jest-dom';
44
import Dashboard from '../components/dashboard/Dashboard';
55

66
// Mock subcomponents that are imported in Dashboard
77
jest.mock('../components/dashboard/Chart', () => () => <div>Mocked Chart Component</div>);
88
jest.mock('../components/dashboard/Deposits', () => () => <div>Mocked Deposits Component</div>);
9-
jest.mock('../components/defectConfig/DefectConfig', () => () => <div>Mocked Orders Component</div>);
9+
10+
// Mock the DefectConfig component to include the Apply button and Snackbar
11+
jest.mock('../components/defectConfig/DefectConfig', () => () => (
12+
<div>
13+
Mocked DefectConfig Component
14+
<button onClick={() => {}}>Apply</button>
15+
<div role="alert">Defect configuration updated successfully!</div>
16+
</div>
17+
));
1018

1119
describe('Dashboard Component', () => {
1220
test('renders the Dashboard component', () => {
@@ -24,4 +32,23 @@ describe('Dashboard Component', () => {
2432
expect(screen.getByText(/Copyright ©/i)).toBeInTheDocument();
2533
expect(screen.getByText('Karevo')).toBeInTheDocument();
2634
});
35+
36+
test('shows success message when Apply button is clicked', async () => {
37+
render(<Dashboard />);
38+
39+
// Check if the Apply button is present
40+
const applyButton = screen.getByText('Apply');
41+
expect(applyButton).toBeInTheDocument();
42+
43+
// Mock the click event and verify Snackbar visibility
44+
fireEvent.click(applyButton);
45+
46+
// Wait for the success message to appear
47+
await waitFor(() => {
48+
expect(screen.getByRole('alert')).toHaveTextContent('Defect configuration updated successfully!');
49+
});
50+
51+
// Optionally, you can test if the message disappears after 3 seconds
52+
await new Promise((resolve) => setTimeout(resolve, 3000));
53+
});
2754
});

frontend/src/__tests__/ParameterSelection.test.js

-54
This file was deleted.

frontend/src/components/parameterSelection/ParameterSelection.jsx

-219
This file was deleted.

0 commit comments

Comments
 (0)