diff --git a/core/components/molecules/chat/Chat.tsx b/core/components/molecules/chat/Chat.tsx index ef85a5f6b..413a796d2 100644 --- a/core/components/molecules/chat/Chat.tsx +++ b/core/components/molecules/chat/Chat.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import DateSeparator from './dateSeparator'; +import UnreadMessage from './unreadMessage'; import { BaseProps } from '@/utils/types'; export interface ChatProps extends BaseProps { @@ -19,5 +20,6 @@ export const Chat = (props: ChatProps) => { }; Chat.DateSeparator = DateSeparator; +Chat.UnreadMessage = UnreadMessage; export default Chat; diff --git a/core/components/molecules/chat/unreadMessage/UnreadMessage.tsx b/core/components/molecules/chat/unreadMessage/UnreadMessage.tsx new file mode 100644 index 000000000..8ca8bb0ce --- /dev/null +++ b/core/components/molecules/chat/unreadMessage/UnreadMessage.tsx @@ -0,0 +1,31 @@ +import * as React from 'react'; +import { Icon, Text } from '@/index'; +import styles from '@css/components/chatSeparator.module.css'; +import { BaseProps } from '@/utils/types'; +import classNames from 'classnames'; + +export interface UnreadMessageProps extends BaseProps { + /** + * Text to be rendered inside `UnreadMessage` + */ + text: string; +} + +const UnreadMessage: React.FC = (props) => { + const { text, className, ...rest } = props; + + const wrapperClass = classNames('d-flex align-items-center justify-content-center my-4', className); + + return ( +
+ + + + {text} + + +
+ ); +}; + +export default UnreadMessage; diff --git a/core/components/molecules/chat/unreadMessage/__stories__/all.story.jsx b/core/components/molecules/chat/unreadMessage/__stories__/all.story.jsx new file mode 100644 index 000000000..ed8070889 --- /dev/null +++ b/core/components/molecules/chat/unreadMessage/__stories__/all.story.jsx @@ -0,0 +1,36 @@ +import * as React from 'react'; +import { Chat } from '@/index'; + +export const unreadMessage = () => { + return ( + + + + ); +}; + +const customCode = `() => { + return ( + + + + ) +}`; + +export default { + title: 'Components/Chat/Separator/Unread Message', + component: Chat, + subcomponents: { + 'Chat.DateSeparator': Chat.DateSeparator, + 'Chat.NewMessage': Chat.NewMessage, + 'Chat.UnreadMessage': Chat.UnreadMessage, + }, + parameters: { + docs: { + docPage: { + title: 'Chat', + customCode, + }, + }, + }, +}; diff --git a/core/components/molecules/chat/unreadMessage/__tests__/UnreadMessage.test.tsx b/core/components/molecules/chat/unreadMessage/__tests__/UnreadMessage.test.tsx new file mode 100644 index 000000000..ed76b8201 --- /dev/null +++ b/core/components/molecules/chat/unreadMessage/__tests__/UnreadMessage.test.tsx @@ -0,0 +1,61 @@ +import * as React from 'react'; +import { render } from '@testing-library/react'; +import { testHelper, filterUndefined, valueHelper, testMessageHelper } from '@/utils/testHelper'; +import { Chat } from '@/index'; +import { ChatProps as Props } from '@/index.type'; + +const text = '2 Unread Messages'; + +const mapper = { + text: valueHelper(text, { required: true, iterate: false }), +}; + +describe('Chat Unread Message component snapshot', () => { + const testFunc = (props: Record): void => { + const attr = filterUndefined(props) as Props; + + it(testMessageHelper(attr), () => { + const { baseElement } = render( + + + + ); + expect(baseElement).toMatchSnapshot(); + }); + }; + + testHelper(mapper, testFunc); +}); + +describe('Chat Unread Message component', () => { + it('renders children', () => { + const { getByTestId } = render( + + + + ); + expect(getByTestId('DesignSystem-Chat-UnreadMessage')).toBeInTheDocument(); + expect(getByTestId('DesignSystem-Chat-UnreadMessage').textContent).toMatch(text); + }); + + it('overwrite Chat Unread Message class', () => { + const { getByTestId } = render( + + + + ); + expect(getByTestId('DesignSystem-Chat-UnreadMessage')).toHaveClass('custom-class'); + }); + + it('Chat Unread Message Component with overwrite data-test attribute', () => { + const testDataValue = 'DesignSystem-UnreadMessage-TestValue'; + const { getByTestId } = render( + + + + ); + + const dateElement = getByTestId(testDataValue); + expect(dateElement.getAttribute('data-test')).toBe(testDataValue); + }); +}); diff --git a/core/components/molecules/chat/unreadMessage/__tests__/__snapshots__/UnreadMessage.test.tsx.snap b/core/components/molecules/chat/unreadMessage/__tests__/__snapshots__/UnreadMessage.test.tsx.snap new file mode 100644 index 000000000..5e23d9d1c --- /dev/null +++ b/core/components/molecules/chat/unreadMessage/__tests__/__snapshots__/UnreadMessage.test.tsx.snap @@ -0,0 +1,39 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Chat Unread Message component snapshot + text: "2 Unread Messages" + 1`] = ` + +
+
+
+ + + arrow_Downward + + + 2 Unread Messages + + +
+
+
+ +`; diff --git a/core/components/molecules/chat/unreadMessage/index.tsx b/core/components/molecules/chat/unreadMessage/index.tsx new file mode 100644 index 000000000..c4f26abf8 --- /dev/null +++ b/core/components/molecules/chat/unreadMessage/index.tsx @@ -0,0 +1,2 @@ +export { default } from './UnreadMessage'; +export * from './UnreadMessage'; diff --git a/css/src/components/chatSeparator.module.css b/css/src/components/chatSeparator.module.css new file mode 100644 index 000000000..a01fb22a2 --- /dev/null +++ b/css/src/components/chatSeparator.module.css @@ -0,0 +1,9 @@ +.Chat-UnreadMessage { + border-radius: var(--spacing-2); + padding: var(--spacing-s) var(--spacing-l) var(--spacing-s) var(--spacing); + display: flex; + align-items: center; + justify-content: center; + background-color: var(--primary); + cursor: pointer; +}