feat: implement test cases tab with styling and functionality for displaying test cases
This commit is contained in:
@@ -18,6 +18,7 @@ const CodeChallenge = () => {
|
|||||||
const [timeRemaining, setTimeRemaining] = useState(null);
|
const [timeRemaining, setTimeRemaining] = useState(null);
|
||||||
const [terminalInput, setTerminalInput] = useState('');
|
const [terminalInput, setTerminalInput] = useState('');
|
||||||
const [waitingForInput, setWaitingForInput] = useState(false);
|
const [waitingForInput, setWaitingForInput] = useState(false);
|
||||||
|
const [activeTab, setActiveTab] = useState('console'); // 'console' or 'testcases'
|
||||||
const socketRef = useRef(null);
|
const socketRef = useRef(null);
|
||||||
const terminalInputRef = useRef(null);
|
const terminalInputRef = useRef(null);
|
||||||
const { token } = useAuth();
|
const { token } = useAuth();
|
||||||
@@ -729,27 +730,6 @@ const CodeChallenge = () => {
|
|||||||
{currentQuestion.constraints && <p><strong>Constraints:</strong> {currentQuestion.constraints}</p>}
|
{currentQuestion.constraints && <p><strong>Constraints:</strong> {currentQuestion.constraints}</p>}
|
||||||
{currentQuestion.marks && <p><strong>Points:</strong> {currentQuestion.marks}</p>}
|
{currentQuestion.marks && <p><strong>Points:</strong> {currentQuestion.marks}</p>}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{currentQuestion.test_cases && currentQuestion.test_cases.length > 0 && (
|
|
||||||
<div className="test-cases-section">
|
|
||||||
<h3>Example Test Cases:</h3>
|
|
||||||
{currentQuestion.test_cases.slice(0, 2).map((testCase, idx) => (
|
|
||||||
<div key={idx} className="test-case-card">
|
|
||||||
<div className="test-case-label">Example {idx + 1}</div>
|
|
||||||
<div className="test-case-content">
|
|
||||||
<div className="test-case-item">
|
|
||||||
<span className="test-label">Input:</span>
|
|
||||||
<code className="test-value">{testCase.input}</code>
|
|
||||||
</div>
|
|
||||||
<div className="test-case-item">
|
|
||||||
<span className="test-label">Expected Output:</span>
|
|
||||||
<code className="test-value">{testCase.expected_output}</code>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -954,55 +934,106 @@ const CodeChallenge = () => {
|
|||||||
<div className="console-section">
|
<div className="console-section">
|
||||||
<div className="console-header">
|
<div className="console-header">
|
||||||
<div className="console-tabs">
|
<div className="console-tabs">
|
||||||
<button className="console-tab console-tab-active">
|
<button
|
||||||
|
className={`console-tab ${activeTab === 'console' ? 'console-tab-active' : ''}`}
|
||||||
|
onClick={() => setActiveTab('console')}
|
||||||
|
>
|
||||||
<span>Console</span>
|
<span>Console</span>
|
||||||
</button>
|
</button>
|
||||||
<button className="console-tab">
|
<button
|
||||||
<span>Testcases</span>
|
className={`console-tab ${activeTab === 'testcases' ? 'console-tab-active' : ''}`}
|
||||||
|
onClick={() => setActiveTab('testcases')}
|
||||||
|
>
|
||||||
|
<span>Test Cases</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
|
||||||
className="console-content"
|
{/* Console Tab Content */}
|
||||||
onClick={() => {
|
{activeTab === 'console' && (
|
||||||
if (waitingForInput && terminalInputRef.current) {
|
<div
|
||||||
terminalInputRef.current.focus();
|
className="console-content"
|
||||||
}
|
onClick={() => {
|
||||||
}}
|
if (waitingForInput && terminalInputRef.current) {
|
||||||
style={{ cursor: waitingForInput ? 'text' : 'default' }}
|
terminalInputRef.current.focus();
|
||||||
>
|
}
|
||||||
{terminalOutput.length === 0 ? (
|
}}
|
||||||
<div className="console-placeholder">
|
style={{ cursor: waitingForInput ? 'text' : 'default' }}
|
||||||
Console output will appear here...
|
>
|
||||||
</div>
|
{terminalOutput.length === 0 ? (
|
||||||
) : (
|
<div className="console-placeholder">
|
||||||
<>
|
Console output will appear here...
|
||||||
{terminalOutput.map((line, index) => (
|
</div>
|
||||||
<div
|
) : (
|
||||||
key={index}
|
<>
|
||||||
className={`console-line ${line.type}`}
|
{terminalOutput.map((line, index) => (
|
||||||
>
|
<div
|
||||||
{line.content}
|
key={index}
|
||||||
</div>
|
className={`console-line ${line.type}`}
|
||||||
))}
|
>
|
||||||
{waitingForInput && (
|
{line.content}
|
||||||
<div className="console-line console-input-line">
|
</div>
|
||||||
<form onSubmit={handleTerminalInput} className="console-input-form">
|
))}
|
||||||
<span className="console-cursor">{'> '}</span>
|
{waitingForInput && (
|
||||||
<input
|
<div className="console-line console-input-line">
|
||||||
ref={terminalInputRef}
|
<form onSubmit={handleTerminalInput} className="console-input-form">
|
||||||
type="text"
|
<span className="console-cursor">{'> '}</span>
|
||||||
value={terminalInput}
|
<input
|
||||||
onChange={(e) => setTerminalInput(e.target.value)}
|
ref={terminalInputRef}
|
||||||
className="console-input"
|
type="text"
|
||||||
autoFocus
|
value={terminalInput}
|
||||||
/>
|
onChange={(e) => setTerminalInput(e.target.value)}
|
||||||
</form>
|
className="console-input"
|
||||||
</div>
|
autoFocus
|
||||||
)}
|
/>
|
||||||
</>
|
</form>
|
||||||
)}
|
</div>
|
||||||
</div>
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Test Cases Tab Content */}
|
||||||
|
{activeTab === 'testcases' && (
|
||||||
|
<div className="console-content testcases-tab-content">
|
||||||
|
{(() => {
|
||||||
|
const currentQuestion = getCurrentQuestion();
|
||||||
|
if (currentQuestion?.test_cases && currentQuestion.test_cases.length > 0) {
|
||||||
|
return (
|
||||||
|
<div className="testcases-container">
|
||||||
|
{currentQuestion.test_cases.map((testCase, idx) => (
|
||||||
|
<div key={testCase.id || idx} className="testcase-item">
|
||||||
|
<div className="testcase-header">
|
||||||
|
<span className="testcase-title">Test Case {idx + 1}</span>
|
||||||
|
{testCase.is_sample && (
|
||||||
|
<span className="testcase-badge">Sample</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="testcase-body">
|
||||||
|
<div className="testcase-field">
|
||||||
|
<div className="testcase-field-label">Input:</div>
|
||||||
|
<pre className="testcase-field-value">{testCase.input}</pre>
|
||||||
|
</div>
|
||||||
|
<div className="testcase-field">
|
||||||
|
<div className="testcase-field-label">Expected Output:</div>
|
||||||
|
<pre className="testcase-field-value">{testCase.expected_output}</pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<div className="console-placeholder">
|
||||||
|
No test cases available for this question.
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})()}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1735,6 +1735,90 @@ body {
|
|||||||
caret-color: #212529;
|
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 */
|
||||||
.action-bar {
|
.action-bar {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|||||||
Reference in New Issue
Block a user