Skip to content

Commit

Permalink
Supporting an action link
Browse files Browse the repository at this point in the history
  • Loading branch information
Golodhros committed Aug 28, 2020
1 parent 1a7b073 commit 65744b8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ describe('Alert', () => {
expect(actual).toEqual(expected);
});
});

describe('when passing an action text and action href', () => {
it('should render the action link', () => {
const { wrapper } = setup({
actionHref: 'http://testSite.com',
actionText: 'Action Text',
});
const expected = 1;
const actual = wrapper.find('.action-link').length;

expect(actual).toEqual(expected);
});

it('should render the action text', () => {
const { props, wrapper } = setup({
actionHref: 'http://testSite.com',
actionText: 'Action Text',
});
const expected = props.actionText;
const actual = wrapper.find('.action-link').text();

expect(actual).toEqual(expected);
});
});
});

describe('lifetime', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import './styles.scss';
export interface AlertProps {
message: string | React.ReactNode;
actionText?: string;
actionHref?: string;
onAction?: (event: React.MouseEvent<HTMLButtonElement>) => void;
}

const Alert: React.FC<AlertProps> = ({
message,
onAction,
actionText,
actionHref,
}: AlertProps) => {
return (
<div className="alert">
Expand All @@ -27,6 +29,11 @@ const Alert: React.FC<AlertProps> = ({
{actionText}
</button>
)}
{actionText && actionHref && (
<a className="action-link" href={actionHref}>
{actionText}
</a>
)}
</div>
);
};
Expand Down

0 comments on commit 65744b8

Please sign in to comment.