Skip to content

Commit

Permalink
fix: disable test case running for database questions
Browse files Browse the repository at this point in the history
  • Loading branch information
HollaG committed Nov 13, 2024
1 parent 3ce85bb commit 4cd0bef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
43 changes: 33 additions & 10 deletions peer-prep/src/components/TestCases/TestCasesWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Space,
Text,
Title,
Tooltip,
useMantineColorScheme,
} from "@mantine/core";
import classes from "./TestCasesWrapper.module.css";
Expand Down Expand Up @@ -43,9 +44,7 @@ import ReactMarkdown from "react-markdown";
import { useAi } from "../../hooks/useAi";

type TestCasesWrapperProps = {
testCases: TestCase[]; // array of test cases
channelId: string | null;
questionId: string | null;

// to decide if we want to pass down a function from parent instead of passing down solutioncode
// runAllTestCases: () => void;
Expand All @@ -57,19 +56,21 @@ type TestCasesWrapperProps = {
latestResultsRef: React.MutableRefObject<TestCaseResult[]>;

roomId: string;
question: string;

question: Question;
};

const STATUS_PARTIAL = 206;
const STATUS_COMPLETE = 200;
const STATUS_CONNECTED = 201;
const STATUS_STARTED = 202;

const BLOCKED_CATEGORY_IDS = [2];

export default function TestCasesWrapper({
testCases,
channelId,
// runAllTestCases,
questionId,

currentValueRef,

userId,
Expand All @@ -78,8 +79,17 @@ export default function TestCasesWrapper({
latestResultsRef,

roomId,

question,
}: TestCasesWrapperProps) {
const questionString = question.description.descriptionText;
const questionId = question._id;
const testCases = question.testCases;

const isBlockedFromRunningTestCase = question.categoriesId.some((id) =>
BLOCKED_CATEGORY_IDS.includes(id)
);

const [latestResults, setLatestResults] = useState<TestCaseResult[]>([]);

const [currentTestCase, setCurrentTestCase] = useState<TestCase | null>(
Expand Down Expand Up @@ -325,10 +335,23 @@ export default function TestCasesWrapper({
>
Test Cases ({testCases.length})
</Title>
<Button variant="light" onClick={runTestCases} loading={isRunning}>
{" "}
Run all testcases{" "}
</Button>
<Tooltip
label={
isBlockedFromRunningTestCase
? "Testcase running is disabled for Database questions."
: "Run your code on the server. This may take some time!"
}
>
<Button
variant="light"
onClick={runTestCases}
loading={isRunning}
disabled={isBlockedFromRunningTestCase}
>
{" "}
Run all testcases{" "}
</Button>
</Tooltip>
</Group>
<TestCasesDisplay
key={testCaseRunKey}
Expand All @@ -339,7 +362,7 @@ export default function TestCasesWrapper({
testCases={testCases}
roomId={roomId}
userId={userId}
question={question}
question={questionString}
/>
<>
{/* <>
Expand Down
4 changes: 1 addition & 3 deletions peer-prep/src/pages/Session/SessionPage/SessionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -686,15 +686,13 @@ export default function SessionPage() {
</Paper>

<TestCasesWrapper
testCases={question.testCases || []}
channelId={channelId}
questionId={question._id}
currentValueRef={currentValueRef}
userId={user._id}
otherUserId={otherUserId}
latestResultsRef={latestResultsRef}
roomId={roomId}
question={question.description.descriptionText}
question={question}
/>
</Stack>
</Flex>
Expand Down

0 comments on commit 4cd0bef

Please sign in to comment.