-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27b9ed3
commit 74c343e
Showing
9 changed files
with
276 additions
and
78 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Feature: Login | ||
Scenario: User enters valid details that match with an existing account | ||
Given I navigate to the "Home" page | ||
Then I open the menu drawer | ||
When I enter user email and password | ||
When I click to login button | ||
Then I should see the text "Hello Marco!" | ||
|
||
Scenario: User enters unmatched details | ||
Given I navigate to the "Home" page | ||
Then I open the menu drawer | ||
When I click to login button | ||
Then I should see the text "Invalid email address." | ||
Then I should see the text "Password is required." |
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
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,12 @@ | ||
import { When } from "@badeball/cypress-cucumber-preprocessor"; | ||
import { clickOnText } from "./rtlDescriptors"; | ||
import { homePageDescriptor } from "../../e2e/pageDescriptors"; | ||
|
||
When("I enter user email and password", () => { | ||
homePageDescriptor.emailLoginInput().type("[email protected]"); | ||
homePageDescriptor.passwordLoginInput().type("Password@123"); | ||
}); | ||
|
||
When("I click to login button", () => { | ||
clickOnText("Login to your account"); | ||
}); |
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { useMutation } from "@apollo/client"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { Button, Input, Typography } from "@material-tailwind/react"; | ||
import { SubmitHandler, useForm } from "react-hook-form"; | ||
import { Button, Typography } from "@material-tailwind/react"; | ||
import { FormProvider, SubmitHandler, useForm } from "react-hook-form"; | ||
import { Link, useRevalidator } from "react-router-dom"; | ||
import { toast } from "react-toastify"; | ||
import { z } from "zod"; | ||
import { FormInput } from "@components/Form"; | ||
import { | ||
LOGIN_USER, | ||
GET_USER_ATTEMPTS, | ||
|
@@ -15,24 +16,24 @@ import { | |
} from "@utils/queries"; | ||
|
||
const formSchema = z.object({ | ||
email: z.string().email(), | ||
password: z.string().min(1), | ||
email: z.string().email("Invalid email address."), | ||
password: z.string().min(1, "Password is required."), | ||
}); | ||
|
||
export function LoginForm({ toggleDrawer }: { toggleDrawer: () => void }) { | ||
const revalidator = useRevalidator(); | ||
const { | ||
register, | ||
handleSubmit, | ||
reset, | ||
formState: { errors }, | ||
} = useForm<z.infer<typeof formSchema>>({ | ||
const form = useForm<z.infer<typeof formSchema>>({ | ||
resolver: zodResolver(formSchema), | ||
defaultValues: { | ||
email: "", | ||
password: "", | ||
}, | ||
}); | ||
const { | ||
handleSubmit, | ||
reset, | ||
formState: { errors }, | ||
} = form; | ||
|
||
const [loginMutation, { loading: isLoadingLogin, error: mutationError }] = useMutation(LOGIN_USER, { | ||
onCompleted: async ({ loginUser }) => { | ||
|
@@ -67,45 +68,45 @@ export function LoginForm({ toggleDrawer }: { toggleDrawer: () => void }) { | |
</Typography> | ||
</div> | ||
|
||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-3 py-4"> | ||
<Input | ||
{...register("email")} | ||
name="email" | ||
size="lg" | ||
label="Email address" | ||
placeholder="[email protected]" | ||
error={!!errors.email} | ||
/> | ||
<FormProvider {...form}> | ||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-3 py-4"> | ||
<FormInput | ||
name="email" | ||
size="lg" | ||
label="Email address" | ||
placeholder="[email protected]" | ||
fieldError={errors.email} | ||
/> | ||
|
||
<Input | ||
{...register("password")} | ||
name="password" | ||
size="lg" | ||
type="password" | ||
label="Password" | ||
placeholder="*******" | ||
error={!!errors.password} | ||
/> | ||
<FormInput | ||
name="password" | ||
size="lg" | ||
type="password" | ||
label="Password" | ||
placeholder="*******" | ||
fieldError={errors.password} | ||
/> | ||
|
||
{mutationError?.message && ( | ||
<Typography variant="small" color="red"> | ||
{mutationError.message} | ||
</Typography> | ||
)} | ||
{mutationError?.message && ( | ||
<Typography variant="small" color="red"> | ||
{mutationError.message} | ||
</Typography> | ||
)} | ||
|
||
<Button type="submit" fullWidth disabled={isLoadingLogin} loading={isLoadingLogin}> | ||
Login to your account | ||
</Button> | ||
<Button type="submit" fullWidth disabled={isLoadingLogin} loading={isLoadingLogin}> | ||
Login to your account | ||
</Button> | ||
|
||
<div className="flex items-center"> | ||
<Typography>Not registered?</Typography> | ||
<Link to="/register" onClick={toggleDrawer} className="text-blue-700 hover:underline"> | ||
<Button size="sm" variant="text"> | ||
Create an account | ||
</Button> | ||
</Link> | ||
</div> | ||
</form> | ||
<div className="flex items-center"> | ||
<Typography>Not registered?</Typography> | ||
<Link to="/register" onClick={toggleDrawer} className="text-blue-700 hover:underline"> | ||
<Button size="sm" variant="text"> | ||
Create an account | ||
</Button> | ||
</Link> | ||
</div> | ||
</form> | ||
</FormProvider> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.