feat: Refactor result preparation and add contradiction checks
This commit is contained in:
@@ -48,6 +48,8 @@ const DesireForm: React.FC<DesireFormProps> = ({ onSubmit }) => {
|
||||
value={wants}
|
||||
onChange={(e) => setWants(e.target.value)}
|
||||
margin="normal"
|
||||
inputProps={{ maxLength: 500 }}
|
||||
helperText={`${wants.length}/500`}
|
||||
/>
|
||||
|
||||
<Typography variant="h6" gutterBottom sx={{ mt: 4 }}>What you ACCEPT</Typography>
|
||||
@@ -59,6 +61,8 @@ const DesireForm: React.FC<DesireFormProps> = ({ onSubmit }) => {
|
||||
value={accepts}
|
||||
onChange={(e) => setAccepts(e.target.value)}
|
||||
margin="normal"
|
||||
inputProps={{ maxLength: 500 }}
|
||||
helperText={`${accepts.length}/500`}
|
||||
/>
|
||||
|
||||
<Typography variant="h6" gutterBottom sx={{ mt: 4 }}>What you DO NOT WANT</Typography>
|
||||
@@ -70,6 +74,8 @@ const DesireForm: React.FC<DesireFormProps> = ({ onSubmit }) => {
|
||||
value={noGoes}
|
||||
onChange={(e) => setNoGoes(e.target.value)}
|
||||
margin="normal"
|
||||
inputProps={{ maxLength: 500 }}
|
||||
helperText={`${noGoes.length}/500`}
|
||||
/>
|
||||
|
||||
<Button
|
||||
|
||||
33
frontend/src/components/ResultsDisplay.refactor.test.tsx
Normal file
33
frontend/src/components/ResultsDisplay.refactor.test.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import ResultsDisplay from './ResultsDisplay';
|
||||
import { Decision } from '../hooks/useSession';
|
||||
|
||||
describe('ResultsDisplay Refactor', () => {
|
||||
it('should render all categories correctly', () => {
|
||||
const decision: Decision = {
|
||||
goTo: ['Pizza'],
|
||||
alsoGood: ['Pasta'],
|
||||
considerable: ['Burgers'],
|
||||
noGoes: ['Salad'],
|
||||
needsDiscussion: ['Tacos'],
|
||||
};
|
||||
|
||||
render(<ResultsDisplay decision={decision} />);
|
||||
|
||||
expect(screen.getByText('Go-to')).toBeInTheDocument();
|
||||
expect(screen.getByText('Pizza')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText('Also good')).toBeInTheDocument();
|
||||
expect(screen.getByText('Pasta')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText('Considerable')).toBeInTheDocument();
|
||||
expect(screen.getByText('Burgers')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText('No-goes')).toBeInTheDocument();
|
||||
expect(screen.getByText('Salad')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText('Needs discussion')).toBeInTheDocument();
|
||||
expect(screen.getByText('Tacos')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -1,29 +0,0 @@
|
||||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import ResultsDisplay from './ResultsDisplay';
|
||||
import { Decision } from '../hooks/useSession';
|
||||
|
||||
const mockDecision: Decision = {
|
||||
goTos: [{ title: 'Go to the beach', rawInputs: ['beach'] }],
|
||||
alsoGoods: [{ title: 'Eat pizza', rawInputs: ['pizza'] }],
|
||||
considerables: [{ title: 'Watch a movie', rawInputs: ['movie'] }],
|
||||
noGoes: [{ title: 'Stay home', rawInputs: ['home'] }],
|
||||
};
|
||||
|
||||
describe('ResultsDisplay', () => {
|
||||
it('renders all categories correctly', () => {
|
||||
render(<ResultsDisplay decision={mockDecision} />);
|
||||
|
||||
expect(screen.getByText('Go-to')).toBeInTheDocument();
|
||||
expect(screen.getByText('Go to the beach')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText('Also good')).toBeInTheDocument();
|
||||
expect(screen.getByText('Eat pizza')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText('Considerable')).toBeInTheDocument();
|
||||
expect(screen.getByText('Watch a movie')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText('No-goes')).toBeInTheDocument();
|
||||
expect(screen.getByText('Stay home')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -2,13 +2,13 @@ import React from 'react';
|
||||
import { Box, Typography, List, ListItem, ListItemText, Collapse, IconButton } from '@mui/material';
|
||||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
||||
import ExpandLessIcon from '@mui/icons-material/ExpandLess';
|
||||
import { Decision, SemanticDesire } from '../hooks/useSession';
|
||||
import { Decision } from '../hooks/useSession';
|
||||
|
||||
interface ResultsDisplayProps {
|
||||
decision: Decision;
|
||||
}
|
||||
|
||||
const CategorySection: React.FC<{ title: string; desires: SemanticDesire[]; defaultExpanded?: boolean }>
|
||||
const CategorySection: React.FC<{ title: string; desires: string[]; defaultExpanded?: boolean }>
|
||||
= ({ title, desires, defaultExpanded = true }) => {
|
||||
const [expanded, setExpanded] = React.useState(defaultExpanded);
|
||||
|
||||
@@ -30,7 +30,7 @@ const CategorySection: React.FC<{ title: string; desires: SemanticDesire[]; defa
|
||||
<List dense>
|
||||
{desires.map((desire, index) => (
|
||||
<ListItem key={index}>
|
||||
<ListItemText primary={desire.title} />
|
||||
<ListItemText primary={desire} />
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
@@ -50,10 +50,11 @@ const ResultsDisplay: React.FC<ResultsDisplayProps> = ({ decision }) => {
|
||||
Cooperative Decision
|
||||
</Typography>
|
||||
|
||||
<CategorySection title="Go-to" desires={decision.goTos} />
|
||||
<CategorySection title="Also good" desires={decision.alsoGoods} />
|
||||
<CategorySection title="Considerable" desires={decision.considerables} defaultExpanded={false} />
|
||||
<CategorySection title="Go-to" desires={decision.goTo} />
|
||||
<CategorySection title="Also good" desires={decision.alsoGood} />
|
||||
<CategorySection title="Considerable" desires={decision.considerable} defaultExpanded={false} />
|
||||
<CategorySection title="No-goes" desires={decision.noGoes} />
|
||||
<CategorySection title="Needs discussion" desires={decision.needsDiscussion} />
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -17,16 +17,12 @@ export interface DesireSet {
|
||||
noGoes: string[];
|
||||
}
|
||||
|
||||
export interface SemanticDesire {
|
||||
title: string;
|
||||
rawInputs: string[];
|
||||
}
|
||||
|
||||
export interface Decision {
|
||||
goTos: SemanticDesire[];
|
||||
alsoGoods: SemanticDesire[];
|
||||
considerables: SemanticDesire[];
|
||||
noGoes: SemanticDesire[];
|
||||
goTo: string[];
|
||||
alsoGood: string[];
|
||||
considerable: string[];
|
||||
noGoes: string[];
|
||||
needsDiscussion: string[];
|
||||
}
|
||||
|
||||
// Define the SessionState enum (mirroring backend)
|
||||
|
||||
Reference in New Issue
Block a user