generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/Arquisoft/wiq_es05a into…
… develop
- Loading branch information
Showing
12 changed files
with
149 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ defineFeature(feature, test => { | |
|
||
given('An unregistered user', async () => { | ||
username = "[email protected]" | ||
password = "pabloasw" | ||
password = "pabloasw1" | ||
await expect(page).toClick("button", { text: "REGÍSTRATE" }); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ defineFeature(feature, test => { | |
|
||
given('A user that is logged in the application', async () => { | ||
username = "[email protected]" | ||
password = "pabloasw" | ||
password = "pabloasw1" | ||
await expect(page).toClick("button", { text: "INICIA SESIÓN" }); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ defineFeature(feature, test => { | |
|
||
given('A user that is logged in the application', async () => { | ||
username = "[email protected]" | ||
password = "pabloasw" | ||
password = "pabloasw1" | ||
await expect(page).toClick("button", { text: "INICIA SESIÓN" }); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import App from './App'; | ||
|
||
/*test('renders learn react link', () => { | ||
render(<App />); | ||
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( | ||
<MemoryRouter> | ||
<App /> | ||
</MemoryRouter> | ||
); | ||
|
||
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( | ||
<MemoryRouter> | ||
<App /> | ||
</MemoryRouter> | ||
); | ||
|
||
expect(screen.getByText(/Home/i)).toBeInTheDocument(); | ||
}); | ||
|
||
it('redirects to login when trying to access stats page without logging in', () => { | ||
render( | ||
<MemoryRouter initialEntries={['/stats']}> | ||
<App /> | ||
</MemoryRouter> | ||
); | ||
|
||
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( | ||
<MemoryRouter initialEntries={['/stats']}> | ||
<App /> | ||
</MemoryRouter> | ||
); | ||
|
||
expect(screen.getByText(/Estadisticas/i)).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import Temporizador from './Temporizador'; | ||
|
||
describe('Temporizador', () => { | ||
it('renders the initial countdown time', () => { | ||
const tiempoInicial = 60; | ||
render(<Temporizador tiempoInicial={tiempoInicial} />); | ||
const countdownElement = screen.getByText(tiempoInicial); | ||
expect(countdownElement).toBeInTheDocument(); | ||
}); | ||
|
||
it('decreases countdown time when not paused', () => { | ||
jest.useFakeTimers(); | ||
const tiempoInicial = 60; | ||
render(<Temporizador tiempoInicial={tiempoInicial} />); | ||
jest.advanceTimersByTime(1000); | ||
const updatedCountdownElement = screen.getByText(tiempoInicial - 1); | ||
expect(updatedCountdownElement).toBeInTheDocument(); | ||
jest.useRealTimers(); | ||
}); | ||
|
||
it('stops countdown time when paused', () => { | ||
jest.useFakeTimers(); | ||
const tiempoInicial = 60; | ||
render(<Temporizador tiempoInicial={tiempoInicial} pausa={true} />); | ||
jest.advanceTimersByTime(1000); | ||
const updatedCountdownElement = screen.getByText(tiempoInicial); | ||
expect(updatedCountdownElement).toBeInTheDocument(); | ||
jest.useRealTimers(); | ||
}); | ||
|
||
it('restarts countdown time when restart prop changes', () => { | ||
jest.useFakeTimers(); | ||
const tiempoInicial = 60; | ||
const { rerender } = render(<Temporizador tiempoInicial={tiempoInicial} />); | ||
jest.advanceTimersByTime(1000); | ||
const updatedCountdownElement = screen.getByText(tiempoInicial - 1); | ||
expect(updatedCountdownElement).toBeInTheDocument(); | ||
|
||
// Simulate restart by changing the restart prop | ||
rerender(<Temporizador tiempoInicial={tiempoInicial} restart={true} />); | ||
|
||
// Countdown should restart | ||
const restartedCountdownElement = screen.getByText(tiempoInicial); | ||
expect(restartedCountdownElement).toBeInTheDocument(); | ||
jest.useRealTimers(); | ||
}); | ||
}); |