-
Notifications
You must be signed in to change notification settings - Fork 0
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
WPP15 - User Page #63
Open
connormckellips
wants to merge
15
commits into
master
Choose a base branch
from
WPP15-UserPage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5bc7942
Included page routes and updates
connormckellips 0005930
Temporary User Page route
connormckellips a8aac57
Put more stuff on here
connormckellips 4f8f4f5
Added in some more stuff
connormckellips d0bd46d
Updated page route
connormckellips ffd6a92
Included username change password
connormckellips 29c4b3c
Continuing work here
connormckellips d867a3f
Updated ChangePassword
connormckellips d8bb633
Revert "Updated ChangePassword"
connormckellips 57beceb
Included form information
connormckellips 73f8b9b
Modal finally works!
connormckellips 838aeb0
Placed in tests for change password
connormckellips 2a6a684
Partial completion of user page tests
connormckellips 767b776
Finally have all tests in the user page done
connormckellips 73f3d05
Final css refactoring
connormckellips File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.changePassword_Label{ | ||
color:black; | ||
} | ||
|
||
.changePassword_Submit{ | ||
background-color: lightgreen; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import React, { Component } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { Button, Form, Row } from "react-bootstrap"; | ||
import { changePassword } from "../../api/DataHelper"; | ||
import "./ChangePassword.css" | ||
import { checkPasswordRequirements } from "../../../utilities/AccountValidators"; | ||
|
||
//Default values for form data | ||
const initialFormData = Object.freeze({ | ||
currentPassword: "", | ||
newPassword: "", | ||
confirmNewPassword: "", | ||
}); | ||
|
||
|
||
function ChangePassword(props) { | ||
//formData is an object that holds currentPassword, newPassword, and confirmNewPassword | ||
const [formData, updateFormData] = React.useState(initialFormData); | ||
const navigate = useNavigate(); | ||
//Whenever username or confirmPassword input boxes change, this saves the new data to formData | ||
const handleChange = (e) => { | ||
updateFormData({ | ||
...formData, | ||
[e.target.name]: e.target.value.trim(), | ||
}); | ||
}; | ||
//See if new password meets requirements, and new password is confirmed, then close page | ||
const handleSubmit = (e) => { | ||
e.preventDefault(); | ||
try { | ||
if(checkPasswordRequirements(formData.newPassword) && | ||
(formData.newPassword == formData.confirmNewPassword)) { | ||
changePassword(formData) | ||
.then((res) => { | ||
//No need to navigate anywhere else from this point. | ||
//Give user the option to continue viewing user profile | ||
alert("Password successfully changed") | ||
}) | ||
.catch((err) => { | ||
alert(err) | ||
}) | ||
} | ||
console.log("Hey this code works"); | ||
props.close(); | ||
} catch (error) { | ||
alert(error.message); | ||
} | ||
}; | ||
return( | ||
<Form onSubmit={handleSubmit}> | ||
<Row className="changePassword_Label"> | ||
<Form.Text>Enter Current Password:</Form.Text> | ||
<Form.Control | ||
type="password" | ||
data-testid="currentPassword" | ||
name="currentPassword" | ||
onChange={handleChange} | ||
/> | ||
</Row> | ||
<Row className="changePassword_Label"> | ||
<Form.Text>Enter New Password:</Form.Text> | ||
<Form.Control | ||
type="password" | ||
data-testid="newPassword" | ||
name="newPassword" | ||
onChange={handleChange} | ||
/> | ||
</Row> | ||
<Row className="changePassword_Label"> | ||
<Form.Text>Confirm New Password:</Form.Text> | ||
<Form.Control | ||
type="password" | ||
data-testid="confirmNewPassword" | ||
name="confirmNewPassword" | ||
onChange={handleChange} | ||
/> | ||
</Row> | ||
<Row> | ||
<Button | ||
className="changePassword_Submit" | ||
variant="primary" | ||
type="submit" | ||
data-testid="changePassword_Submit" | ||
onClick={handleSubmit} | ||
> | ||
Change Password | ||
</Button> | ||
</Row> | ||
</Form> | ||
); | ||
} | ||
|
||
export { ChangePassword }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.userPage_ProfilePicture { | ||
display: block; | ||
margin: auto; | ||
} | ||
|
||
.userPage_Title{ | ||
color: white; | ||
text-align: center; | ||
font-size: large; | ||
} | ||
|
||
.userPage_Username{ | ||
color: white; | ||
text-align: center; | ||
} | ||
|
||
.userPage_Button{ | ||
background-color: lightgreen; | ||
text-align: center; | ||
margin: auto; | ||
display: block; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, { useState } from 'react'; | ||
import { Link, useNavigate } from "react-router-dom"; | ||
import { Button, Form, Container, Modal } from "react-bootstrap"; | ||
import { ChangePassword } from "../../components/ChangePassword/ChangePassword"; | ||
import "./UserPage.css"; | ||
|
||
export default function UserPage () { | ||
const userIcon = | ||
"https://api.dicebear.com/5.x/adventurer/svg?seed=Gracie&scale=130&radius=20&backgroundType=solid,gradientLinear&randomizeIds=true&backgroundColor=c0aede,b6e3f4,d1d4f9,ffdfbf,ffd5dc"; | ||
|
||
const [showChange, setShowChange] = useState(false); | ||
|
||
const handleShowChange = () => setShowChange(true); | ||
const handleCloseChange = () => setShowChange(false); | ||
|
||
//Default values for form data | ||
const initialFormData = Object.freeze({ | ||
currentPassword: "", | ||
newPassword: "", | ||
confirmNewPassword: "", | ||
}); | ||
|
||
const [formData, updateFormData] = React.useState(initialFormData); | ||
|
||
const handleChange = (e) => { | ||
updateFormData({ | ||
...formData, | ||
[e.target.name]: e.target.value.trim() | ||
}); | ||
} | ||
|
||
const navigate = useNavigate(); | ||
|
||
return( | ||
<div className="UserPage" data-testid="userPage"> | ||
<div> | ||
<p className="userPage_Title">User Profile</p> | ||
</div> | ||
<div> | ||
<img className="userPage_ProfilePicture" src={userIcon} data-testid="profilePic" height="75" /> | ||
</div> | ||
<div> | ||
<p className="userPage_Username" data-testid="usename"> Username goes here! </p> | ||
</div> | ||
<div> | ||
<Button | ||
className="userPage_Button" | ||
variant="secondary" | ||
data-testid="changePassword" | ||
onClick={handleShowChange}> | ||
Change Password | ||
</Button> | ||
<Modal show={showChange} onHide={handleCloseChange}> | ||
<Modal.Header closeButton> | ||
<Modal.Title>Change Password</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<ChangePassword /> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Button variant="secondary" onClick={handleCloseChange}> | ||
Close | ||
</Button> | ||
</Modal.Footer> | ||
</Modal> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { ChangePassword } from "../../client/components/ChangePassword/ChangePassword"; | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { BrowserRouter } from "react-router-dom"; | ||
|
||
describe("Tests for Change Password", () => { | ||
beforeAll(() => { | ||
jest.spyOn(console, "log").mockImplementation(() => {}); | ||
jest.spyOn(console, "error").mockImplementation(() => {}); | ||
}); | ||
|
||
test("Checks for current password label", () => { | ||
const wrapper = render( | ||
<BrowserRouter> | ||
<ChangePassword/> | ||
</BrowserRouter> | ||
); | ||
expect(wrapper.baseElement.outerHTML).toContain("Enter Current Password:"); | ||
}); | ||
|
||
test("Checks for new password label", () => { | ||
const wrapper = render( | ||
<BrowserRouter> | ||
<ChangePassword/> | ||
</BrowserRouter> | ||
); | ||
expect(wrapper.baseElement.outerHTML).toContain("Enter New Password:"); | ||
}); | ||
|
||
test("Checks for confirm new password label", () => { | ||
const wrapper = render( | ||
<BrowserRouter> | ||
<ChangePassword/> | ||
</BrowserRouter> | ||
); | ||
expect(wrapper.baseElement.outerHTML).toContain("Confirm New Password:"); | ||
}); | ||
|
||
test("Checks for successful form submission", () => { | ||
const consoleSpy = jest.spyOn(global.console, "log"); | ||
const close = jest.fn(); | ||
const wrapper = render( | ||
<BrowserRouter> | ||
<ChangePassword close={close}/> | ||
</BrowserRouter> | ||
); | ||
|
||
const inputCurrentPassword = screen.getByTestId("currentPassword"); | ||
userEvent.type(inputCurrentPassword, "Connor123"); | ||
|
||
const inputNewPassword = screen.getByTestId("newPassword"); | ||
userEvent.type(inputNewPassword, "Connor1234"); | ||
|
||
const inputConfirmNewPassword = screen.getByTestId("confirmNewPassword"); | ||
userEvent.type(inputConfirmNewPassword, "Connor1234"); | ||
|
||
const submitButton = screen.getByTestId("changePassword_Submit"); | ||
userEvent.click(submitButton); | ||
|
||
expect(consoleSpy).toBeCalledWith("Hey this code works"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import UserPage from "../../client/pages/UserPage/UserPage"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { BrowserRouter } from "react-router-dom"; | ||
|
||
describe("Tests for User Page", () => { | ||
beforeAll(() => { | ||
jest.spyOn(console, "log").mockImplementation(); | ||
jest.spyOn(console, "error").mockImplementation(); | ||
}); | ||
|
||
test("Checks for User Profile header", () => { | ||
const { baseElement } = render( | ||
<BrowserRouter> | ||
<UserPage/> | ||
</BrowserRouter> | ||
); | ||
expect(baseElement.outerHTML).toContain("User Profile"); | ||
}); | ||
|
||
test("Checks for user profile picture", () => { | ||
render( | ||
<UserPage url="/UserProfile"/>, {wrapper: BrowserRouter} | ||
); | ||
|
||
expect(screen.getByTestId("profilePic").outerHTML).toContain("https://api.dicebear.com/5.x/adventurer/svg?seed=Gracie&scale=130&radius=20&backgroundType=solid,gradientLinear&randomizeIds=true&backgroundColor=c0aede,b6e3f4,d1d4f9,ffdfbf,ffd5dc"); | ||
}); | ||
|
||
test("Checks for username header", () => { | ||
const { baseElement } = render( | ||
<BrowserRouter> | ||
<UserPage/> | ||
</BrowserRouter> | ||
); | ||
expect(baseElement.outerHTML).toContain("Username goes here!"); | ||
}); | ||
|
||
test("Checks for change password button", () => { | ||
const { baseElement } = render( | ||
<BrowserRouter> | ||
<UserPage/> | ||
</BrowserRouter> | ||
); | ||
expect(baseElement.outerHTML).toContain("Change Password"); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
wouldn't it be better to actually display the username, as is mentioned in this user story