-
Notifications
You must be signed in to change notification settings - Fork 19
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
) * Adds a CTA box on the opportunity detail page with link to legacy site * upgrades the testing-library package to fix bug with querying for paragraph role
- Loading branch information
1 parent
9d22440
commit dfd3e74
Showing
14 changed files
with
200 additions
and
43 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { environment } from "src/constants/environments"; | ||
|
||
import { useTranslations } from "next-intl"; | ||
import { ReactNode } from "react"; | ||
import { Button } from "@trussworks/react-uswds"; | ||
|
||
import { USWDSIcon } from "src/components/USWDSIcon"; | ||
|
||
export const OpportunityContentBox = ({ | ||
title, | ||
content, | ||
}: { | ||
title?: string | ReactNode; | ||
content: string | ReactNode; | ||
}) => { | ||
return ( | ||
<div className="border radius-md border-base-lighter padding-x-2"> | ||
{title && <p className="text-bold margin-bottom-0">{title}</p>} | ||
<p className="desktop-lg:font-sans-sm margin-top-0">{content}</p> | ||
</div> | ||
); | ||
}; | ||
|
||
const OpportunityCTA = ({ id }: { id: number }) => { | ||
const t = useTranslations("OpportunityListing.cta"); | ||
const legacyOpportunityURL = `${environment.LEGACY_HOST}/search-results-detail/${id}`; | ||
|
||
const content = ( | ||
<> | ||
<span>{t("apply_content")}</span> | ||
<a href={legacyOpportunityURL} target="_blank" rel="noopener noreferrer"> | ||
<Button type="button" outline={true} className="margin-top-2"> | ||
<span>{t("button_content")}</span> | ||
<USWDSIcon | ||
name="launch" | ||
className="usa-icon usa-icon--size-4 text-middle" | ||
/> | ||
</Button> | ||
</a> | ||
</> | ||
); | ||
|
||
return ( | ||
<div className="usa-prose margin-top-2"> | ||
<OpportunityContentBox title={t("apply_title")} content={content} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default OpportunityCTA; |
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
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
62 changes: 62 additions & 0 deletions
62
frontend/tests/components/opportunity/OpportunityCTA.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,62 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { useTranslationsMock } from "src/utils/testing/intlMocks"; | ||
|
||
import OpportunityCTA, { | ||
OpportunityContentBox, | ||
} from "src/components/opportunity/OpportunityCTA"; | ||
|
||
jest.mock("next-intl", () => ({ | ||
useTranslations: () => useTranslationsMock(), | ||
})); | ||
|
||
describe("OpportunityCTA", () => { | ||
it("renders the expected content and title", () => { | ||
render(<OpportunityCTA id={1} />); | ||
|
||
expect(screen.getByText("apply_title")).toBeInTheDocument(); | ||
expect(screen.getByText("apply_content")).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders a link that links out to the opportunity detail on grants.gov", () => { | ||
render(<OpportunityCTA id={1} />); | ||
|
||
const link = screen.getByRole("link"); | ||
expect(link).toBeInTheDocument(); | ||
expect(link).toHaveAttribute( | ||
"href", | ||
"https://test.grants.gov/search-results-detail/1", | ||
); | ||
}); | ||
}); | ||
|
||
describe("OpportunityContentBox", () => { | ||
it("displays title if one is provided", () => { | ||
render(<OpportunityContentBox title="fun title" content="fun content" />); | ||
expect(screen.getByText("fun title")).toBeInTheDocument(); | ||
}); | ||
it("does not displays title if one is not provided", () => { | ||
render(<OpportunityContentBox content="fun content" />); | ||
expect(screen.getAllByRole("paragraph")).toHaveLength(1); | ||
}); | ||
it("displays content as string or React children", () => { | ||
const { rerender } = render( | ||
<OpportunityContentBox title="fun title" content="fun content" />, | ||
); | ||
expect(screen.getByText("fun content")).toBeInTheDocument(); | ||
|
||
rerender( | ||
<OpportunityContentBox | ||
title="fun title" | ||
content={ | ||
<> | ||
<span>Some Stuff</span> | ||
<button>A button</button> | ||
</> | ||
} | ||
/>, | ||
); | ||
|
||
expect(screen.getByText("Some Stuff")).toBeInTheDocument(); | ||
expect(screen.getByRole("button")).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.