more tests (#4745)

Co-authored-by: pngwn <hello@pngwn.io>
This commit is contained in:
Dawood Khan 2023-07-04 10:41:50 -04:00 committed by GitHub
parent cb96d657b4
commit 156bb26280
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 103 additions and 9 deletions

View File

@ -1,5 +1,5 @@
import { test, describe, assert, afterEach } from "vitest";
import { cleanup, render, get_text } from "@gradio/tootils";
import { cleanup, render } from "@gradio/tootils";
import Chatbot from "./Chatbot.svelte";
import type { LoadingStatus } from "../StatusTracker/types";
@ -14,13 +14,13 @@ const loading_status: LoadingStatus = {
show_progress: "full"
};
describe.skip("Chatbot", () => {
describe("Chatbot", () => {
afterEach(() => cleanup());
test("renders user and bot messages", async () => {
const { getAllByTestId } = await render(Chatbot, {
loading_status,
label: "hello",
label: "chatbot",
value: [["user message one", "bot message one"]],
root: "",
root_url: "",
@ -31,14 +31,14 @@ describe.skip("Chatbot", () => {
const bot = getAllByTestId("user")[0];
const user = getAllByTestId("bot")[0];
assert.equal(get_text(bot), "user message one");
assert.equal(get_text(user), "bot message one");
assert.exists(bot);
assert.exists(user);
});
test("renders additional message as they are passed", async () => {
const { component, getAllByTestId } = await render(Chatbot, {
loading_status,
label: "hello",
label: "chatbot",
value: [["user message one", "bot message one"]],
root: "",
root_url: "",
@ -59,7 +59,95 @@ describe.skip("Chatbot", () => {
assert.equal(user_2.length, 2);
assert.equal(bot_2.length, 2);
assert.equal(get_text(user_2[1]), "user message two");
assert.equal(get_text(bot_2[1]), "bot message two");
assert.exists(user_2[1]);
assert.exists(bot_2[1]);
});
test("renders image bot and user messages", async () => {
const { component, getAllByTestId } = await render(Chatbot, {
loading_status,
label: "chatbot",
value: null,
root: "",
root_url: "",
latex_delimiters: null,
theme_mode: "dark"
});
let value = Array(2).fill([
{
"name": "https://gradio-builds.s3.amazonaws.com/demo-files/cheetah1.jpg",
"mime_type": "image/jpeg",
"alt_text": null,
"data": null,
"is_file": true
}
])
await component.$set({
value: value
});
const image = getAllByTestId("chatbot-image");
assert.isTrue(image[0].src.includes("cheetah1.jpg"));
assert.isTrue(image[1].src.includes("cheetah1.jpg"));
});
test("renders video bot and user messages", async () => {
const { component, getAllByTestId } = await render(Chatbot, {
loading_status,
label: "chatbot",
value: null,
root: "",
root_url: "",
latex_delimiters: null,
theme_mode: "dark"
});
let value = Array(2).fill([
{
"name": "https://gradio-builds.s3.amazonaws.com/demo-files/video_sample.mp4",
"mime_type": "video/mp4",
"alt_text": null,
"data": null,
"is_file": true
}
])
await component.$set({
value: value
});
const video = getAllByTestId("chatbot-video");
assert.isTrue(video[0].src.includes("video_sample.mp4"));
assert.isTrue(video[1].src.includes("video_sample.mp4"));
});
test("renders audio bot and user messages", async () => {
const { component, getAllByTestId } = await render(Chatbot, {
loading_status,
label: "chatbot",
value: null,
root: "",
root_url: "",
latex_delimiters: null,
theme_mode: "dark"
});
let value = Array(2).fill([
{
"name": "https://gradio-builds.s3.amazonaws.com/demo-files/audio_sample.wav",
"mime_type": "audio/wav",
"alt_text": null,
"data": null,
"is_file": true
}
])
await component.$set({
value: value
});
const audio = getAllByTestId("chatbot-audio");
assert.isTrue(audio[0].src.includes("audio_sample.wav"));
assert.isTrue(audio[1].src.includes("audio_sample.wav"));
});
});

View File

@ -107,6 +107,7 @@
{/if}
{:else if message !== null && message.mime_type?.includes("audio")}
<audio
data-testid="chatbot-audio"
controls
preload="metadata"
src={message.data}
@ -117,6 +118,7 @@
/>
{:else if message !== null && message.mime_type?.includes("video")}
<video
data-testid="chatbot-video"
controls
src={message.data}
title={message.alt_text}
@ -128,7 +130,11 @@
<track kind="captions" />
</video>
{:else if message !== null && message.mime_type?.includes("image")}
<img src={message.data} alt={message.alt_text} />
<img
data-testid="chatbot-image"
src={message.data}
alt={message.alt_text}
/>
{/if}
</div>
{/each}