Skip to content

Commit 1f89c3d

Browse files
authored
Add welcome prompts to chatbot and related tests (#1719)
Introduced predefined welcome prompts to the AnsibleChatbot component, allowing users to quickly send common queries. Added tests to verify that all welcome prompts are rendered and that clicking a prompt sends the correct message. Update test to match new API call signature Adjusted the test for clicking a welcome prompt to expect the updated API call parameters, reflecting changes in the request payload structure. Refactor test to use getByRole for welcome prompt button Updated the test to select the welcome prompt button using getByRole with the button's accessible name instead of getByText. This improves test reliability and accessibility alignment.
1 parent 2cba3e2 commit 1f89c3d

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

ansible_ai_connect_chatbot/src/AnsibleChatbot/AnsibleChatbot.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,26 @@ export const AnsibleChatbot: React.FunctionComponent = () => {
129129
handleStopButton,
130130
isStreamingSupported,
131131
} = useChatbot();
132+
133+
const welcomePrompts = [
134+
{
135+
title: "Using Ansible Automation Platform",
136+
message: "I have a question about Ansible Automation Platform",
137+
},
138+
{
139+
title: "Containerized Installation",
140+
message: "I want to install AAP using the containerized installer",
141+
},
142+
{
143+
title: "RPM Installation",
144+
message: "I want to install AAP using the RPM installer",
145+
},
146+
].map((prompt) => ({
147+
title: prompt.title,
148+
message: prompt.message,
149+
onClick: () => handleSend(prompt.message),
150+
}));
151+
132152
const [chatbotVisible, setChatbotVisible] = useState<boolean>(true);
133153
const [displayMode, setDisplayMode] = useState<ChatbotDisplayMode>(
134154
ChatbotDisplayMode.fullscreen,
@@ -330,6 +350,7 @@ export const AnsibleChatbot: React.FunctionComponent = () => {
330350
<ChatbotWelcomePrompt
331351
title="Hello, Ansible User"
332352
description="How may I help you today?"
353+
prompts={welcomePrompts}
333354
/>
334355
{alertMessage && (
335356
<ChatbotAlert

ansible_ai_connect_chatbot/src/App.test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,3 +892,35 @@ test("Test reset conversation state once unmounting the component.", async () =>
892892
view.unmount();
893893
assert(conversationStore.size === 0);
894894
});
895+
896+
test("Clicking a welcome prompt sends the correct message", async () => {
897+
const spy = mockAxios(200);
898+
const view = await renderApp();
899+
900+
const promptButton = view.getByRole("button", {
901+
name: "Using Ansible Automation Platform",
902+
});
903+
expect(promptButton).toBeVisible();
904+
905+
await userEvent.click(promptButton);
906+
907+
expect(spy).toHaveBeenCalledWith(
908+
expect.anything(),
909+
expect.objectContaining({
910+
conversation_id: undefined,
911+
query: "I have a question about Ansible Automation Platform",
912+
}),
913+
expect.anything(),
914+
);
915+
});
916+
917+
test("All welcome prompts are rendered", async () => {
918+
const view = await renderApp();
919+
await expect
920+
.element(view.getByText("Using Ansible Automation Platform"))
921+
.toBeVisible();
922+
await expect
923+
.element(view.getByText("Containerized Installation"))
924+
.toBeVisible();
925+
await expect(view.getByText("RPM Installation")).toBeVisible();
926+
});

0 commit comments

Comments
 (0)