Skip to content

Commit f605c02

Browse files
authored
Merge pull request #23 from DigitalProductInnovationAndDevelopment/feature/defect-configs-fe-integration
[FEATURE] Defect configs Front-End Integration
2 parents 46f587f + 9323599 commit f605c02

File tree

13 files changed

+192
-427
lines changed

13 files changed

+192
-427
lines changed

backend/controllers/defectConfigsController.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const DefectConfigModel = require("../models/DefectConfigModel");
33

44
const getDefectConfig = async (req, res) => {
55
try {
6-
const defectConfig = await DefectConfigModel.findOne();
6+
const defectConfig = await DefectConfigModel.findOne().exec();
77
res.status(200).json(defectConfig);
88
} catch (error) {
99
res.status(500).json({ message: error.message });

backend/models/DefectConfigModel.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const defectConfigSchema = new mongoose.Schema({
66
type: Number,
77
min: 0,
88
max: 1,
9+
default: 0.6
910
},
1011
dryRot: {
1112
type: Number,

backend/routes/routes.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ const userRoutes = require('./userRoutes.js');
55
const parametersRoutes = require('./parametersRoutes.js');
66
const modelsRoutes = require('./modelsRoutes.js');
77
const trackingHistoryRoutes = require('./trackingHistoryRoutes.js');
8+
const defectConfigRoutes = require('./defectConfigRoutes.js');
89

910
router.use('/users', userRoutes);
1011
router.use('/parameters', parametersRoutes);
1112
router.use('/models', modelsRoutes);
1213
router.use('/tracking-history', trackingHistoryRoutes);
13-
router.use('/defect-config', trackingHistoryRoutes);
14+
router.use('/defect-config', defectConfigRoutes);
1415

1516

1617
module.exports = router;

backend/scripts/seed.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const mongoose = require("mongoose");
22
const User = require("../models/User");
3-
const process = require('process')
3+
const DefectConfig = require("../models/DefectConfigModel");
44
const DetectionModel = require("../models/DetectionModel");
55
require("dotenv").config();
66

77
const seedDatabase = async () => {
88
try {
99
await mongoose.connect(process.env.MONGO_URI);
1010

11-
//seed initial users
11+
// Seed initial users
1212
const admin = await User.findOne({ isAdmin: true });
1313
const client = await User.findOne({ isAdmin: false });
1414

@@ -59,6 +59,16 @@ const seedDatabase = async () => {
5959
} else {
6060
console.log("Model 2 Unloading already exists");
6161
}
62+
63+
// Check and seed the default defect config
64+
const defectConfig = await DefectConfig.findOne();
65+
66+
if (!defectConfig) {
67+
await DefectConfig.create({});
68+
console.log("Default defect config created with default values.");
69+
} else {
70+
console.log("Default defect config already exists.");
71+
}
6272
} catch (err) {
6373
console.log(err);
6474
} finally {

frontend/src/__tests__/Dashboard.test.js

+30-3
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/dashboard/Orders', () => () => <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', () => {
@@ -18,10 +26,29 @@ describe('Dashboard Component', () => {
1826
// Check if the sub-components are rendered
1927
expect(screen.getByText('Mocked Chart Component')).toBeInTheDocument();
2028
expect(screen.getByText('Mocked Deposits Component')).toBeInTheDocument();
21-
expect(screen.getByText('Mocked Orders Component')).toBeInTheDocument();
29+
expect(screen.getByText('Mocked DefectConfig Component')).toBeInTheDocument();
2230

2331
// Check for the presence of the copyright text
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/dashboard/Dashboard.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import ChevronLeftIcon from '@mui/icons-material/ChevronLeft';
1919
import { mainListItems, secondaryListItems } from './listItems';
2020
import Chart from './Chart';
2121
import Deposits from './Deposits';
22-
import Orders from './Orders';
22+
import DefectConfig from '../defectConfig/DefectConfig';
2323
import {Logout} from "@mui/icons-material";
2424

2525
function Copyright(props) {
@@ -188,10 +188,10 @@ export default function Dashboard() {
188188
<Deposits />
189189
</Paper>
190190
</Grid>
191-
{/* Recent Orders */}
191+
{/* Recent DefectConfig */}
192192
<Grid item xs={12}>
193193
<Paper sx={{ p: 2, display: 'flex', flexDirection: 'column' }}>
194-
<Orders />
194+
<DefectConfig />
195195
</Paper>
196196
</Grid>
197197
</Grid>

frontend/src/components/dashboard/Orders.js

-96
This file was deleted.

frontend/src/components/dashboard/listItems.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import DashboardIcon from '@mui/icons-material/Dashboard';
77
import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
88
import PeopleIcon from '@mui/icons-material/People';
99
import BarChartIcon from '@mui/icons-material/BarChart';
10-
import LayersIcon from '@mui/icons-material/Layers';
1110
import AssignmentIcon from '@mui/icons-material/Assignment';
1211

1312
export const mainListItems = (
@@ -22,7 +21,7 @@ export const mainListItems = (
2221
<ListItemIcon>
2322
<ShoppingCartIcon />
2423
</ListItemIcon>
25-
<ListItemText primary="Orders" />
24+
<ListItemText primary="DefectConfig" />
2625
</ListItemButton>
2726
<ListItemButton>
2827
<ListItemIcon>

0 commit comments

Comments
 (0)