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

Integrating Backgrounds and their Testing #334

Merged
merged 2 commits into from
Apr 28, 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
21 changes: 19 additions & 2 deletions webapp/src/__tests__/pages/GroupDetails.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import { render, waitFor } from '@testing-library/react';
import { render, waitFor, screen } from '@testing-library/react';
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';
import { SessionContext } from '../../SessionContext';

const mockAxios = new MockAdapter(axios);

jest.mock('react-router-dom', () => ({
Expand Down Expand Up @@ -51,6 +51,23 @@ describe('GroupDetails component', () => {
});
});

it('debe reproducir el video a una velocidad de 0.85', async () => {
render(
<SessionContext.Provider value={{ username: 'TestCreator' }}>
<Router>
<GroupDetails />
</Router>
</SessionContext.Provider>
);

await waitFor(() => {
const videoElement = screen.getByTestId('video');
expect(videoElement).toBeInTheDocument();
expect(videoElement.playbackRate).toBe(0.85);
});

});

it('should render error message when failed to fetch group information', async () => {

mockAxios.onGet(`http://localhost:8000/group/NonExistentGroup`).reply(404);
Expand Down
8 changes: 8 additions & 0 deletions webapp/src/__tests__/pages/Groups.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ describe('Groups component', () => {
});
};

it('debe reproducir el video a una velocidad de 0.85', async () => {
renderGroupsComponent();
const videoElement = screen.getByTestId('video');
expect(videoElement).toBeInTheDocument();
expect(videoElement.playbackRate).toBe(0.85);

});

it('should render groups list and creation elements', async () => {
// It mocks a succesful request getting two groups from the database.
mockAxios.onGet('http://localhost:8000/group').reply(200, { groups: [{ name: 'Group 1' }, { name: 'Group 2' }] });
Expand Down
11 changes: 11 additions & 0 deletions webapp/src/__tests__/pages/Ranking.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ describe('Ranking Component', () => {

});

it('debe reproducir el video a una velocidad de 0.85', async () => {
render(<Ranking />);

setTimeout(() => {
const videoElement = screen.getByTestId('video');
expect(videoElement).toBeInTheDocument();
expect(videoElement.playbackRate).toBe(0.85);
}, 15);

});

it('should display group ranking when "GROUPS" button is clicked', async () => {
const groupRanking = {
data: { rank: [
Expand Down
14 changes: 14 additions & 0 deletions webapp/src/__tests__/pages/Statistics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ describe('Statistics component', () => {
expect(screen.getByText('2')).toBeInTheDocument();
});

it('debe reproducir el video a una velocidad de 0.85', async () => {
render(
<SessionContext.Provider value={{ username: 'testuser' }}>
<Router>
<Statistics />
</Router>
</SessionContext.Provider>
);
const videoElement = screen.getByTestId('video');
expect(videoElement).toBeInTheDocument();
expect(videoElement.playbackRate).toBe(0.85);

});

it('should render Statistics component with correct user statistics for Wise Men Stack mode', async () => {
render(
<SessionContext.Provider value={{ username: 'testuser' }}>
Expand Down
1 change: 1 addition & 0 deletions webapp/src/index.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
body {
background-image: url('../public/hurta2.jpg');
background-size: cover;
background-repeat: no-repeat;
margin: 0;
Expand Down
25 changes: 25 additions & 0 deletions webapp/src/pages/GroupDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,31 @@ const GroupDetails = () => {
navigate(`/statistics/${name}`);
};

//Video settings
const styles = {
video: {
position: "absolute",
top: "50%",
left: "50%",
width: "100%",
height: "100%",
transform: "translate(-50%, -50%)",
objectFit: "cover",
zIndex: '-1',
userSelect: 'none',
pointerEvents: 'none'
},
};

const videoRef = React.useRef(null);
React.useEffect(() => {if (videoRef.current) {videoRef.current.playbackRate = 0.85;}}, []);

if (error || !groupInfo) {
return (
<Container sx={{ margin: '0 auto auto' }}>
<video data-testid="video" ref={videoRef} autoPlay muted loop style={{ ...styles.video}}>
<source src="../home/Background-White.webm" type="video/mp4" />
</video>
<Typography variant="h5" sx={{ textAlign:'center' }}>{error}</Typography>
</Container>
)
Expand All @@ -50,6 +72,9 @@ const GroupDetails = () => {
// Returns all group data including the creator, the creation date and the members list
return (
<Container sx={{ margin: '0 auto auto' }}>
<video data-testid="video" ref={videoRef} autoPlay muted loop style={{ ...styles.video}}>
<source src="../home/Background-White.webm" type="video/mp4" />
</video>
<Typography variant="h2" align="center" fontWeight="bold" sx={{ textShadow: '2px 2px 4px rgba(0, 0, 0, 0.5)', fontSize:'3rem' }}>
<b>{groupInfo.name}</b>
</Typography>
Expand Down
22 changes: 22 additions & 0 deletions webapp/src/pages/Groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,30 @@ const Groups = () => {
navigate(`/group/${groupName}`);
};

//Video settings
const styles = {
video: {
position: "absolute",
top: "50%",
left: "50%",
width: "100%",
height: "100%",
transform: "translate(-50%, -50%)",
objectFit: "cover",
zIndex: '-1',
userSelect: 'none',
pointerEvents: 'none'
},
};
const videoRef = React.useRef(null);
React.useEffect(() => {if (videoRef.current) {videoRef.current.playbackRate = 0.85;}}, []);

return (
<Container sx={{ margin: '0 auto auto', display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
<video data-testid="video" ref={videoRef} autoPlay muted loop style={{ ...styles.video}}>
<source src="../home/Background-White.webm" type="video/mp4" />
</video>

<Typography variant="h2" align="center" fontWeight="bold" sx={{ width: '100%', textShadow: '2px 2px 4px rgba(0, 0, 0, 0.5)', fontSize:'3rem' }}>
{ t("Groups.title") }
</Typography>
Expand Down
2 changes: 0 additions & 2 deletions webapp/src/pages/Instructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ const Instructions = () => {
pointerEvents: 'none',
top:'0',
left:'0',
opacity:'0.5',

},

gameDisplayRow:{
Expand Down
19 changes: 19 additions & 0 deletions webapp/src/pages/Ranking.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ const Ranking = () => {
{ field: 'totalGamesPlayed', headerName: 'TOTAL GAMES', flex: 1, align: 'center', headerAlign: 'center' }
];

//Video settings
const styles = {
video:{
position: "absolute",
width: "100%",
height: "100%",
objectFit: "cover",
zIndex:'-1',
userSelect:'none',
pointerEvents: 'none'
},
};
const videoRef = React.useRef(null);
React.useEffect(() => {if (videoRef.current) {videoRef.current.playbackRate = 0.85;}}, []);

return (
<Container sx={{
display: "flex",
Expand All @@ -58,6 +73,10 @@ const Ranking = () => {
flexGrow: 1
}}>

< video data-testid="video" ref={videoRef} autoPlay muted loop style={{ ...styles.video}}>
<source src="../home/Background-White.webm" type="video/mp4" />
</video>

<Container style={{ display: 'flex', flexDirection: 'column' }}>
<Typography variant="h2" align="center" fontWeight="bold" sx={{ textShadow: '2px 2px 4px rgba(0, 0, 0, 0.5)', fontSize:'3rem' }}>
RANKING
Expand Down
22 changes: 22 additions & 0 deletions webapp/src/pages/Statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,30 @@ const Statistics = () => {
}
};

//Video settings
const styles = {
video: {
position: "absolute",
top: "50%",
left: "50%",
width: "100%",
height: "100%",
transform: "translate(-50%, -50%)",
objectFit: "cover",
zIndex: '-1',
userSelect: 'none',
pointerEvents: 'none'
},
};

const videoRef = React.useRef(null);
React.useEffect(() => {if (videoRef.current) {videoRef.current.playbackRate = 0.85;}}, []);

return (
<Container sx={{ margin: '0 auto auto', display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
<video data-testid="video" ref={videoRef} autoPlay muted loop style={{ ...styles.video}}>
<source src="../home/Background-White.webm" type="video/mp4" />
</video>
<Typography variant="h2" align="center" fontWeight="bold" gutterBottom sx={{ textShadow: '2px 2px 4px rgba(0, 0, 0, 0.5)', fontSize:'3rem' }}>
{ t("Statistics.title") }
</Typography>
Expand Down