Skip to content

Commit 7b3ec12

Browse files
authored
Merge pull request #399 from user-interviews/feature/UIDS-398-toast-object-messages
feature(UIDS-398): Allow Toast component to accept messages with a title prop
2 parents 5939e2c + 01375e9 commit 7b3ec12

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/Toast/Toast.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default function Toast(props) {
2424
autoDismiss={props.autoDismiss}
2525
id={message.id}
2626
message={message.message}
27+
title={message.title}
2728
type={message.type}
2829
onDismiss={props.onToastClosed}
2930
/>
@@ -41,6 +42,7 @@ Toast.propTypes = {
4142
PropTypes.shape({
4243
id: PropTypes.string,
4344
message: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
45+
title: PropTypes.string,
4446
type: PropTypes.string,
4547
}),
4648
).isRequired,

src/Toast/Toast.test.jsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { create } from 'react-test-renderer';
33

44
import { Toast } from 'src/Toast';
5+
import { Alert } from 'src/Alert';
56

67
describe('Toast', () => {
78
test('no header classes', () => {
@@ -17,4 +18,34 @@ describe('Toast', () => {
1718
expect(props.className).toContain('Toast');
1819
expect(props.className).toContain('Toast--no-header');
1920
});
21+
22+
describe('when building alert props', () => {
23+
const setup = (props) => create(
24+
<Toast
25+
messages={[
26+
{ id: '1', type: 'success', ...props },
27+
]}
28+
/>,
29+
);
30+
31+
test('builds props from string message', () => {
32+
const { root } = setup({ message: 'hello' });
33+
34+
expect(root.findByType(Alert).props.message).toBe('hello');
35+
});
36+
37+
test('builds props from node message', () => {
38+
const { root } = setup({ message: <div>hello</div> });
39+
40+
expect(root.findByType(Alert).props.message).toEqual(<div>hello</div>);
41+
});
42+
43+
describe('when title prop is passed', () => {
44+
test('builds title prop', () => {
45+
const { root } = setup({ title: 'woohoo', message: 'you did it!' });
46+
47+
expect(root.findByType(Alert).props.title).toBe('woohoo');
48+
});
49+
});
50+
});
2051
});

0 commit comments

Comments
 (0)