Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { render, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { PdsGoalsList } from '../GoalsList/PdsGoalsList';
import { PdsGoalCalculatorTestWrapper } from '../PdsGoalCalculatorTestWrapper';

Expand Down Expand Up @@ -65,6 +66,42 @@
expect(await findByTestId('date-value')).toHaveTextContent('March 15');
});

it('shows the full goal name in a tooltip on hover', async () => {
const longName =
'A very long goal name that would otherwise stretch the card';
const { findByTestId, findByRole } = render(
<PdsGoalCalculatorTestWrapper
withProvider={false}
calculationsMock={{
nodes: [{ name: longName }],
}}
>
<PdsGoalsList />
</PdsGoalCalculatorTestWrapper>,
);

userEvent.hover(await findByTestId('goal-name'));

expect(await findByRole('tooltip')).toHaveTextContent(longName);
});

Check warning on line 86 in src/components/HrTools/PdsGoalCalculator/GoalCard/PdsGoalCard.test.tsx

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ New issue: Code Duplication

The module contains 6 functions with similar structure: 'renders the Delete and View buttons','renders the goal name in the card','renders the last updated date','renders unnamed goal when name is null' and 2 more functions. Avoid duplicated, aka copy-pasted, code inside the module. More duplication lowers the code health.

it('shows the unnamed goal fallback in a tooltip on hover', async () => {
const { findByTestId, findByRole } = render(
<PdsGoalCalculatorTestWrapper
withProvider={false}
calculationsMock={{
nodes: [{ name: null }],
}}
>
<PdsGoalsList />
</PdsGoalCalculatorTestWrapper>,
);

userEvent.hover(await findByTestId('goal-name'));

expect(await findByRole('tooltip')).toHaveTextContent('Unnamed Goal');
});

it('renders the calculated goal amount', async () => {
const { findByTestId } = render(
<PdsGoalCalculatorTestWrapper
Expand Down
17 changes: 13 additions & 4 deletions src/components/HrTools/PdsGoalCalculator/GoalCard/PdsGoalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Card,
Divider,
Skeleton,
Tooltip,
Typography,
styled,
} from '@mui/material';
Expand All @@ -24,7 +25,7 @@
} from '../calculations/calculatePdsGoalTotal';

const StyledCard = styled(Card)(({ theme }) => ({
minWidth: 350,
width: 350,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] `width: 350` hard-caps the card on narrow viewports — at <350px the card overflows the container. Adding `maxWidth: '100%'` lets the card shrink below 350px on small mobile screens while still capping it above:
const StyledCard = styled(Card)(({ theme }) => ({
  width: 350,
  maxWidth: '100%',
  borderRadius: theme.shape.borderRadius,
}));

borderRadius: theme.shape.borderRadius,
}));

Expand All @@ -34,6 +35,7 @@
justifyContent: 'center',
marginBottom: theme.spacing(2),
marginTop: theme.spacing(2),
paddingInline: theme.spacing(2),
}));

const StyledContentBox = styled(Box)(({ theme }) => ({
Expand Down Expand Up @@ -127,9 +129,16 @@

<StyledCard>
<StyledHeaderBox>
<Typography data-testid="goal-name" variant="h6">
{goal.name ?? t('Unnamed Goal')}
</Typography>
<Tooltip title={goal.name ?? t('Unnamed Goal')}>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] `goal.name ??` only catches `null`/`undefined`, not `''` or whitespace-only strings. If your server-side `.required()` validation already blocks those, this is a non-issue — otherwise `goal.name?.trim() || t('Unnamed Goal')` would harden both the visible text and the tooltip:
<Tooltip title={goal.name?.trim() || t('Unnamed Goal')}>
  <Typography ...>
    {goal.name?.trim() || t('Unnamed Goal')}
  </Typography>
</Tooltip>

<Typography
data-testid="goal-name"
variant="h6"
noWrap
sx={{ width: '100%', textAlign: 'center' }}
>
{goal.name ?? t('Unnamed Goal')}
</Typography>
</Tooltip>

Check warning on line 141 in src/components/HrTools/PdsGoalCalculator/GoalCard/PdsGoalCard.tsx

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ New issue: Large Method

PdsGoalCard:React.FC<PdsGoalCardProps> has 120 lines, threshold = 120. Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function.
</StyledHeaderBox>

<Divider />
Expand Down
Loading