Skip to content

Commit

Permalink
Validate mail (#829)
Browse files Browse the repository at this point in the history
* changed emailRegex form so that it will except all type of email . in previous it wont accept email that having space after .com and yahoo.com

* changed emailRegex form so that it will except all type of email . in previous it wont accept email that having space after .com and yahoo.com

* added line cy.should('be.disabled'). as some test cases are failed . for more info visit Validate mail pull request

* added line cy.should('be.disabled'). as some test cases are failed . for more info visit Validate mail pull request

* Update forgotpassword.cy.js

---------

Co-authored-by: MOHAMMAD SARFRAZ ALAM <sarf.alam0206@gmail.com>
  • Loading branch information
kushalShukla-web and Sarfraz-droid committed Jul 13, 2023
1 parent e35264f commit 6446e9e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe("Forgot Password Page | CodeLabz", () => {
});
});


before(function () {
indexedDB.deleteDatabase("firebaseLocalStorageDb");
});
Expand All @@ -22,8 +23,7 @@ describe("Forgot Password Page | CodeLabz", () => {

it("empty email ", function () {
cy.visit(`${this.base_url}forgotpassword`);
cy.get("[data-testId=forgotPasswordButton]").click();
cy.contains("The email address is badly formatted.");
cy.get("[data-testId=forgotPasswordButton]").should('be.disabled');
});
it("successfull ", function () {
cy.visit(`${this.base_url}forgotpassword`);
Expand Down
14 changes: 12 additions & 2 deletions src/components/AuthPage/ForgotPassword/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const ForgotPassword = ({
const [success, setSuccess] = useState(false);
const [email, setEmail] = useState("");
const [open, setOpen] = React.useState(true);
const [isValidEmail, setIsValidEmail] = useState(false);
const errorProps = useSelector(({ auth }) => auth.profile.error);
const loadingProps = useSelector(({ auth }) => auth.profile.loading);
const dispatch = useDispatch();
Expand All @@ -62,12 +63,20 @@ const ForgotPassword = ({
[dispatch]
);


const onSubmit = async (values) => {
values.preventDefault();
setError("");
await sendPasswordResetEmail(email)(firebase, dispatch);
};

const handleChange =(e)=>{
const enteredEmail = e.target.value;
setEmail(enteredEmail)
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+\s*$/;
const isValid = emailRegex.test(enteredEmail);
setIsValidEmail(isValid);
}
const classes = useStyles();

return (
Expand Down Expand Up @@ -115,7 +124,7 @@ const ForgotPassword = ({
<OutlinedInput
placeholder="Email"
autoComplete="email"
onChange={(e) => setEmail(e.target.value)}
onChange={handleChange}
className="mb-32"
fullWidth
height="10rem"
Expand All @@ -134,7 +143,8 @@ const ForgotPassword = ({
className="mt-10"
type="submit"
fullWidth
data-testId="forgotPasswordButton">
data-testId="forgotPasswordButton"
disabled={!isValidEmail}>
{loading ? "Sending..." : "Send me the link"}
</Button>
</form>
Expand Down

0 comments on commit 6446e9e

Please sign in to comment.