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

Internationalization of WebApp Elements #270

Merged
merged 25 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
177ac40
Installed required packages
PabloGOP Apr 9, 2024
dd942e2
Created localization file
PabloGOP Apr 9, 2024
e643b01
added traduction files
PabloGOP Apr 9, 2024
f478196
Internacionalization applied and provided method to change language
PabloGOP Apr 9, 2024
4d36de0
Applied traduction to Footer so I see if changes in Select apply as e…
PabloGOP Apr 9, 2024
47419bf
Added reccomended configurations
PabloGOP Apr 9, 2024
aefa831
It was that easy... I fucking hate life
PabloGOP Apr 9, 2024
8dfa76b
Refactor: using dedicated dir for the whole functionality
PabloGOP Apr 9, 2024
9b4a578
Removed displayed total time (not the branch goal but...)
PabloGOP Apr 9, 2024
092d070
Format imports and solved warning
PabloGOP Apr 9, 2024
49f7e2b
Inernationalization applied to the game
PabloGOP Apr 9, 2024
921ae2d
Removed timer placed gitanally in the upper right corner and ruining …
PabloGOP Apr 9, 2024
5f18ae6
First try to intern Home & Homepage (last had to be rolled back due t…
PabloGOP Apr 9, 2024
f950b88
:)
PabloGOP Apr 9, 2024
f2131ea
Refactor register and implemented internationalization
PabloGOP Apr 9, 2024
a401ee3
Inter login
PabloGOP Apr 9, 2024
9c34651
Testing regarding internationalization
PabloGOP Apr 9, 2024
e84cd9f
Added unit testing for NavBar updated component including language ch…
PabloGOP Apr 9, 2024
250d2b4
Inter ranking provisional page (not test update necessary?)
PabloGOP Apr 9, 2024
f524acf
Inter groups and groups details + unit tests
PabloGOP Apr 10, 2024
c45ab78
Inter to Stats and its tests
PabloGOP Apr 10, 2024
71c4e28
Cities were required a diff element out of some ingenious staff (test…
PabloGOP Apr 10, 2024
6c50260
Inter for Groups of Erasmus will be able to spend a happy time playin…
PabloGOP Apr 10, 2024
08c600f
Forgot to add Spanish translation in multiplayer, Erasmus party was o…
PabloGOP Apr 10, 2024
3e0988d
PoC: Include french pretties in WIQ parties
PabloGOP Apr 10, 2024
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
63 changes: 62 additions & 1 deletion webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^14.5.2",
"axios": "^1.6.5",
"cross-env": "^7.0.3",
"babel": "^6.23.0",
"cross-env": "^7.0.3",
"express": "^4.19.2",
"i18next": "^23.11.0",
"react": "^18.2.0",
"react-confetti": "^6.1.0",
"react-countdown-circle-timer": "^3.2.1",
"react-dom": "^18.2.0",
"react-i18next": "^14.1.0",
"react-router-dom": "^6.22.1",
"react-scripts": "5.0.1",
"sequelize": "^6.37.2",
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import AddUser from './pages/AddUser';
import Register from './pages/Register';
import Instructions from './pages/Instructions';
import Login from './pages/Login';
import NavBar from './components/NavBar';
Expand Down Expand Up @@ -48,7 +48,7 @@ function App() {
<Routes>
<Route path="/" element={<Home />}/>
<Route path="/login" element={<Login />}/>
<Route path="/register" element={<AddUser />}/>
<Route path="/register" element={<Register />}/>
<Route path="/instructions" element={<Instructions />}/>
<Route path="/homepage" element={<Homepage />}/>
<Route path="/game" element={<Game />}/>
Expand Down
1 change: 1 addition & 0 deletions webapp/src/__tests__/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import App from '../App';
import { SessionContext } from '../SessionContext';
import '../localize/i18n';

describe('App component', () => {
it('renders home page by default', () => {
Expand Down
1 change: 1 addition & 0 deletions webapp/src/__tests__/components/Footer.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import Footer from '../../components/Footer.js';
import '../../localize/i18n.js';

describe('Footer component', () => {
beforeEach(() => {
Expand Down
32 changes: 32 additions & 0 deletions webapp/src/__tests__/components/NavBar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { render, screen, waitFor, fireEvent } from '@testing-library/react';
import { BrowserRouter } from 'react-router-dom';
import NavBar from '../../components/NavBar';
import { SessionContext } from '../../SessionContext';
import '../../localize/i18n';

describe('NavBar component', () => {
it('should render logo when not logged', async () => {
Expand Down Expand Up @@ -106,4 +107,35 @@ describe('NavBar component', () => {
fireEvent.click(logoutButton);
expect(window.location.pathname).toBe('/');
});

it('should render language options and change as expected', async () => {
render(
<SessionContext.Provider value={{ isLoggedIn: true }}>
<BrowserRouter>
<NavBar />
</BrowserRouter>
</SessionContext.Provider>
);

// Checks select menu is in the nav
const selectLang = screen.getByText("English");
await expect(selectLang).toBeInTheDocument();

// Click on it and check both options are there
// mouse down para elementos que no son botón: https://stackoverflow.com/questions/55184037/react-testing-library-on-change-for-material-ui-select-component
// "uhh, es buena esa"
fireEvent.mouseDown(selectLang);
const selectLangEn = screen.getAllByText("English")[1];
await expect(selectLangEn).toBeInTheDocument();
const selectLangEs = screen.getByText("Spanish");
await expect(selectLang).toBeInTheDocument();

// Click on spanish element
fireEvent.click(selectLangEs);

// Check lang has changed for the menu and the navigation
const playOptionEs = screen.getAllByText("Jugar");
await expect(playOptionEs[0]).toBeInTheDocument();
await expect(playOptionEs[1]).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion webapp/src/__tests__/pages/Game.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BrowserRouter as Router } from 'react-router-dom';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import Game from '../../pages/Game';
import '../../localize/i18n';

const mockAxios = new MockAdapter(axios);

Expand Down Expand Up @@ -50,7 +51,6 @@ describe('Game component', () => {
expect(screen.findByText('London'));

expect(screen.getByRole('button', { name: /Pause/i }));
expect(screen.getByText(/Game time:/i)).toBeInTheDocument();

});

Expand Down
1 change: 1 addition & 0 deletions webapp/src/__tests__/pages/GroupDetails.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BrowserRouter as Router, useParams } from 'react-router-dom';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import GroupDetails from '../../pages/GroupDetails';
import '../../localize/i18n';

const mockAxios = new MockAdapter(axios);

Expand Down
1 change: 1 addition & 0 deletions webapp/src/__tests__/pages/Groups.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BrowserRouter as Router } from 'react-router-dom';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import Groups from '../../pages/Groups';
import '../../localize/i18n';

const mockAxios = new MockAdapter(axios);

Expand Down
1 change: 1 addition & 0 deletions webapp/src/__tests__/pages/Home.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Home from '../../pages/Home';
import { BrowserRouter } from 'react-router-dom';
import { SessionContext } from '../../SessionContext';
import userEvent from '@testing-library/user-event';
import '../../localize/i18n';

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

Expand Down
7 changes: 4 additions & 3 deletions webapp/src/__tests__/pages/Login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BrowserRouter as Router } from 'react-router-dom';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import Login from '../../pages/Login';
import '../../localize/i18n';

const mockAxios = new MockAdapter(axios);

Expand All @@ -26,7 +27,7 @@ describe('Login component', () => {

expect(screen.getByLabelText('Username')).toBeInTheDocument();
expect(screen.getByLabelText('Password')).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Log In' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Log in' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Don\'t have an account? Register here.' })).toBeInTheDocument();
});

Expand All @@ -42,7 +43,7 @@ describe('Login component', () => {
fireEvent.change(screen.getByLabelText('Username'), { target: { value: 'testuser' } });
fireEvent.change(screen.getByLabelText('Password'), { target: { value: 'testpassword' } });

fireEvent.click(screen.getByRole('button', { name: 'Log In' }));
fireEvent.click(screen.getByRole('button', { name: 'Log in' }));

await waitFor(() => {
expect(mockAxios.history.post.length).toBe(1); // Ensure one POST request is made
Expand All @@ -63,7 +64,7 @@ describe('Login component', () => {
fireEvent.change(screen.getByLabelText('Username'), { target: { value: ' ' } });
fireEvent.change(screen.getByLabelText('Password'), { target: { value: 'testpassword' } });

fireEvent.click(screen.getByRole('button', { name: 'Log In' }));
fireEvent.click(screen.getByRole('button', { name: 'Log in' }));

await waitFor(() => {
expect(screen.getByText('Error: The username cannot contain only spaces')).toBeInTheDocument();
Expand Down
1 change: 1 addition & 0 deletions webapp/src/__tests__/pages/MultiplayerGame.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SessionContext } from '../../SessionContext';
import { BrowserRouter, useLocation } from 'react-router-dom';
import MultiplayerGame from '../../pages/MultiplayerGame';
import io from 'socket.io-client';
import '../../localize/i18n';

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
Expand Down
1 change: 1 addition & 0 deletions webapp/src/__tests__/pages/MultiplayerRoom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import MultiplayerRoom from '../../pages/MultiplayerRoom';
import io from 'socket.io-client';
import { SessionContext } from '../../SessionContext';
import { BrowserRouter as Router } from 'react-router-dom';
import '../../localize/i18n';

//mock some socket behaviour
jest.mock('socket.io-client', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { SessionContext } from '../../SessionContext';
import { BrowserRouter as Router } from 'react-router-dom';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import AddUser from '../../pages/AddUser';
import Register from '../../pages/Register';
import '../../localize/i18n';

const mockAxios = new MockAdapter(axios);

describe('AddUser component', () => {
describe('Register component', () => {
beforeEach(() => {
mockAxios.reset();
// Mock the axios.post request to simulate a successful response
Expand All @@ -20,7 +21,7 @@ describe('AddUser component', () => {
render(
<SessionContext.Provider value={{}}>
<Router>
<AddUser />
<Register />
</Router>
</SessionContext.Provider>
);
Expand All @@ -29,15 +30,15 @@ describe('AddUser component', () => {
expect(screen.getByLabelText('Password')).toBeInTheDocument();
expect(screen.getByLabelText('Name')).toBeInTheDocument();
expect(screen.getByLabelText('Surname')).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Sign Up' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Sign up' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Already have an account? Login here.' })).toBeInTheDocument();
});

it('should sign up a user', async () => {
render(
<SessionContext.Provider value={{ createSession: jest.fn() }}>
<Router>
<AddUser />
<Register />
</Router>
</SessionContext.Provider>
);
Expand All @@ -47,7 +48,7 @@ describe('AddUser component', () => {
fireEvent.change(screen.getByLabelText('Name'), { target: { value: 'John' } });
fireEvent.change(screen.getByLabelText('Surname'), { target: { value: 'Doe' } });

fireEvent.click(screen.getByRole('button', { name: 'Sign Up' }));
fireEvent.click(screen.getByRole('button', { name: 'Sign up' }));

await waitFor(() => {
expect(mockAxios.history.post.length).toBe(2); // Ensure two POST requests are made
Expand All @@ -60,12 +61,12 @@ describe('AddUser component', () => {
render(
<SessionContext.Provider value={{}}>
<Router>
<AddUser />
<Register />
</Router>
</SessionContext.Provider>
);

fireEvent.click(screen.getByRole('button', { name: 'Sign Up' }));
fireEvent.click(screen.getByRole('button', { name: 'Sign up' }));

await waitFor(() => {
expect(screen.getByText('Error: Username already exists')).toBeInTheDocument();
Expand Down
1 change: 1 addition & 0 deletions webapp/src/__tests__/pages/Statistics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SessionContext } from '../../SessionContext';
import { BrowserRouter as Router } from 'react-router-dom';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import '../../localize/i18n';

const mockAxios = new MockAdapter(axios);

Expand Down
11 changes: 9 additions & 2 deletions webapp/src/components/Footer.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import * as React from 'react';
import { AppBar, Toolbar, Typography, Link } from '@mui/material';
import { useTranslation } from 'react-i18next';

const Footer = () => {
const { t } = useTranslation();

return (
<AppBar component="footer" position="static" sx={{ backgroundColor: "primary", color: "white", bottom: 0, left: 0, width: '100%', zIndex: 1000}}>
<Toolbar>
<Typography sx={{ margin: 'auto' }}>
<Link href='https://app.swaggerhub.com/apis-docs/UO288347_1/questions-api/1.0.0' target="_blank" color="inherit">QUESTIONS API DOC</Link>
<Link href='https://app.swaggerhub.com/apis-docs/UO288347_1/questions-api/1.0.0' target="_blank" color="inherit">
{t("Footer.api_questions")}
</Link>
</Typography>
<Typography sx={{ margin: 'auto' }}>
<Link href="https://github.com/Arquisoft/wiq_es04a" target="_blank" rel="noopener" color="inherit">© WIQ-ES04A</Link>
</Typography>
<Typography sx={{ margin: 'auto' }}>
<Link href='https://app.swaggerhub.com/apis-docs/UO289689_1/users-api/1.0.0' target="_blank" color="inherit">USERS API DOC</Link>
<Link href='https://app.swaggerhub.com/apis-docs/UO289689_1/users-api/1.0.0' target="_blank" color="inherit">
{t("Footer.api_users")}
</Link>
</Typography>
</Toolbar>
</AppBar>
Expand Down
Loading