-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Init card work * Added unit test * Added external link echimp prop and unit test * Update beneficiaries test * Updated unit test
- Loading branch information
1 parent
5af5642
commit 3f80941
Showing
13 changed files
with
238 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/features/ModelPlan/CollaborationArea/Cards/CRTDLCard/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React from 'react'; | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import i18next from 'i18next'; | ||
|
||
import CRTDLCard, { CRTDLType } from './index'; | ||
|
||
const mockCrtdls: CRTDLType[] = [ | ||
{ id: 'crtdl1', __typename: 'EChimpCR' }, | ||
{ id: 'crtdl2', __typename: 'EChimpTDL' } | ||
]; | ||
|
||
describe('CRTDLCard', () => { | ||
it('renders the card with the correct heading', () => { | ||
render( | ||
<Router> | ||
<CRTDLCard crtdls={mockCrtdls} modelID="model123" /> | ||
</Router> | ||
); | ||
|
||
expect( | ||
screen.getByText(i18next.t('collaborationArea:crtdlsCard.heading')) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('displays a message when there are no crtdls', () => { | ||
render( | ||
<Router> | ||
<CRTDLCard crtdls={[]} modelID="model123" /> | ||
</Router> | ||
); | ||
|
||
expect( | ||
screen.getByText(i18next.t('collaborationArea:crtdlsCard.noCrtdls')) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('displays a list of crtdls when they are present', () => { | ||
render( | ||
<Router> | ||
<CRTDLCard crtdls={mockCrtdls} modelID="model123" /> | ||
</Router> | ||
); | ||
|
||
expect(screen.getByText('crtdl1, crtdl2')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders the "View All" button when crtdls are present', () => { | ||
render( | ||
<Router> | ||
<CRTDLCard crtdls={mockCrtdls} modelID="model123" /> | ||
</Router> | ||
); | ||
|
||
expect( | ||
screen.getByText(i18next.t('collaborationArea:crtdlsCard.viewAll')) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('does not render the "View All" button when there are no crtdls', () => { | ||
render( | ||
<Router> | ||
<CRTDLCard crtdls={[]} modelID="model123" /> | ||
</Router> | ||
); | ||
|
||
expect( | ||
screen.queryByText(i18next.t('collaborationArea:crtdlsCard.viewAll')) | ||
).not.toBeInTheDocument(); | ||
}); | ||
}); |
86 changes: 86 additions & 0 deletions
86
src/features/ModelPlan/CollaborationArea/Cards/CRTDLCard/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { | ||
Card, | ||
CardBody, | ||
CardFooter, | ||
CardHeader | ||
} from '@trussworks/react-uswds'; | ||
import { GetModelPlanQuery } from 'gql/generated/graphql'; | ||
|
||
import ExternalLink from 'components/ExternalLink'; | ||
import UswdsReactLink from 'components/LinkWrapper'; | ||
|
||
import '../../index.scss'; | ||
|
||
export type CRTDLType = GetModelPlanQuery['modelPlan']['echimpCRsAndTDLs'][0]; | ||
|
||
type CRTDLCardType = { | ||
crtdls: CRTDLType[]; | ||
modelID: string; | ||
}; | ||
|
||
const CRTDLCard = ({ crtdls = [], modelID }: CRTDLCardType) => { | ||
const { t: collaborationAreaT } = useTranslation('collaborationArea'); | ||
|
||
const firstFirstFiveCRTDLs = crtdls.slice(0, 5); | ||
|
||
const remainingCRTDLs: number = crtdls.length - firstFirstFiveCRTDLs.length; | ||
|
||
return ( | ||
<Card | ||
gridLayout={{ mobile: { col: 12 }, desktop: { col: 4 } }} | ||
className="collaboration-area__card" | ||
> | ||
<CardHeader> | ||
<h3 className="usa-card__heading"> | ||
{collaborationAreaT('crtdlsCard.heading')} | ||
</h3> | ||
</CardHeader> | ||
|
||
<CardBody> | ||
{crtdls?.length === 0 ? ( | ||
<p className="text-base"> | ||
{collaborationAreaT('crtdlsCard.noCrtdls')} | ||
</p> | ||
) : ( | ||
<p className="text-base-dark"> | ||
{firstFirstFiveCRTDLs.map(crtdl => crtdl.id).join(', ')} | ||
{remainingCRTDLs > 0 && ( | ||
<> | ||
{' '} | ||
{collaborationAreaT('crtdlsCard.andMore', { | ||
count: remainingCRTDLs | ||
})} | ||
</> | ||
)} | ||
</p> | ||
)} | ||
</CardBody> | ||
|
||
<CardFooter> | ||
<ExternalLink | ||
href="https://echimp.cmsnet/" | ||
className="usa-button" | ||
variant="unstyled" | ||
asButton | ||
toEchimp | ||
> | ||
{collaborationAreaT('crtdlsCard.addInEChimp')} | ||
</ExternalLink> | ||
|
||
{crtdls?.length !== 0 && ( | ||
<UswdsReactLink | ||
className="usa-button usa-button--outline" | ||
variant="unstyled" | ||
to={`/models/${modelID}/collaboration-area/cr-and-tdl`} | ||
> | ||
{collaborationAreaT('crtdlsCard.viewAll')} | ||
</UswdsReactLink> | ||
)} | ||
</CardFooter> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default CRTDLCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters