-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
198 add ecmps beta apis to api docs cards (#201)
* Added ECMPS beta cards * Added context about ECMPS and CAMPD and links to Power Sector Emission Data Guide * Added Tags for CAMPD and ECMPS as well as the beta * Split the API Doc card from the API Docs component
- Loading branch information
1 parent
550819a
commit 52bfbf8
Showing
5 changed files
with
273 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { | ||
Card, | ||
CardHeader, | ||
CardBody, | ||
CardFooter, | ||
Button, | ||
Tag, | ||
} from "@trussworks/react-uswds"; | ||
import React, { useRef, useEffect } from "react"; | ||
import { Link as RouterLink } from "react-router-dom"; | ||
|
||
export const APIDocCard = ({ page, index }) => { | ||
const apiCardDocsRef = useRef(null); | ||
useEffect(() => { | ||
apiCardDocsRef.current.focus(); | ||
}); | ||
|
||
return ( | ||
<Card gridLayout={{ desktop: { col: 4 } }} key={index} align="left"> | ||
<CardHeader> | ||
<h2 | ||
card-testid="card-title" | ||
tabIndex={-1} | ||
ref={apiCardDocsRef} | ||
style={{ outline: "none" }} | ||
> | ||
{page.title} | ||
</h2> | ||
</CardHeader> | ||
<CardBody> | ||
{page.tags.map((tag) => { | ||
return <Tag>{tag}</Tag>; | ||
})} | ||
<p>{page.description}</p> | ||
</CardBody> | ||
<CardFooter> | ||
<RouterLink | ||
to={`/swagger/${page.name}`} | ||
rel="noopener noreferrer" | ||
aria-label={`Link to ${page.title} API documentation`} | ||
> | ||
<Button className="usa-button" type="button"> | ||
View {page.title} docs | ||
</Button> | ||
</RouterLink> | ||
</CardFooter> | ||
</Card> | ||
); | ||
}; |
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,57 @@ | ||
import React from "react"; | ||
import { getByText, render, waitFor, screen } from "@testing-library/react"; | ||
import { APIDocCard } from "./APIDocCard"; | ||
import { axe, toHaveNoViolations } from "jest-axe"; | ||
import { MemoryRouter } from "react-router-dom"; | ||
import { CardGroup } from "@trussworks/react-uswds"; | ||
|
||
window.open = jest.fn(); // mock window.open for testing the card | ||
jest.setTimeout(30000); | ||
|
||
describe("test the APIDocs page", () => { | ||
it("renders the main content", async () => { | ||
window.open.mockClear(); | ||
render( | ||
<MemoryRouter> | ||
<CardGroup> | ||
<APIDocCard | ||
page={{ | ||
title: "Beta", | ||
name: "test", | ||
description: "read", | ||
tags: ["ECMPS"], | ||
}} | ||
index={1} | ||
/> | ||
</CardGroup> | ||
</MemoryRouter> | ||
); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText("Beta")).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
expect.extend(toHaveNoViolations); | ||
|
||
test("should pass axe accessibility tests", async () => { | ||
const { container } = render( | ||
<MemoryRouter> | ||
<CardGroup> | ||
<APIDocCard | ||
page={{ | ||
title: "Beta", | ||
name: "test", | ||
description: "read", | ||
tags: ["ECMPS"], | ||
}} | ||
index={1} | ||
/> | ||
</CardGroup> | ||
</MemoryRouter> | ||
); | ||
const results = await axe(container); | ||
|
||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |
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