diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cccab54..207909d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,6 +6,7 @@ on: - develop - LaraFMz - Pablo-Arreglos + - Jota pull_request: types: [opened, synchronize, reopened] jobs: diff --git a/docs/images/07_DiagramaDespliegue3.png b/docs/images/07_DiagramaDespliegue3.png new file mode 100644 index 0000000..6eae1bc Binary files /dev/null and b/docs/images/07_DiagramaDespliegue3.png differ diff --git a/webapp/Dockerfile b/webapp/Dockerfile index 0d1b158..466e82a 100644 --- a/webapp/Dockerfile +++ b/webapp/Dockerfile @@ -15,4 +15,4 @@ RUN npm install serve #Execute npm run prod to run the server CMD [ "npm", "run", "prod" ] -#CMD ["npm", "start"] \ No newline at end of file +#CMD ["npm", "start"] diff --git a/webapp/src/App.test.js b/webapp/src/App.test.js new file mode 100644 index 0000000..0c8f791 --- /dev/null +++ b/webapp/src/App.test.js @@ -0,0 +1,68 @@ +import { render, screen } from '@testing-library/react'; +import App from './App'; + +/*test('renders learn react link', () => { + render(); + const linkElement = screen.getByText(/Welcome to the 2024 edition of the Software Architecture course/i); + expect(linkElement).toBeInTheDocument(); +}); +*/ + +describe('App', () => { + + it('renders login page when not logged in', () => { + render( + + + + ); + + expect(screen.getByText(/Login/i)).toBeInTheDocument(); + }); + + it('renders home page when logged in', () => { + // Mock local storage to simulate being logged in + const mockLocalStorage = { + getItem: jest.fn(() => 'true'), + setItem: jest.fn(), + clear: jest.fn() + }; + global.localStorage = mockLocalStorage; + + render( + + + + ); + + expect(screen.getByText(/Home/i)).toBeInTheDocument(); + }); + + it('redirects to login when trying to access stats page without logging in', () => { + render( + + + + ); + + expect(screen.getByText(/Login/i)).toBeInTheDocument(); + }); + + it('renders stats page when logged in and trying to access stats page', () => { + // Mock local storage to simulate being logged in + const mockLocalStorage = { + getItem: jest.fn(() => 'true'), + setItem: jest.fn(), + clear: jest.fn() + }; + global.localStorage = mockLocalStorage; + + render( + + + + ); + + expect(screen.getByText(/Estadisticas/i)).toBeInTheDocument(); + }); +}); \ No newline at end of file diff --git a/webapp/src/components/Pages/Juego.js b/webapp/src/components/Pages/Juego.js index ca0dd6a..a7416f4 100644 --- a/webapp/src/components/Pages/Juego.js +++ b/webapp/src/components/Pages/Juego.js @@ -29,7 +29,7 @@ const Juego = ({isLogged, username, numPreguntas}) => { const [numRespuestasIncorrectas, setNumRespuestasIncorrectas] = useState(0) const [disableFinish, setDisableFinish] = useState(false) - //const navigate= useNavigate() + const navigate= useNavigate() //Variables para la obtencion y modificacion de estadisticas del usuario y de preguntas const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; @@ -201,7 +201,7 @@ const Juego = ({isLogged, username, numPreguntas}) => { const clickFinalizar = () => { updateStats(); setDisableFinish(true) - //navigate('/') + navigate('/') } const handleRestart = () => { diff --git a/webapp/src/components/Pages/Layout.js b/webapp/src/components/Pages/Layout.js index d49490d..389cb5d 100644 --- a/webapp/src/components/Pages/Layout.js +++ b/webapp/src/components/Pages/Layout.js @@ -3,6 +3,8 @@ import React from 'react'; import {Container, Nav, Navbar} from 'react-bootstrap'; import PropTypes from 'prop-types' +const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; + const Layout = ({ isLogged, setIsLogged }) => { function onLogout(){ @@ -22,8 +24,12 @@ import PropTypes from 'prop-types' Estadísticas } +