Chat bubble 컴포넌트
Chat bubble(채팅 말풍선)는 채팅 메시지를 시각적으로 표현하는 컴포넌트입니다. 사용자가 보낸 메시지(outgoing)와 상대방이나 생성형 AI로부터 받은 메시지(incoming)를 구분해 표시하며, 아바타, 콘텐츠, 인라인 동작, 로딩 상태 등을 지원합니다. 이 페이지에서는 Chat bubble 컴포넌트의 테스트 유틸리티, 일반 지침, 작성 지침, 접근성 지침을 소개합니다.
출처: 문서
본문
단위 테스트 예제
Chat bubble 선택하기
import { render } from '@testing-library/react';
import createWrapper from '@cloudscape-design/components/test-utils/dom';
import ChatBubble from '@cloudscape-design/components/chat-bubble';
describe('<ChatBubble />', () => {
it('renders the chat-bubble component', () => {
const { container } = render(<ChatBubble />);
const wrapper = createWrapper(container);
expect(wrapper.findChatBubble()).toBeTruthy();
});
it('selects all chat-bubble components', () => {
const { container } = render(<>
<ChatBubble />
<ChatBubble />
<ChatBubble />
</>);
const wrapper = createWrapper(container);
const components = wrapper.findAllChatBubbles();
expect(components).toHaveLength(3)
});
});
콘텐츠 슬롯에서 코드 뷰 선택하기
// side-effect imports to install the finder methods
import Avatar from '@cloudscape-design/chat-components/avatar';
import ChatBubble from '@cloudscape-design/chat-components/chat-bubble';
import CodeView from '@cloudscape-design/code-view/code-view';
// use import from the main package to use the wrapper
import createWrapper from '@cloudscape-design/components/test-utils/dom';
import '@cloudscape-design/chat-components/test-utils/dom';
import '@cloudscape-design/code-view/test-utils/dom';
import { render } from '@testing-library/react';
import React from 'react';
function Component() {
return (
<ChatBubble
type="incoming"
avatar={<Avatar ariaLabel="Generative AI assistant" iconName="gen-ai" color="gen-ai" />}
ariaLabel="Generative AI assistant at 03:45:16"
>
<CodeView content='const hello: string = "world";' />
</ChatBubble>
);
}
describe('<ChatBubble />', () => {
it('get content', () => {
const { container } = render(<Component />);
const wrapper = createWrapper(container).findChatBubble()!;
const content = wrapper.findContentSlot()!.findCodeView()!.findContent().getElement();
expect(content.textContent).toBe('const hello: string = "world";');
});
});
아바타 슬롯에서 아바타 선택하기
import Avatar from '@cloudscape-design/chat-components/avatar';
import ChatBubble from '@cloudscape-design/chat-components/chat-bubble';
import createWrapper from '@cloudscape-design/chat-components/test-utils/dom';
import { render } from '@testing-library/react';
import React from 'react';
function Component() {
return (
<ChatBubble
type="incoming"
avatar={
<Avatar
ariaLabel="Generative AI assistant"
tooltipText="Generative AI assistant"
iconName="gen-ai"
color="gen-ai"
/>
}
ariaLabel="Generative AI assistant at 03:45:16"
>
Amazon S3 is built using AWS's highly available and reliable infrastructure.
</ChatBubble>
);
}
describe('<ChatBubble />', () => {
it('get avatar inside avatar slot', () => {
const { container } = render(<Component />);
const wrapper = createWrapper(container).findChatBubble()!;
const avatar = wrapper.findAvatarSlot()!.findAvatar()!;
avatar.focus();
expect(avatar.findTooltip()?.getElement().textContent).toBe('Generative AI assistant');
});
});
actions 슬롯에서 버튼 그룹 선택하기
// side-effect import to install the finder methods
import Avatar from '@cloudscape-design/chat-components/avatar';
import ChatBubble from '@cloudscape-design/chat-components/chat-bubble';
import ButtonGroup from '@cloudscape-design/components/button-group';
// use import from the main package to use the wrapper
import createWrapper from '@cloudscape-design/components/test-utils/dom';
import '@cloudscape-design/chat-components/test-utils/dom';
import { render } from '@testing-library/react';
import React from 'react';
function Component() {
return (
<ChatBubble
type="incoming"
avatar={<Avatar ariaLabel="Generative AI assistant" iconName="gen-ai" color="gen-ai" />}
ariaLabel="Generative AI assistant at 03:45:16"
actions={
<ButtonGroup
ariaLabel="Chat bubble actions"
variant="icon"
items={[
{
type: 'icon-button',
id: 'copy',
iconName: 'copy',
text: 'Copy',
popoverFeedback: 'Message copied',
},
]}
/>
}
>
Amazon S3 is built using AWS's highly available and reliable infrastructure.
</ChatBubble>
);
}
describe('<ChatBubble />', () => {
it('get button group inside actions slot', () => {
const { container } = render(<Component />);
const wrapper = createWrapper(container).findChatBubble()!;
const buttonGroup = wrapper.findActionsSlot()!.findButtonGroup()!;
expect(buttonGroup.findItems()).toHaveLength(1);
});
});
단위 테스트 API
ChatBubbleWrapper
| 이름 | 반환 타입 | 설명 | 매개변수 |
|---|---|---|---|
| findActionsSlot | ElementWrapper | null | - | - |
| findAvatarSlot | ElementWrapper | null | - | - |
| findContentSlot | ElementWrapper | null | - | - |
| findLoadingBar | LoadingBarWrapper | null | - | - |
통합 테스트 예제
콘텐츠 슬롯에서 코드 뷰 선택하기
// side-effect import to install the finder methods of code view
import createWrapper from '@cloudscape-design/chat-components/test-utils/selectors';
import '@cloudscape-design/code-view/test-utils/selectors';
/**
* browser - is a global object representing your testing framework.
* The exact API could be different for your stack.
*/
describe('Chat bubble', () => {
it('get content', async () => {
// this code tests a component instance similar to the TestPage
await browser.url('your-page-to-test');
const wrapper = createWrapper().findChatBubble();
const content = await browser.$(wrapper.findContentSlot().findCodeView().findContent().toSelector()).getText();
expect(content).toEqual('const hello: string = "world";');
});
});
/**
* TestPage.tsx
*
* function Component() {
* return (
* <ChatBubble
* type="incoming"
* avatar={<Avatar ariaLabel="Generative AI assistant" iconName="gen-ai" color="gen-ai" />}
* ariaLabel="Generative AI assistant at 03:45:16"
* >
* <CodeView content='const hello: string = "world";' />
* </ChatBubble>
* );
* }
*/
아바타 슬롯에서 아바타 선택하기
import createWrapper from '@cloudscape-design/chat-components/test-utils/selectors';
/**
* browser - is a global object representing your testing framework.
* The exact API could be different for your stack.
*/
describe('Chat bubble', () => {
it('get avatar inside avatar slot', async () => {
// this code tests a component instance similar to this /components/chat-bubble&example=incoming-message
await browser.url('your-page-to-test');
const wrapper = createWrapper().findChatBubble();
const avatarSelector = await browser.$(wrapper.findAvatarSlot()!.findAvatar().toSelector());
await avatarSelector.moveTo();
const tooltipSelector = await browser.$(wrapper.findAvatarSlot()!.findAvatar().findTooltip().toSelector());
expect(tooltipSelector.getText()).toBe('Generative AI assistant');
});
});
actions 슬롯에서 버튼 그룹 선택하기
import createWrapper from '@cloudscape-design/chat-components/test-utils/selectors';
/**
* browser - is a global object representing your testing framework.
* The exact API could be different for your stack.
*/
describe('Chat bubble', () => {
it('get button group inside actions slot', async () => {
// this code tests a component instance similar to this /components/chat-bubble&example=incoming-message
await browser.url('your-page-to-test');
const wrapper = createWrapper().findChatBubble();
const buttonGroupItemsSelector = await browser.$$(
wrapper.findActionsSlot()!.findButtonGroup().findItems().toSelector()
);
expect(buttonGroupItemsSelector.length).toBe(3);
});
});
통합 테스트 API
ChatBubbleWrapper
| 이름 | 반환 타입 | 설명 | 매개변수 |
|---|---|---|---|
| findActionsSlot | ElementWrapper | - | - |
| findAvatarSlot | ElementWrapper | null | - | - |
| findContentSlot | ElementWrapper | - | - |
| findLoadingBar | LoadingBarWrapper | - | - |
일반 지침
Do
- 대화에서 작성자를 시각적으로 나타내려면 아바타를 사용하세요. 이는 대화 안의 콘텐츠를 구분하고 가독성을 높이는 데 도움이 됩니다.
- 채팅 말풍선에 인라인 동작을 보여줘야 한다면 버튼 그룹을 사용하세요.
- 생성형 AI 채팅을 만들 때는 생성형 AI 채팅 지침을 따르세요.
Don't
기능
유형
-
발신 메시지(Outgoing message)
사용자가 보낸 채팅 메시지입니다. -
수신 메시지(Incoming message)
다른 사람에게서 받은 채팅 메시지입니다.
구조
-
아바타
작성자의 정체성을 보여주려면 아바타를 사용하세요. 아바타 지침을 따르세요.
-
콘텐츠
채팅 메시지 콘텐츠가 표시되는 영역입니다. 일반적인 콘텐츠 유형은 다음과 같습니다:
- 텍스트: 일반 텍스트나 형식이 지정된 텍스트로 된 간단한 메시지.
- 미디어: 이미지, 그래픽, 임베드되거나 링크된 비디오.
- 펼칠 수 있는 섹션: 접을 수 있는 섹션. 예를 들어 추가 옵션이나 출처·인용을 표시할 때 사용합니다.
- 링크: 사용자를 사이트나 페이지로 안내하는 하이퍼링크.
- 기타: 항목 목록, 코드 블록 같은 복잡한 UI 요소.
-
동작 - 선택 사항
버튼 그룹을 사용해 사용자가 채팅 말풍선 안에서 수행할 수 있는 인라인 동작을 표시하세요.
상태
-
로딩 상태
수신 메시지가 로딩 중임을 나타냅니다.
생성형 AI의 수신 응답 로딩 상태를 표시하려면:
- 생성형 AI가 처리 단계에 있을 때는 로딩 텍스트와 함께 로딩 아바타를 채팅 말풍선에 표시하세요.
- 생성형 AI 응답에 항목 목록 같은 다른 UI 요소가 포함될 때는 로딩 아바타와 함께 로딩 텍스트가 있는 로딩 바를 표시하세요. 생성형 AI 로딩 상태 지침을 따르세요.
작성 지침
일반 작성 지침
-
문장형 대소문자(sentence case)를 사용하되, 고유명사와 브랜드 이름은 맥락에 맞게 대문자로 표기하세요.
-
현재 시제 동사와 능동태를 사용하세요.
-
작성할 때 please, thank you, 줄임표( ... ), 앰퍼샌드( & ), e.g., i.e., *etc.*를 사용하지 마세요.
-
방향을 가리키는 표현은 피하세요.
- 예: above(위) 대신 previous(이전), below(아래) 대신 following(다음)을 사용하세요.
-
기기와 무관한 언어를 사용하세요.
- 예: click 대신 choose 또는 select를 사용하세요.
컴포넌트별 지침
인라인 동작
- 버튼 그룹에 대한 작성 지침을 따르세요.
아바타
- 아바타에 대한 작성 지침을 따르세요.
접근성 지침
일반 접근성 지침
- 각 컴포넌트에 대한 대체 텍스트와 ARIA(Accessible Rich Internet Applications) 영역 지침을 따르세요.
- 애플리케이션의 언어 맥락에 맞게 ARIA 라벨을 정의하세요.
- 역할과 랜드마크에 불필요한 마크업을 추가하지 마세요. 각 컴포넌트에 대한 지침을 따르세요.
- 모든 콘텐츠에 논리적이고 예측 가능한 순서로 키보드 기능을 제공하세요. 정보의 흐름이 자연스러워야 합니다.
컴포넌트별 지침
- 스크린 리더 사용자가 각 메시지를 구분할 수 있도록 각 채팅 말풍선에 고유한
ariaLabel를 제공하세요. 예를 들어 타임스탬프를 사용하세요: Jane Doe at 2:30:25 pm.