2022-03-23 23:19:12 +08:00
|
|
|
import { test, describe, assert, afterEach } from "vitest";
|
|
|
|
import { cleanup, render, get_text } from "@gradio/tootils";
|
|
|
|
|
|
|
|
import Chatbot from "./Chatbot.svelte";
|
2022-07-22 02:12:46 +08:00
|
|
|
import type { LoadingStatus } from "../StatusTracker/types";
|
|
|
|
|
|
|
|
const loading_status = {
|
|
|
|
eta: 0,
|
|
|
|
queue_position: 1,
|
|
|
|
status: "complete" as LoadingStatus["status"],
|
|
|
|
scroll_to_output: false,
|
|
|
|
visible: true,
|
|
|
|
fn_index: 0
|
|
|
|
};
|
2022-03-23 23:19:12 +08:00
|
|
|
|
|
|
|
describe("Chatbot", () => {
|
|
|
|
afterEach(() => cleanup());
|
|
|
|
|
2022-05-02 16:41:20 +08:00
|
|
|
test("renders user and bot messages", () => {
|
2022-03-23 23:19:12 +08:00
|
|
|
const { getAllByTestId } = render(Chatbot, {
|
2022-07-22 02:12:46 +08:00
|
|
|
loading_status,
|
|
|
|
label: "hello",
|
2022-05-02 16:41:20 +08:00
|
|
|
value: [["user message one", "bot message one"]]
|
2022-03-23 23:19:12 +08:00
|
|
|
});
|
|
|
|
|
2022-05-02 16:41:20 +08:00
|
|
|
const bot = getAllByTestId("user")[0];
|
|
|
|
const user = getAllByTestId("bot")[0];
|
2022-03-23 23:19:12 +08:00
|
|
|
|
2022-05-02 16:41:20 +08:00
|
|
|
assert.equal(get_text(bot), "user message one");
|
|
|
|
assert.equal(get_text(user), "bot message one");
|
2022-03-23 23:19:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("renders additional message as they are passed", async () => {
|
|
|
|
const { component, getAllByTestId } = render(Chatbot, {
|
2022-07-22 02:12:46 +08:00
|
|
|
loading_status,
|
|
|
|
label: "hello",
|
2022-05-02 16:41:20 +08:00
|
|
|
value: [["user message one", "bot message one"]]
|
2022-03-23 23:19:12 +08:00
|
|
|
});
|
|
|
|
|
2022-05-02 16:41:20 +08:00
|
|
|
const bot = getAllByTestId("user");
|
|
|
|
const user = getAllByTestId("bot");
|
2022-03-23 23:19:12 +08:00
|
|
|
|
|
|
|
assert.equal(user.length, 1);
|
2022-05-02 16:41:20 +08:00
|
|
|
assert.equal(bot.length, 1);
|
2022-03-23 23:19:12 +08:00
|
|
|
|
|
|
|
await component.$set({
|
|
|
|
value: [
|
2022-05-02 16:41:20 +08:00
|
|
|
["user message one", "bot message one"],
|
|
|
|
["user message two", "bot message two"]
|
2022-03-23 23:19:12 +08:00
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
const user_2 = getAllByTestId("user");
|
2022-05-02 16:41:20 +08:00
|
|
|
const bot_2 = getAllByTestId("bot");
|
2022-03-23 23:19:12 +08:00
|
|
|
|
|
|
|
assert.equal(user_2.length, 2);
|
2022-05-02 16:41:20 +08:00
|
|
|
assert.equal(bot_2.length, 2);
|
2022-03-23 23:19:12 +08:00
|
|
|
|
|
|
|
assert.equal(get_text(user_2[1]), "user message two");
|
2022-05-02 16:41:20 +08:00
|
|
|
assert.equal(get_text(bot_2[1]), "bot message two");
|
2022-03-23 23:19:12 +08:00
|
|
|
});
|
|
|
|
});
|