HyeonJun Jeon

[Add] Login test

function login(id, pw) {
return `I got data { id:"${id}" pw:"${pw}" }`;
}
export { login };
......
import { useState } from "react";
import { useNavigate } from "react-router-dom";
import { login } from "../libs/E_Campus";
import "../styles/Debug.css";
import { initTempSubjects } from "../utils/Test";
const Debug = () => {
const [state, setState] = useState({ input: "", output: "" });
const [state, setState] = useState({
type: "login",
input1: "",
input2: "",
output: "",
});
const handleChangeState = (e) => {
setState({
......@@ -13,10 +21,18 @@ const Debug = () => {
};
const handleSubmit = async (e) => {
if (state.input === "init") await initTempSubjects();
const result = state.input;
let result;
switch (state.type) {
case "initSubjects":
await initTempSubjects();
result = "inited";
break;
case "login":
result = login(state.input1, state.input2);
break;
default:
}
console.log(result);
setState({ ...state, output: result });
};
......@@ -33,10 +49,28 @@ const Debug = () => {
Home
</button>
</div>
<div className="dd">
<div>
<span>type : </span>
<select name="type" value={state.type} onChange={handleChangeState}>
<option value={"initSubjects"}>initSubjects</option>
<option value={"login"}>login</option>
</select>
</div>
<input value={state.input} onChange={handleChangeState} name="input" />
<input
value={state.input1}
onChange={handleChangeState}
name="input1"
/>
<input
value={state.input2}
onChange={handleChangeState}
name="input2"
/>
<button onClick={handleSubmit}>Enter</button>
<div>{"result : " + state.output}</div>
<div>{"result : \n" + state.output}</div>
</div>
</div>
);
};
......
.dd {
display: flex;
flex-direction: column;
width: 300px;
margin: 10px 0 10px 0;
}
.dd > div,
.dd > span {
margin: 5px 0 5px 0;
}