Skip to content

Commit

Permalink
Add test case components
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolelim02 committed Oct 30, 2024
1 parent ee43fb4 commit bb8c950
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
49 changes: 49 additions & 0 deletions frontend/src/components/TestCase/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Box, styled, Typography } from "@mui/material";

type TestCaseProps = {
input: string;
output: string;
stdout: string;
result: string;
};

const StyledBox = styled(Box)(({ theme }) => ({
margin: theme.spacing(2, 0),
}));

const StyledTypography = styled(Typography)(({ theme }) => ({
background: theme.palette.divider,
padding: theme.spacing(1, 2),
borderRadius: theme.spacing(1),
whiteSpace: "pre-line",
}));

const TestCase: React.FC<TestCaseProps> = ({
input,
output,
stdout,
result,
}) => {
return (
<Box>
<StyledBox sx={(theme) => ({ marginBottom: theme.spacing(2) })}>
<Typography variant="overline">Input</Typography>
<StyledTypography fontFamily={"monospace"}>{input}</StyledTypography>
</StyledBox>
<StyledBox>
<Typography variant="overline">Output</Typography>
<StyledTypography fontFamily={"monospace"}>{output}</StyledTypography>
</StyledBox>
<StyledBox>
<Typography variant="overline">Standard output</Typography>
<StyledTypography fontFamily={"monospace"}>{stdout}</StyledTypography>
</StyledBox>
<StyledBox>
<Typography variant="overline">Result</Typography>
<StyledTypography fontFamily={"monospace"}>{result}</StyledTypography>
</StyledBox>
</Box>
);
};

export default TestCase;
51 changes: 49 additions & 2 deletions frontend/src/pages/CollabSandbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
Grid2,
Tab,
Tabs,
Typography,
} from "@mui/material";
import classes from "./index.module.css";
import { useMatch } from "../../contexts/MatchContext";
Expand All @@ -26,6 +25,31 @@ import QuestionDetailComponent from "../../components/QuestionDetail";
import { Navigate } from "react-router-dom";
import Chat from "../../components/Chat";
import TabPanel from "../../components/TabPanel";
import TestCase from "../../components/TestCase";

// hardcode for now...

type TestCase = {
input: string;
output: string;
stdout: string;
result: string;
};

const testcases: TestCase[] = [
{
input: "1 2 3 4",
output: "1 2 3 4",
stdout: "1\n2\n3\n4",
result: "1 2 3 4",
},
{
input: "5 6 7 8",
output: "5 6 7 8",
stdout: "5\n6\n7\n8",
result: "5 6 7 8",
},
];

const CollabSandbox: React.FC = () => {
const [showErrorScreen, setShowErrorScreen] = useState<boolean>(false);
Expand All @@ -48,6 +72,7 @@ const CollabSandbox: React.FC = () => {
const [state, dispatch] = useReducer(reducer, initialState);
const { selectedQuestion } = state;
const [selectedTab, setSelectedTab] = useState<"tests" | "chat">("tests");
const [selectedTestcase, setSelectedTestcase] = useState(0);

useEffect(() => {
if (!partner) {
Expand Down Expand Up @@ -193,7 +218,29 @@ const CollabSandbox: React.FC = () => {
<Tab label="Chat" value="chat" />
</Tabs>
<TabPanel selected={selectedTab} value="tests">
<Typography>Tests</Typography>
<Box sx={(theme) => ({ margin: theme.spacing(2, 0) })}>
{[...Array(testcases.length)]
.map((_, index) => index + 1)
.map((i) => (
<Button
key={i}
variant="contained"
color={
selectedTestcase === i - 1 ? "primary" : "secondary"
}
onClick={() => setSelectedTestcase(i - 1)}
sx={(theme) => ({ margin: theme.spacing(0, 1) })}
>
Testcase {i}
</Button>
))}
</Box>
<TestCase
input={testcases[selectedTestcase].input}
output={testcases[selectedTestcase].output}
stdout={testcases[selectedTestcase].stdout}
result={testcases[selectedTestcase].result}
/>
</TabPanel>
<TabPanel selected={selectedTab} value="chat">
<Chat isActive={selectedTab === "chat"} />
Expand Down

0 comments on commit bb8c950

Please sign in to comment.