From b075e5b3d39982def7a099bf0ddc73c8604c0981 Mon Sep 17 00:00:00 2001 From: Arnab-Afk Date: Sat, 8 Nov 2025 22:52:51 +0530 Subject: [PATCH] feat: implement test cases tab with styling and functionality for displaying test cases --- Frontend/src/components/CodeChallenge.jsx | 161 +++++++++++++--------- Frontend/src/index.css | 84 +++++++++++ 2 files changed, 180 insertions(+), 65 deletions(-) diff --git a/Frontend/src/components/CodeChallenge.jsx b/Frontend/src/components/CodeChallenge.jsx index b4bf573..177f527 100644 --- a/Frontend/src/components/CodeChallenge.jsx +++ b/Frontend/src/components/CodeChallenge.jsx @@ -18,6 +18,7 @@ const CodeChallenge = () => { const [timeRemaining, setTimeRemaining] = useState(null); const [terminalInput, setTerminalInput] = useState(''); const [waitingForInput, setWaitingForInput] = useState(false); + const [activeTab, setActiveTab] = useState('console'); // 'console' or 'testcases' const socketRef = useRef(null); const terminalInputRef = useRef(null); const { token } = useAuth(); @@ -729,27 +730,6 @@ const CodeChallenge = () => { {currentQuestion.constraints &&

Constraints: {currentQuestion.constraints}

} {currentQuestion.marks &&

Points: {currentQuestion.marks}

} - - {currentQuestion.test_cases && currentQuestion.test_cases.length > 0 && ( -
-

Example Test Cases:

- {currentQuestion.test_cases.slice(0, 2).map((testCase, idx) => ( -
-
Example {idx + 1}
-
-
- Input: - {testCase.input} -
-
- Expected Output: - {testCase.expected_output} -
-
-
- ))} -
- )} ); } @@ -954,55 +934,106 @@ const CodeChallenge = () => {
- -
-
{ - if (waitingForInput && terminalInputRef.current) { - terminalInputRef.current.focus(); - } - }} - style={{ cursor: waitingForInput ? 'text' : 'default' }} - > - {terminalOutput.length === 0 ? ( -
- Console output will appear here... -
- ) : ( - <> - {terminalOutput.map((line, index) => ( -
- {line.content} -
- ))} - {waitingForInput && ( -
-
- {'> '} - setTerminalInput(e.target.value)} - className="console-input" - autoFocus - /> -
-
- )} - - )} -
+ + {/* Console Tab Content */} + {activeTab === 'console' && ( +
{ + if (waitingForInput && terminalInputRef.current) { + terminalInputRef.current.focus(); + } + }} + style={{ cursor: waitingForInput ? 'text' : 'default' }} + > + {terminalOutput.length === 0 ? ( +
+ Console output will appear here... +
+ ) : ( + <> + {terminalOutput.map((line, index) => ( +
+ {line.content} +
+ ))} + {waitingForInput && ( +
+
+ {'> '} + setTerminalInput(e.target.value)} + className="console-input" + autoFocus + /> +
+
+ )} + + )} +
+ )} + + {/* Test Cases Tab Content */} + {activeTab === 'testcases' && ( +
+ {(() => { + const currentQuestion = getCurrentQuestion(); + if (currentQuestion?.test_cases && currentQuestion.test_cases.length > 0) { + return ( +
+ {currentQuestion.test_cases.map((testCase, idx) => ( +
+
+ Test Case {idx + 1} + {testCase.is_sample && ( + Sample + )} +
+
+
+
Input:
+
{testCase.input}
+
+
+
Expected Output:
+
{testCase.expected_output}
+
+
+
+ ))} +
+ ); + } else { + return ( +
+ No test cases available for this question. +
+ ); + } + })()} +
+ )}
diff --git a/Frontend/src/index.css b/Frontend/src/index.css index ef125c8..22321fb 100644 --- a/Frontend/src/index.css +++ b/Frontend/src/index.css @@ -1735,6 +1735,90 @@ body { caret-color: #212529; } +/* Test Cases Tab Styles */ +.testcases-tab-content { + overflow-y: auto; + padding: 0; +} + +.testcases-container { + padding: 12px; +} + +.testcase-item { + background-color: #ffffff; + border: 1px solid #dee2e6; + border-radius: 4px; + margin-bottom: 12px; + overflow: hidden; +} + +.testcase-item:last-child { + margin-bottom: 0; +} + +.testcase-header { + display: flex; + align-items: center; + justify-content: space-between; + padding: 8px 12px; + background-color: #f8f9fa; + border-bottom: 1px solid #dee2e6; +} + +.testcase-title { + font-size: 12px; + font-weight: 600; + color: #212529; +} + +.testcase-badge { + font-size: 10px; + font-weight: 600; + padding: 2px 8px; + background-color: #e7f3ff; + color: #0066cc; + border-radius: 3px; + text-transform: uppercase; + letter-spacing: 0.5px; +} + +.testcase-body { + padding: 12px; +} + +.testcase-field { + margin-bottom: 12px; +} + +.testcase-field:last-child { + margin-bottom: 0; +} + +.testcase-field-label { + font-size: 11px; + font-weight: 600; + color: #6c757d; + margin-bottom: 4px; + text-transform: uppercase; + letter-spacing: 0.5px; +} + +.testcase-field-value { + background-color: #f8f9fa; + border: 1px solid #dee2e6; + border-radius: 3px; + padding: 8px 10px; + font-family: 'Consolas', 'Monaco', monospace; + font-size: 12px; + line-height: 1.5; + color: #212529; + margin: 0; + white-space: pre-wrap; + word-break: break-word; + overflow-x: auto; +} + /* Action Bar */ .action-bar { position: absolute;