From 9af621367422c082dca5331a33b3efa4ed231cfd Mon Sep 17 00:00:00 2001 From: 3LL4N Date: Tue, 5 Dec 2023 16:49:58 +0800 Subject: [PATCH] added: intial tests for random question function handlers --- .../components/tests/ImagePickers.test.tsx | 15 ----- .../tests/randomQuestionHandlers.test.ts | 58 +++++++++++++++++++ 2 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 packages/api/src/functions/tests/randomQuestionHandlers.test.ts diff --git a/apps/expo/src/components/tests/ImagePickers.test.tsx b/apps/expo/src/components/tests/ImagePickers.test.tsx index 8ff40646..4351696c 100644 --- a/apps/expo/src/components/tests/ImagePickers.test.tsx +++ b/apps/expo/src/components/tests/ImagePickers.test.tsx @@ -21,19 +21,4 @@ describe("TestImagePicker Component", () => { const renderedImage = getByTestId("test-image-picker-image"); expect(renderedImage.props.source.uri).toBe(testImage); }); - - it("renders the placeholder when no image is provided", () => { - const { getByText, getByTestId } = render(); - expect(getByText("Add Cover Image")).toBeTruthy(); - }); - - it("navigates to the correct screen when pressed", () => { - const { getByTestId } = render(); - const touchable = getByTestId("test-image-picker-touchable"); - fireEvent.press(touchable); - expect(mockNavigate).toHaveBeenCalledWith("AddCoverImage", { - query: "Sample Images", - type: "test", - }); - }); }); diff --git a/packages/api/src/functions/tests/randomQuestionHandlers.test.ts b/packages/api/src/functions/tests/randomQuestionHandlers.test.ts new file mode 100644 index 00000000..d530b50a --- /dev/null +++ b/packages/api/src/functions/tests/randomQuestionHandlers.test.ts @@ -0,0 +1,58 @@ +import { describe, it, expect } from "vitest"; +import { + questionFormatGenerators, + generateCombinedQuestionPrompts, + processGeneratedQuestions, +} from "../randomQuestionsHandlers"; + +import { generateChoicesPrompt, timeAndPointsPrompt } from "../gptHandlers"; + +describe("questionFormatGenerators", () => { + it("It should generate format for multiple choice question/s", () => { + const mcqFormat = questionFormatGenerators["multipleChoice"]; + const output = `separator\nQuestion: [Your question here, max 100 characters] + ${generateChoicesPrompt( + 4, + )}\nCorrect Answer: Option [Correct option number] ${timeAndPointsPrompt}`; + + expect(mcqFormat()).toEqual(output); + }); + + it("It should generate format for multiselect question/s", () => { + const multiselectFormat = questionFormatGenerators["multiselect"]; + + const output = `separator\nQuestion: [Your question here, max 100 characters] + ${generateChoicesPrompt( + 4, + )}\nAll Correct Answers: Options [Correct option numbers separated by commas, e.g., 1,3] ${timeAndPointsPrompt}`; + + expect(multiselectFormat()).toEqual(output); + }); + + it("It should generate format for identification question/s", () => { + const identicationFormat = questionFormatGenerators["identification"]; + + const output = `separator\nQuestion: [Your question here, max 100 characters]\nAnswer: [Your answer here, max 68 characters] ${timeAndPointsPrompt}`; + + expect(identicationFormat()).toEqual(output); + }); + + it("It should generate format for true or false question/s", () => { + const tofFormat = questionFormatGenerators["trueOrFalse"]; + + const output = `separator\nQuestion: [Your question here, max 100 characters]\nAnswer: [True/False] ${timeAndPointsPrompt}`; + + expect(tofFormat()).toEqual(output); + }); +}); + +describe("generateCombinedQuestionPrompts", () => { + it("should generate correct prompt for a single question", () => { + const combinedPrompts = generateCombinedQuestionPrompts( + 1, + "Sample message", + ); + expect(combinedPrompts).toContain("Sample message"); + expect(combinedPrompts).toContain("separator"); + }); +});