generated from Arquisoft/wiq_0
-
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
Feat/webapp/new signup #65
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
26649ca
feat: Creating the Signup.css
sergiorodriguezgarcia baef072
feat: Adding the Signup.test.js class
sergiorodriguezgarcia 8b39b97
feat: Deleting the css and updating the Signup.jsx
sergiorodriguezgarcia 1a032b8
feat: Changing the UI of the Signup
sergiorodriguezgarcia 58b339f
feat: Adding confirm password to the Signup and aesthetic changes
sergiorodriguezgarcia 49bbb4e
feat: Adding control to the show hide password
sergiorodriguezgarcia 702f8c5
feat: Adding the translation conventions to the Signup view
sergiorodriguezgarcia b126bdf
feat: Adding test cases to the Signup.test.js
sergiorodriguezgarcia 32d0845
feat: Fixing errors in the Signup.test.js
sergiorodriguezgarcia cc7e899
Merge branch 'develop' into feat/webapp/new-signup
sergiorodriguezgarcia 6ecdac0
fix: Making the Signup.test work correctly
sergiorodriguezgarcia c278c38
fx: Changes in the Signup.jsx to make the test pass
sergiorodriguezgarcia 994de83
Merge branch 'develop' into feat/webapp/new-signup
sergiorodriguezgarcia c419e3b
Update Signup.jsx
sergiorodriguezgarcia 1416212
fix: Updating to pass the test
sergiorodriguezgarcia 2a7ad39
Merge branch 'feat/webapp/new-signup' of https://github.com/Arquisoft…
sergiorodriguezgarcia 8e72663
fix: Changing the signup.jsx to pass the tests
sergiorodriguezgarcia 35de8f7
fix: Changing the signup.test error submitting the info
sergiorodriguezgarcia 353a454
fix: Updating the signup.tests
sergiorodriguezgarcia b9b0c65
fix: Merge Login.jsx
sergiorodriguezgarcia f8eecc9
feat: Adding buttons to follow conventions of other views
sergiorodriguezgarcia 17beee4
fix: Changing the Signup.test to pass with the new conventions
sergiorodriguezgarcia 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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import React from "react"; | ||
import Root from "../pages/Root"; | ||
import Login from "../pages/Login"; | ||
import { Route, createRoutesFromElements } from "react-router-dom"; | ||
import Signup from "../pages/Signup"; | ||
import { Route,createRoutesFromElements } from "react-router-dom"; | ||
|
||
export default createRoutesFromElements( | ||
<Route path="/" > | ||
<Route path="/"> | ||
<Route index element={<Root />} /> | ||
<Route path="/signup" element={<Signup />} /> | ||
<Route path="/login" element={<Login />}/> | ||
</Route> | ||
) |
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,53 +1,139 @@ | ||
import { Center } from "@chakra-ui/layout"; | ||
import { Button, FormControl, FormLabel, Heading, Input, Text, Stack } from "@chakra-ui/react"; | ||
import { Heading, Input, Button, InputGroup, Stack, InputLeftElement, chakra, Box, Avatar, FormControl, InputRightElement, Text, FormHelperText } from "@chakra-ui/react"; | ||
import { ViewIcon, ViewOffIcon } from '@chakra-ui/icons' | ||
import axios, { HttpStatusCode } from "axios"; | ||
import React, { useState } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { FaUserAlt, FaLock, FaAddressCard } from "react-icons/fa"; | ||
import ButtonEf from '../components/ButtonEf'; | ||
|
||
export default function Signup() { | ||
|
||
const [email, setEmail] = useState(""); | ||
const [username, setUsername] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
const [confirmPassword, setConfirmPassword] = useState(""); | ||
const [showPassword, setShowPassword] = useState(false); | ||
const [showConfirmPassword, setShowConfirmPassword] = useState(false); | ||
const [hasError, setHasError] = useState(false); | ||
|
||
const navigate = useNavigate(); | ||
const { t } = useTranslation(); | ||
|
||
const ChakraFaCardAlt = chakra(FaAddressCard); | ||
const ChakraFaUserAlt = chakra(FaUserAlt); | ||
const ChakraFaLock = chakra(FaLock); | ||
|
||
const sendLogin = async () => { | ||
let data = {}; | ||
let response = await axios.post(process.env.API_URL, data); | ||
if (response.status === HttpStatusCode.Accepted) { | ||
navigate("/home"); | ||
} else { | ||
try { | ||
const response = await axios.post(process.env.API_URL, { email, username, password }); | ||
if (response.status === HttpStatusCode.Accepted) { | ||
navigate("/home"); | ||
} | ||
} catch (error) { | ||
setHasError(true); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<Center display={"flex"} flexDirection={"column"} maxW={"100%"} minW={"30%"} mt={"2vh"}> | ||
<Heading as="h2">{ t("common.register")}</Heading> | ||
{ | ||
!hasError ? | ||
<></> : | ||
<Center bgColor={"#FFA98A"} margin={"1vh 0vw"} padding={"1vh 0vw"} | ||
color={"#FF0500"} border={"0.1875em solid #FF0500"} | ||
borderRadius={"0.75em"} maxW={"100%"} minW={"30%"}> | ||
<Center | ||
display={"flex"} | ||
flexDirection={"column"} | ||
w={"100wh"} | ||
h={"100vh"} | ||
bg={"blue.50"} | ||
justifyContent={"center"} | ||
alignItems={"center"} | ||
> | ||
{hasError && ( | ||
<div className="error-container"> | ||
<Text>Error</Text> | ||
</div> | ||
)} | ||
<Stack flexDir={"column"} mb="2" justifyContent="center" alignItems={"center"}> | ||
<Avatar bg="blue.500" /> | ||
<Heading as="h2" color="blue.400"> | ||
{t("common.register")} | ||
</Heading> | ||
{!hasError ? ( | ||
<></> | ||
) : ( | ||
<Center | ||
bgColor={"#FFA98A"} | ||
margin={"1vh 0vw"} | ||
padding={"1vh 0vw"} | ||
color={"#FF0500"} | ||
border={"0.1875em solid #FF0500"} | ||
borderRadius={"0.75em"} | ||
maxW={"100%"} | ||
minW={"30%"} | ||
> | ||
<Text>Error</Text> | ||
</Center> | ||
} | ||
<Stack spacing={4} mt={4} width="100%" mx={"auto"} maxWidth={"400px"}> | ||
<FormControl as="fieldset" padding={"1vh 0vw"} isRequired> | ||
<FormLabel>{ t("session.username") }</FormLabel> | ||
<Input type="text" /> | ||
</FormControl> | ||
<FormControl as="fieldset" padding={"1vh 0vw"} isRequired> | ||
<FormLabel>{ t("Correo electrónico") }</FormLabel> {/* To be changed */} | ||
<Input type="text" /> | ||
</FormControl> | ||
<FormControl as="fieldset" padding={"1vh 0vw"} isRequired> | ||
<FormLabel> {t("session.password")}</FormLabel> | ||
<Input type="password" /> | ||
</FormControl> | ||
<Button type="submit" onClick={sendLogin}>Enviar</Button> | ||
</Center> | ||
)} | ||
<Box minW={{ md: "400px" }}> | ||
<Stack spacing={4} p="1rem" backgroundColor="whiteAlpha.900" boxShadow="md"> | ||
<FormControl> | ||
<InputGroup> | ||
<InputLeftElement children={<ChakraFaCardAlt color="gray.300" />} /> | ||
<Input | ||
type="text" | ||
placeholder={t("session.email")} | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
/> | ||
</InputGroup> | ||
</FormControl> | ||
<FormControl> | ||
<InputGroup> | ||
<InputLeftElement children={<ChakraFaUserAlt color="gray.300" />} /> | ||
<Input | ||
type="text" | ||
placeholder={t("session.username")} | ||
value={username} | ||
onChange={(e) => setUsername(e.target.value)} | ||
/> | ||
</InputGroup> | ||
</FormControl> | ||
<FormControl> | ||
<InputGroup> | ||
<InputLeftElement children={<ChakraFaLock color="gray.300" />} /> | ||
<Input | ||
type={showPassword ? "text" : "password"} | ||
placeholder={t("session.password")} | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
/> | ||
<InputRightElement width="4.5rem"> | ||
<Button data-testid="show-confirm-password-button" h="1.75rem" size="sm" onClick={() => setShowPassword(!showPassword)}> | ||
{showPassword ? <ViewOffIcon/> : <ViewIcon/>} | ||
</Button> | ||
</InputRightElement> | ||
</InputGroup> | ||
</FormControl> | ||
<FormControl> | ||
<InputGroup> | ||
<InputLeftElement children={<ChakraFaLock color="gray.300" />} /> | ||
<Input | ||
type={showConfirmPassword ? "text" : "password"} | ||
placeholder={t("session.confirm_password")} | ||
value={confirmPassword} | ||
onChange={(e) => setConfirmPassword(e.target.value)} | ||
/> | ||
<InputRightElement width="4.5rem"> | ||
<Button data-testid="show-confirm-password-button" h="1.75rem" size="sm" onClick={() => setShowConfirmPassword(!showConfirmPassword)}> | ||
{showConfirmPassword ? <ViewOffIcon/> : <ViewIcon/>} | ||
</Button> | ||
</InputRightElement> | ||
</InputGroup> | ||
{confirmPassword && password && confirmPassword !== password && ( | ||
<FormHelperText color="red">Las contraseñas no coinciden</FormHelperText> | ||
)} | ||
</FormControl> | ||
<ButtonEf dataTestId={"Sign up"} variant={"solid"} colorScheme={"blue"} text={t("common.register")} onClick={sendLogin}/> | ||
</Stack> | ||
</Box> | ||
</Stack> | ||
</Center> | ||
); | ||
} | ||
} |
125 changes: 64 additions & 61 deletions
125
webapp/src/tests/Login.test.js → webapp/src/tests/Signup.test.js
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,61 +1,64 @@ | ||
import React from 'react'; | ||
import { render, fireEvent, screen, waitFor, act, getByLabelText, getByTestId } from '@testing-library/react'; | ||
import axios from 'axios'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import Login from '../pages/Login'; | ||
import { MemoryRouter, createMemoryRouter } from 'react-router'; | ||
import router from '../components/Router'; | ||
|
||
const mockAxios = new MockAdapter(axios); | ||
const mockRouter = createMemoryRouter(router); | ||
|
||
describe('Login component', () => { | ||
beforeEach(() => { | ||
mockAxios.reset(); | ||
}); | ||
|
||
it('renders form elements correctly', async () => { | ||
const { getByPlaceholderText, getByText } = render(<MemoryRouter><Login /></MemoryRouter>); | ||
|
||
expect(getByPlaceholderText('session.email')).toBeInTheDocument(); | ||
expect(getByPlaceholderText('session.password')).toBeInTheDocument(); | ||
expect(getByTestId(document.body, 'Login')).toBeInTheDocument(); | ||
}); | ||
|
||
it('toggles password visibility', () => { | ||
const { getByPlaceholderText, getByText } = render(<MemoryRouter><Login /></MemoryRouter>); | ||
|
||
const passwordInput = getByPlaceholderText('session.password'); | ||
const showPasswordButton = getByTestId(document.body, 'togglePasswordButton'); | ||
|
||
fireEvent.click(showPasswordButton); | ||
|
||
expect(passwordInput.getAttribute('type')).toBe('text'); | ||
}); | ||
|
||
it('submits form data correctly', async () => { | ||
const axiosMock = jest.spyOn(axios, 'post'); | ||
axiosMock.mockResolvedValueOnce({ status: 202 }); // Accepted status code | ||
|
||
// Render the Signup component | ||
const { getByPlaceholderText, getByText } = render(<MemoryRouter><Login /></MemoryRouter>); | ||
|
||
// Get form elements and submit button by their text and placeholder values | ||
const emailInput = getByPlaceholderText('session.email'); | ||
const passwordInput = getByPlaceholderText('session.password'); | ||
const signUpButton = getByTestId(document.body, 'Login'); | ||
|
||
// Fill out the form with valid data and submit it | ||
fireEvent.change(emailInput, { target: { value: '[email protected]' } }); | ||
fireEvent.change(passwordInput, { target: { value: 'password' } }); | ||
fireEvent.click(signUpButton); | ||
|
||
// Check if the form data was sent correctly | ||
await waitFor(() => { | ||
expect(axiosMock).toHaveBeenCalledWith(process.env.API_URL, {}); | ||
expect(axiosMock).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
axiosMock.mockRestore(); | ||
}); | ||
}); | ||
import React from 'react'; | ||
import { render, fireEvent, waitFor, getByTestId, getAllByTestId } from '@testing-library/react'; | ||
import axios from 'axios'; | ||
import { MemoryRouter, createMemoryRouter } from 'react-router'; | ||
import Signup from '../pages/Signup'; | ||
|
||
describe('Signup Component', () => { | ||
|
||
it('renders form elements correctly', () => { | ||
const { getByPlaceholderText, getByText } = render(<MemoryRouter><Signup /></MemoryRouter>); | ||
|
||
expect(getByPlaceholderText('session.email')).toBeInTheDocument(); | ||
expect(getByPlaceholderText('session.username')).toBeInTheDocument(); | ||
expect(getByPlaceholderText('session.password')).toBeInTheDocument(); | ||
expect(getByPlaceholderText('session.confirm_password')).toBeInTheDocument(); | ||
expect(getByTestId(document.body, 'Sign up')).toBeInTheDocument(); | ||
}); | ||
|
||
it('toggles password visibility', () => { | ||
const { getByPlaceholderText, getAllByRole } = render(<MemoryRouter><Signup /></MemoryRouter>); | ||
|
||
const passwordInput = getByPlaceholderText('session.password'); | ||
const confirmPasswordInput = getByPlaceholderText('session.confirm_password'); | ||
const showPasswordButtons = getAllByTestId(document.body, 'show-confirm-password-button'); | ||
|
||
fireEvent.click(showPasswordButtons[0]); | ||
fireEvent.click(showPasswordButtons[1]); | ||
|
||
expect(passwordInput.getAttribute('type')).toBe('text'); | ||
expect(confirmPasswordInput.getAttribute('type')).toBe('text'); | ||
}); | ||
|
||
it('submits form data correctly', async () => { | ||
const axiosMock = jest.spyOn(axios, 'post'); | ||
axiosMock.mockResolvedValueOnce({ status: 202 }); // Accepted status code | ||
|
||
// Render the Signup component | ||
const { getByPlaceholderText, getByText } = render(<MemoryRouter><Signup /></MemoryRouter>); | ||
|
||
// Get form elements and submit button by their text and placeholder values | ||
const emailInput = getByPlaceholderText('session.email'); | ||
const usernameInput = getByPlaceholderText('session.username'); | ||
const passwordInput = getByPlaceholderText('session.password'); | ||
const signUpButton = getByTestId(document.body, 'Sign up'); | ||
|
||
// Fill out the form with valid data and submit it | ||
fireEvent.change(emailInput, { target: { value: '[email protected]' } }); | ||
fireEvent.change(usernameInput, { target: { value: 'testuser' } }); | ||
fireEvent.change(passwordInput, { target: { value: 'password' } }); | ||
fireEvent.click(signUpButton); | ||
|
||
// Check if the form data was sent correctly | ||
await waitFor(() => { | ||
expect(axiosMock).toHaveBeenCalledWith(process.env.API_URL, { | ||
email: '[email protected]', | ||
username: 'testuser', | ||
password: 'password' | ||
}); | ||
expect(axiosMock).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
axiosMock.mockRestore(); | ||
}); | ||
}); |
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.
The tests seem to fail on this import. I'll approve when it is fixed.