From a4300b1ee8f3d87d54caabe1e1c6d5d106d5fd8e Mon Sep 17 00:00:00 2001 From: Hamed Valiollahi Bayeki Date: Wed, 11 Dec 2024 13:21:26 -0800 Subject: [PATCH] fix: collapse gov comments to organizations box by default --- .../views/Transfers/components/Comments.jsx | 9 +++++-- .../Transfers/components/TransferView.jsx | 12 +++++---- .../components/__tests__/Comments.test.jsx | 26 +++++++++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/frontend/src/views/Transfers/components/Comments.jsx b/frontend/src/views/Transfers/components/Comments.jsx index f53f74614..ce69e042a 100644 --- a/frontend/src/views/Transfers/components/Comments.jsx +++ b/frontend/src/views/Transfers/components/Comments.jsx @@ -6,9 +6,14 @@ import { useFormContext } from 'react-hook-form' import { LabelBox } from './LabelBox' import { useTranslation } from 'react-i18next' -export const Comments = ({ editorMode, isGovernmentUser, commentField }) => { +export const Comments = ({ + editorMode, + isGovernmentUser, + commentField, + isDefaultExpanded = false +}) => { const { t } = useTranslation(['transfer']) - const [isExpanded, setIsExpanded] = useState(true) + const [isExpanded, setIsExpanded] = useState(!isDefaultExpanded) const { register, diff --git a/frontend/src/views/Transfers/components/TransferView.jsx b/frontend/src/views/Transfers/components/TransferView.jsx index a33bbb62e..cd837d0e8 100644 --- a/frontend/src/views/Transfers/components/TransferView.jsx +++ b/frontend/src/views/Transfers/components/TransferView.jsx @@ -1,14 +1,14 @@ import BCBox from '@/components/BCBox' import InternalComments from '@/components/InternalComments' import { Role } from '@/components/Role' -import { govRoles } from '@/constants/roles' +import { roles, govRoles } from '@/constants/roles' import { TRANSFER_STATUSES, getAllTerminalTransferStatuses } from '@/constants/statuses' import { useCurrentUser } from '@/hooks/useCurrentUser' import { decimalFormatter } from '@/utils/formatters' -import { Typography } from '@mui/material' +import BCTypography from '@/components/BCTypography' import PropTypes from 'prop-types' import { useTranslation } from 'react-i18next' import TransferHistory from './TransferHistory' @@ -18,8 +18,9 @@ import { CommentList } from '@/views/Transfers/components/CommentList' export const TransferView = ({ transferId, editorMode, transferData }) => { const { t } = useTranslation(['common', 'transfer']) - const { data: currentUser, sameOrganization } = useCurrentUser() + const { data: currentUser, sameOrganization, hasAnyRole } = useCurrentUser() const isGovernmentUser = currentUser?.isGovernmentUser + const isAnalyst = hasAnyRole(roles.analyst) const { currentStatus: { status: transferStatus } = {}, toOrganization: { name: toOrganization, organizationId: toOrgId } = {}, @@ -55,7 +56,7 @@ export const TransferView = ({ transferId, editorMode, transferData }) => { backgroundColor: 'transparent.main' }} > - + {fromOrganization} {t('transfer:transfers')} {quantity} @@ -64,7 +65,7 @@ export const TransferView = ({ transferId, editorMode, transferData }) => { ${decimalFormatter({ value: pricePerUnit })} {t('transfer:complianceUnitsPerTvo')} ${decimalFormatter(totalValue)} CAD. - + {/* Comments */} {transferData?.comments.length > 0 && ( @@ -84,6 +85,7 @@ export const TransferView = ({ transferId, editorMode, transferData }) => { sameOrganization(toOrgId) && 'toOrgComment') } + isDefaultExpanded={isAnalyst} /> )} diff --git a/frontend/src/views/Transfers/components/__tests__/Comments.test.jsx b/frontend/src/views/Transfers/components/__tests__/Comments.test.jsx index 196c487cf..dc154a904 100644 --- a/frontend/src/views/Transfers/components/__tests__/Comments.test.jsx +++ b/frontend/src/views/Transfers/components/__tests__/Comments.test.jsx @@ -110,4 +110,30 @@ describe('Comments Component', () => { const textField = getByRole('textbox') expect(textField).toHaveAttribute('id', 'external-comments') }) + + it('is initially expanded by default when isDefaultExpanded is false', () => { + render( + + + , + { wrapper } + ) + // With isDefaultExpanded=false, the component should start expanded + expect(screen.getByTestId('external-comments')).toBeVisible() + }) + + it('is initially collapsed when isDefaultExpanded is true', async () => { + render( + + + , + { wrapper } + ) + // With isDefaultExpanded=true, we useState(!true)=false, so it should start collapsed + await waitFor(() => + expect( + screen.getByTestId('external-comments').parentElement + ).not.toBeVisible() + ) + }) })