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

Tests de las vistas de stats, ranking y perfil para calculadora #91

Merged
merged 2 commits into from
Apr 5, 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
1 change: 1 addition & 0 deletions webapp/package-lock.json

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

28 changes: 28 additions & 0 deletions webapp/src/pages/Perfil/Perfil.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,34 @@ describe('Perfil Component', () => {
expect(screen.getByText('No hay partidas recientes.')).toBeInTheDocument();
});
});

test('displays recent calculator game data', async () => {
const mockUserData = {
username: 'testUser',
createdAt: new Date(),
games: [
{ gamemode: 'calculadora', points: 15, avgTime: 8.5 }
]
};

jest.spyOn(global, 'fetch').mockResolvedValueOnce({
json: jest.fn().mockResolvedValueOnce(mockUserData),
});

render(
<MemoryRouter>
<Perfil />
</MemoryRouter>
);

await waitFor(() => {
expect(screen.getByText('calculadora')).toBeInTheDocument();
const dashCells = screen.getAllByText('-');
expect(dashCells.length).toBe(2);
expect(screen.getByText('15')).toBeInTheDocument();
expect(screen.getByText('8.50 segundos')).toBeInTheDocument();
});
});


});
16 changes: 16 additions & 0 deletions webapp/src/pages/Ranking/Ranking.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,21 @@ describe('Ranking component', () => {
expect(screen.getByText('Ranking - modo Batería de sabios')).toBeInTheDocument();
});
});

test('changes gamemode when clicking on mode buttons, clicks on Human Calculator button', async () => {
global.fetch.mockResolvedValueOnce({ json: () => Promise.resolve(mockData) });

renderComponent();

await assertRankingTableWithData();

const calculatorButton = screen.getByRole('button', { name: 'Calculadora humana' });
fireEvent.click(calculatorButton);

await waitFor(() => {
expect(screen.getByText('Ranking - modo Calculadora humana')).toBeInTheDocument();
expect(screen.queryByText('Ratio de aciertos (%)')).toBeNull(); // Asegura que no se muestra la opción de filtrar por ratio de aciertos
});
});
});

43 changes: 43 additions & 0 deletions webapp/src/pages/Stats/Stats.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,47 @@ describe('Stats component', () => {
expect(screen.queryByText('Estadísticas de testUser - modo Batería de sabios')).toBeInTheDocument();
});
});

test('fetches and displays user statistics for Human Calculator mode', async () => {
localStorage.setItem('username', 'testUser');

userData.ratioCorrect=0;
userData.totalCorrectQuestions=0;
userData.totalIncorrectQuestions=0;

global.fetch = jest.fn().mockResolvedValue({
json: jest.fn().mockResolvedValue(userData)
});

renderComponentWithRouter();

await waitFor(() => {
expect(screen.queryByText('Cargando ...')).not.toBeInTheDocument();
});

const modeButton = screen.getByRole('button', { name: /Calculadora humana/i });
userEvent.click(modeButton);

const table = await screen.findByRole('table');
expect(table).toBeInTheDocument();

const columnHeaders = ['Partidas jugadas', 'Puntos por partida', 'Puntos totales', 'Tiempo por pregunta (s):'];
columnHeaders.forEach(headerText => {
const headerElement = screen.getByText(headerText);
expect(headerElement).toBeInTheDocument();
});

Object.entries(userData).forEach(([key, value]) => {
if (key !== 'username') {
if (key === 'avgPoints' || key === 'avgTime') {
const valueElements = screen.getAllByText(value.toFixed(2));
expect(valueElements.length).toBeGreaterThan(0);
} else {
const valueElements = screen.getAllByText(value.toString());
expect(valueElements.length).toBeGreaterThan(0);
}
}
});
});

});
Loading