Skip to content

Commit

Permalink
feat: fixing the tests due to internationalizing the login.
Browse files Browse the repository at this point in the history
  • Loading branch information
gony02 committed Mar 3, 2024
1 parent e433266 commit b3ab87c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions webapp/src/components/ButtonEf.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react';
import { Button } from "@chakra-ui/react";
import '../styles/AppView.css';

const ButtonEf = ({ variant, colorScheme, text, onClick }) => {
const ButtonEf = ({ dataTestId, variant, colorScheme, text, onClick }) => {
return (
<Button type="submit" variant={variant} colorScheme={colorScheme} margin={"10px"} className={"custom-button effect1"} onClick={onClick}>{text}</Button>
<Button type="submit" data-testid={dataTestId} variant={variant} colorScheme={colorScheme} margin={"10px"} className={"custom-button effect1"} onClick={onClick}>{text}</Button>
);
};
export default ButtonEf;
4 changes: 2 additions & 2 deletions webapp/src/pages/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ export default function Login() {
<InputLeftElement children={<ChakraFaLock color="gray.300" />}/>
<Input type={showPassword ? "text" : "password"} placeholder={t("session.password")}/>
<InputRightElement>
<IconButton h="1.75rem" size="sm" onClick={changeShowP} aria-label='Shows or hides the password' icon={showPassword ? <ViewOffIcon/> : <ViewIcon/>}/>
<IconButton h="1.75rem" size="sm" onClick={changeShowP} aria-label='Shows or hides the password' icon={showPassword ? <ViewOffIcon/> : <ViewIcon/>} data-testid="togglePasswordButton"/>
</InputRightElement>
</InputGroup>
</FormControl>
<ButtonEf variant={"solid"} colorScheme={"blue"} text="Login" onClick={sendLogin}/>
<ButtonEf dataTestId={"Login"} variant={"solid"} colorScheme={"blue"} text={t("common.login")} onClick={sendLogin}/>
</Stack>
</Box>
</Stack>
Expand Down
10 changes: 5 additions & 5 deletions webapp/src/tests/Login.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, fireEvent, screen, waitFor, act } from '@testing-library/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';
Expand All @@ -19,15 +19,15 @@ describe('Login component', () => {

expect(getByPlaceholderText('session.email')).toBeInTheDocument();
expect(getByPlaceholderText('session.password')).toBeInTheDocument();
expect(getByText('Login')).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 = getByText('Show');
const showPasswordButton = getByTestId(document.body, 'togglePasswordButton');

fireEvent.click(showPasswordButton);

expect(passwordInput.getAttribute('type')).toBe('text');
Expand All @@ -43,7 +43,7 @@ describe('Login component', () => {
// Get form elements and submit button by their text and placeholder values
const emailInput = getByPlaceholderText('session.email');
const passwordInput = getByPlaceholderText('session.password');
const signUpButton = getByText('Login');
const signUpButton = getByTestId(document.body, 'Login');

// Fill out the form with valid data and submit it
fireEvent.change(emailInput, { target: { value: '[email protected]' } });
Expand Down

0 comments on commit b3ab87c

Please sign in to comment.