Skip to content

Commit 734e33c

Browse files
author
Said Shah
committed
Added a test-util file, added tests for link card, and added a default value for the to field in link card
1 parent a5fb714 commit 734e33c

3 files changed

Lines changed: 52 additions & 2 deletions

File tree

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
import React from "react";
2+
import faker from "faker";
3+
import { LinkCard } from "./link-card";
4+
import { TestUtils } from "../../tests/test-utils";
5+
16
describe("LinkCard", () => {
2-
test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/36", () => {});
7+
test("When default props renders children", () => {
8+
// Arrange
9+
const expected = faker.random.words();
10+
const label = faker.random.words();
11+
12+
// Act
13+
const { getByText } = TestUtils.renderWithRouter(
14+
<LinkCard label={label}>{expected}</LinkCard>
15+
);
16+
17+
//Assert
18+
expect(getByText(expected)).not.toBeNull();
19+
});
320
});

src/molecules/link-card/link-card.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const LinkCard: React.FC<LinkCardProps> = (props: LinkCardProps) => {
4545
const cssClassNamesFlat = cssClassNames.join(" ");
4646
const iconType = props.iconType ?? Icons.Lightbulb;
4747
const type = props.type ?? LinkCardTypes.Link;
48+
const to = props.to ?? "#";
4849

4950
const renderChildren = () => (
5051
<React.Fragment>
@@ -78,7 +79,7 @@ const LinkCard: React.FC<LinkCardProps> = (props: LinkCardProps) => {
7879
)}
7980
{// if
8081
type === LinkCardTypes.Link && (
81-
<Anchor cssClassName={cssClassNamesFlat} to={props.to}>
82+
<Anchor cssClassName={cssClassNamesFlat} to={to}>
8283
{renderChildren()}
8384
</Anchor>
8485
)}

src/tests/test-utils.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { MemoryRouter } from "react-router-dom";
2+
import { render } from "@testing-library/react";
3+
4+
// -----------------------------------------------------------------------------------------
5+
// #region Functions
6+
// -----------------------------------------------------------------------------------------
7+
8+
/**
9+
* Returns a React component wrapped in a MemoryRouter. Used for Components that
10+
* must be rendered inside a Route Component.
11+
*
12+
* @param component
13+
* @returns {ReactComponent}
14+
*/
15+
16+
const _renderWithRouter = (ui, { route = "/" } = {}) => {
17+
window.history.pushState({}, "Test page", route);
18+
19+
return render(ui, { wrapper: MemoryRouter });
20+
};
21+
22+
// #endregion Functions
23+
24+
// -----------------------------------------------------------------------------------------
25+
// #region Exports
26+
// -----------------------------------------------------------------------------------------
27+
28+
export const TestUtils = {
29+
renderWithRouter: _renderWithRouter,
30+
};
31+
32+
// #endregion Exports

0 commit comments

Comments
 (0)