File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import React from "react" ;
2+ import faker from "faker" ;
3+ import { LinkCard } from "./link-card" ;
4+ import { TestUtils } from "../../tests/test-utils" ;
5+
16describe ( "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} ) ;
Original file line number Diff line number Diff 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 ) }
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments