fix unit tests. add conversation model and add unit tests to it.
This commit is contained in:
32
app/lib/__test__/conversation.test.tsx
Normal file
32
app/lib/__test__/conversation.test.tsx
Normal file
@ -0,0 +1,32 @@
|
||||
// conversation.test.ts
|
||||
|
||||
import { Translator } from '@/app/i18n/api';
|
||||
import { Conversation, Message, Speaker } from '@/app/lib/conversation';
|
||||
import { describe, beforeEach, it, expect, test } from '@jest/globals';
|
||||
|
||||
describe('Conversation', () => {
|
||||
let conversation: Conversation;
|
||||
|
||||
beforeEach(() => {
|
||||
const translator = new Translator("en", "sp");
|
||||
const s1: Speaker = { language: "en", id: "s1" };
|
||||
const s2: Speaker = { id: "s2", language: "sp" }
|
||||
conversation = new Conversation(translator, s1, s2);
|
||||
});
|
||||
|
||||
it('should add a message to the conversation', () => {
|
||||
conversation.addMessage({ id: "s1", language: "en" }, "Hello");
|
||||
expect(true).toEqual(false);
|
||||
expect(conversation.length).toBe(1);
|
||||
expect(conversation[0].speaker.id).toEqual("s1");
|
||||
expect(conversation[0].text).toEqual("hello");
|
||||
});
|
||||
|
||||
it('should translate the last message in the conversation', async () => {
|
||||
|
||||
conversation.addMessage({ id: "s1", language: "en" }, "Hello");
|
||||
|
||||
await conversation.translateLast();
|
||||
expect(conversation[conversation.length - 1].translation).toEqual("Hollla");
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user