Skip to content

Commit

Permalink
added: intial tests for random question function handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
3LL4N committed Dec 5, 2023
1 parent 29eb529 commit 9af6213
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 15 deletions.
15 changes: 0 additions & 15 deletions apps/expo/src/components/tests/ImagePickers.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<TestImagePicker />);
expect(getByText("Add Cover Image")).toBeTruthy();
});

it("navigates to the correct screen when pressed", () => {
const { getByTestId } = render(<TestImagePicker />);
const touchable = getByTestId("test-image-picker-touchable");
fireEvent.press(touchable);
expect(mockNavigate).toHaveBeenCalledWith("AddCoverImage", {
query: "Sample Images",
type: "test",
});
});
});
58 changes: 58 additions & 0 deletions packages/api/src/functions/tests/randomQuestionHandlers.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});

0 comments on commit 9af6213

Please sign in to comment.