feat: Refactor result preparation and add contradiction checks

This commit is contained in:
AG
2025-10-11 17:03:13 +03:00
parent 42303b1fc3
commit fd2676dd5f
14 changed files with 436 additions and 211 deletions

View File

@@ -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

View 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();
});
});

View File

@@ -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();
});
});

View File

@@ -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>
);
};

View File

@@ -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)