Skip to content

Commit

Permalink
feat: ameliorations commentaire action
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurlbrjc committed Nov 27, 2024
1 parent 293c505 commit c992882
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,11 @@ function DetailActionPage({
</dl>
</div>

<CommentaireAction action={action} beneficiaire={jeune} />
<CommentaireAction
action={action}
beneficiaire={jeune}
initiallyOpened={!action.comment}
/>

<HistoriqueAction action={action} />

Expand Down
6 changes: 4 additions & 2 deletions components/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ import IconComponent, { IconName } from 'components/ui/IconComponent'
interface DetailsProps {
summary: string
children: ReactNode
initiallyOpened?: boolean
}

function Details(
{ summary, children }: DetailsProps,
{ summary, children, initiallyOpened = false }: DetailsProps,
ref: ForwardedRef<{ focusSummary: () => void }>
) {
const detailsRef = useRef<HTMLDetailsElement>(null)
useImperativeHandle(ref, () => ({
focusSummary: () => detailsRef.current!.querySelector('summary')!.focus(),
}))

const [expanded, setExpanded] = useState<boolean>()
const [expanded, setExpanded] = useState<boolean>(initiallyOpened)

useEffect(() => {
function toggleExpanded() {
Expand All @@ -40,6 +41,7 @@ function Details(
<details
ref={detailsRef}
className='bg-primary_lighten p-6 mt-8 rounded-base shadow-base'
open={initiallyOpened}
>
<summary
className={`text-m-bold text-primary relative flex justify-between items-center cursor-pointer ${expanded ? 'mb-5' : ''}`}
Expand Down
13 changes: 11 additions & 2 deletions components/action/CommentaireAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,22 @@ import { useChatCredentials } from 'utils/chat/chatCredentialsContext'
interface CommentaireActionProps {
beneficiaire: BaseBeneficiaire
action: Action
initiallyOpened: boolean
}

export default function CommentaireAction({
beneficiaire,
action,
initiallyOpened,
}: CommentaireActionProps) {
const chatCredentials = useChatCredentials()
const detailsRef = useRef<{ focusSummary: () => void }>(null)
const inputRef = useRef<HTMLTextAreaElement>(null)

const DEFAULT_MESSAGE =
'Pouvez-vous compléter la description de cette action s’il vous plaît ?'
const [message, setMessage] = useState<ValueWithError<string | undefined>>({
value: undefined,
value: DEFAULT_MESSAGE,
})
const [envoiEnCours, setEnvoiEnCours] = useState<boolean>(false)
const [succesEnvoi, setSuccesEnvoi] = useState<boolean | undefined>(undefined)
Expand Down Expand Up @@ -58,7 +62,11 @@ export default function CommentaireAction({
}

return (
<Details summary='Commentaire' ref={detailsRef}>
<Details
summary='Commentaire'
ref={detailsRef}
initiallyOpened={initiallyOpened}
>
{succesEnvoi && (
<SuccessAlert
label='Votre message a bien été envoyé, retrouvez le dans votre conversation avec le bénéficiaire.'
Expand All @@ -80,6 +88,7 @@ export default function CommentaireAction({
<Textarea
ref={inputRef}
id='commentaire-action'
defaultValue={message.value}
onChange={(value) => setMessage({ value })}
invalid={Boolean(message.error)}
required
Expand Down
27 changes: 16 additions & 11 deletions tests/pages/DetailActionPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,26 +155,31 @@ describe('ActionPage client side', () => {

it('demande la saisi d’un message', async () => {
expect(
within(group).getByRole('button', {
name: 'Envoyer au bénéficiaire',
within(group).getByRole('textbox', {
name: 'Demander plus d’information au bénéficiaire sur l’action',
})
).toHaveAttribute('disabled')
).toHaveValue(
'Peux-tu renseigner la description de cette action s’il te plaît ?'
)
})

it('envoie un message', async () => {
//
expect(group).toHaveAttribute('open')

// Given
const pouet = within(group).getByRole('textbox', {
name: 'Demander plus d’information au bénéficiaire sur l’action',
})
// FIXME pourquoi ça marche pas avec userEvent.click ? 🤨
fireEvent.change(pouet, {
target: {
value: 'Peux tu me détailler quelles recherches tu as fait stp ?',
},
})
fireEvent.change(
within(group).getByRole('textbox', {
name: 'Demander plus d’information au bénéficiaire sur l’action',
}),
{
target: {
value:
'Peux tu me détailler quelles recherches tu as fait stp ?',
},
}
)

// When
await userEvent.click(
Expand Down

0 comments on commit c992882

Please sign in to comment.