Skip to content
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: Adding the home page and tests for it #84

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion webapp/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"username": "Username",
"password": "Password",
"email": "Email",
"confirm_password": "Confirm password"
"confirm_password": "Confirm password",
"welcome": "Welcome to the WIQ-EN2B page",
"account": "Don't have an account?"
},
"error": {
"login": "An ERROR occurred during login"
Expand Down
4 changes: 3 additions & 1 deletion webapp/public/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"username": "Nombre de usuario",
"password": "Contraseña",
"email": "Correo electrónico",
"confirm_password": "Confirmar contraseña"
"confirm_password": "Confirmar contraseña",
"welcome": "Bienvenido a la página principal de WIQ-EN2B",
"account": "¿No tienes una cuenta?"
},
"error": {
"login": "Ocurrió un ERROR en el login"
Expand Down
20 changes: 19 additions & 1 deletion webapp/src/pages/Root.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
import { Center } from "@chakra-ui/layout";
import { Heading, Stack } from "@chakra-ui/react";
import React from "react";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import ButtonEf from '../components/ButtonEf';

export default function Root() {
return <p>Proof of concept</p>
const navigate = useNavigate();
const { t } = useTranslation();

return (
<Center display={"flex"} flexDirection={"column"} w={"100wh"} h={"100vh"}
bg={"blue.50"} justifyContent={"center"} alignItems={"center"}>
<Heading as="h1" color="blue.400">{"WIQ-EN2B"}</Heading>
<p>{t("session.welcome")}</p>
<Stack spacing={4} p="3rem">
<ButtonEf dataTestId={"Login"} variant={"solid"} colorScheme={"blue"} text={t("common.login")} onClick={() => navigate("/login")}/>
<p onClick={() => navigate("/signup")} style={{ cursor: 'pointer' }}>{t("session.account")}</p>
</Stack>
</Center>
);
}
14 changes: 5 additions & 9 deletions webapp/src/pages/Signup.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Center } from "@chakra-ui/layout";
import { Heading, Input, Button, InputGroup, Stack, InputLeftElement, chakra, Box, Avatar, FormControl, InputRightElement, Text, FormHelperText } from "@chakra-ui/react";
import { Heading, Input, Button, InputGroup, Stack, InputLeftElement, chakra, Box, Avatar, FormControl, InputRightElement, Text, FormHelperText, IconButton } from "@chakra-ui/react";
import { ViewIcon, ViewOffIcon } from '@chakra-ui/icons'
import axios, { HttpStatusCode } from "axios";
import React, { useState } from "react";
Expand Down Expand Up @@ -104,10 +104,8 @@ export default function Signup() {
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>
<IconButton aria-label='Shows or hides the password' data-testid="show-confirm-password-button" h="1.75rem" size="sm" onClick={() => setShowPassword(!showPassword)} icon={showPassword ? <ViewOffIcon/> : <ViewIcon/>}/>
</InputRightElement>
</InputGroup>
</FormControl>
Expand All @@ -120,10 +118,8 @@ export default function Signup() {
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>
<IconButton aria-label='Shows or hides the password' data-testid="show-confirm-password-button" h="1.75rem" size="sm" onClick={() => setShowConfirmPassword(!showConfirmPassword)} icon={showConfirmPassword ? <ViewOffIcon/> : <ViewIcon/>}/>
</InputRightElement>
</InputGroup>
{confirmPassword && password && confirmPassword !== password && (
Expand Down
36 changes: 36 additions & 0 deletions webapp/src/tests/Root.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import { render, screen, fireEvent, getByTestId } from '@testing-library/react';
import { MemoryRouter, createMemoryRouter } from 'react-router';
import Root from '../pages/Root';

describe('Root component', () => {

it('renders WIQ-EN2B heading', () => {
render(<MemoryRouter><Root /></MemoryRouter>);
const headingElement = screen.getByText('WIQ-EN2B');
expect(headingElement).toBeInTheDocument();
});

it('renders welcome message', () => {
render(<MemoryRouter><Root /></MemoryRouter>);
const welcomeMessage = screen.getByText('session.welcome');
expect(welcomeMessage).toBeInTheDocument();
});

it('renders Log In button', () => {
render(<MemoryRouter><Root /></MemoryRouter>);
expect(getByTestId(document.body, 'Login')).toBeInTheDocument();
});

it('navigates to /login when Log In button is clicked', () => {
const { container } = render(<MemoryRouter><Root /></MemoryRouter>);
fireEvent.click(getByTestId(document.body, 'Login'));
expect(container.innerHTML).toMatch('<div class=\"css-xmmg5m\"><h1 class=\"chakra-heading css-p03q1r\">WIQ-EN2B</h1><p>session.welcome</p><div class=\"chakra-stack css-gjlptk\"><button type=\"submit\" class=\"chakra-button custom-button effect1 css-1vdwnhw\" data-testid=\"Login\">common.login</button><p style=\"cursor: pointer;\">session.account</p></div></div>');
});

it('navigates to /signup when "You don\'t have an account?" message is clicked', () => {
const { container } = render(<MemoryRouter><Root /></MemoryRouter>);
fireEvent.click(screen.getByText('session.account'));
expect(container.innerHTML).toMatch('<div class=\"css-xmmg5m\"><h1 class=\"chakra-heading css-p03q1r\">WIQ-EN2B</h1><p>session.welcome</p><div class=\"chakra-stack css-gjlptk\"><button type=\"submit\" class=\"chakra-button custom-button effect1 css-1vdwnhw\" data-testid=\"Login\">common.login</button><p style=\"cursor: pointer;\">session.account</p></div></div>');
});
});