-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mm 107 startquizbutton #19
Changes from 3 commits
a98eea2
6794367
d4867f9
844809a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import Home from "./Home"; | ||
import "@testing-library/jest-dom"; | ||
import React, { useState } from "react"; | ||
|
||
test("user's name is displayed on form submission", () => { | ||
render(<Home />); | ||
|
||
test.skip("user's name is displayed on form submission", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can actually fully delete this test as it's no longer the expected behaviour |
||
const name = "Luigi"; | ||
const [username, setUsername] = useState(name); | ||
|
||
render(<Home username={username} setUsername={setUsername}/>); | ||
|
||
const textArea = screen.getByLabelText(/Enter name:/); | ||
fireEvent.change(textArea, { target: { value: name }}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
import React, { useState } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import DisplayBackgroundImage from '../images/DisplayBackgroundImage'; | ||
|
||
function Home() { | ||
interface getUserProp{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the convention is have the props name be ComponentNameProps - so in this case it would be |
||
username:string; | ||
setUsername:(uname:string)=>void; | ||
} | ||
|
||
function Home(props:getUserProp) { | ||
|
||
const [username, setUsername] = useState(""); | ||
//const [username, setUsername] = useState(""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there are a couple of lines commented out in this file that I think are old code that we're not using. |
||
const [submitStatus, setSubmitStatus] = useState(false); | ||
|
||
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
setSubmitStatus(true); | ||
} | ||
|
||
let navigate = useNavigate(); | ||
const routeChange = () =>{ | ||
let path = '/quiz'; | ||
navigate(path); | ||
} | ||
|
||
const homeBackgroundImage = DisplayBackgroundImage(); | ||
|
||
return ( | ||
|
@@ -21,14 +33,19 @@ function Home() { | |
<form onSubmit={handleSubmit}> | ||
<label>Enter name: | ||
<input type="text" | ||
value={username} | ||
onChange={username => setUsername(username.target.value)} | ||
value={props.username} | ||
//onChange={username => setUsername(username.target.value)} | ||
onChange={(username) => {props.setUsername(username.target.value)}} | ||
/> | ||
</label> | ||
<button type="submit">Submit</button> | ||
{submitStatus ? <p>Welcome {username}!</p> : null} | ||
{submitStatus ? <p>Welcome {props.username}!</p> : null} | ||
</form> | ||
|
||
<button className="startQuizButton" onClick={routeChange}> | ||
Start quiz | ||
</button> | ||
|
||
</main> | ||
</> | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
import { QuestionDisplay } from "../QuestionDisplay/QuestionDisplay" | ||
|
||
export function Quiz () { | ||
interface getUserProp{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above please can you change this to |
||
username:string; | ||
} | ||
|
||
export function Quiz (props:getUserProp) { | ||
return ( | ||
<QuestionDisplay/> | ||
<div> | ||
User : {props.username} | ||
<QuestionDisplay/> | ||
</div> | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job moving the state up here