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

added rankings test and removed duplicated code #108

Merged
merged 1 commit into from
Apr 8, 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
34 changes: 5 additions & 29 deletions users/userservice/user-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,43 +97,19 @@ describe('User Service', () => {
expect(response.body);
});

it("should show users' ranking for global stats", async () => {
it("should show users' ranking for <category> stats", async () => {
const response = await request(app).get('/rankings/global');
expect(response.status).toBe(200);
expect(response.body);
});

it("should show users' ranking for foods category", async () => {
const response = await request(app).get('/rankings/foods');
expect(response.status).toBe(200);
expect(response.body);
});

it("should show users' ranking for attractions category", async () => {
const response = await request(app).get('/rankings/tourist_attractions');
expect(response.status).toBe(200);
expect(response.body);
});

it("should show users' ranking for monuments category", async () => {
const response = await request(app).get('/rankings/monuments');
expect(response.status).toBe(200);
expect(response.body);
});

it("should show users' ranking for cities category", async () => {
const response = await request(app).get('/rankings/cities');
expect(response.status).toBe(200);
expect(response.body);
});

it("shouldn't show users' ranking for a category that doesn't exist" , async () => {
const response = await request(app).get('/rankings/reyesmagos');
expect(response.status).toBe(400);
const res = await request(app).get('/rankings/reyesmagos');
expect(res.status).toBe(400);
});

it("shouldn't show users' ranking for an empty category" , async () => {
const response = await request(app).get('/rankings/');
expect(response.status).toBe(404);
const res = await request(app).get('/rankings/');
expect(res.status).toBe(404);
});
});
29 changes: 29 additions & 0 deletions webapp/src/components/ranking/Ranking.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import RankingLayout from './RankingLayout';
import { useState } from 'react';
import { jest } from '@jest/globals';

describe('Ranking page', () => {
it ('should render the global ranking when entering Rankings page', async () => {
render(<RankingLayout />);
const category = screen.getAllByText(/global/i);
expect(category.length).toBe(2);
});

it ('should render the <category> ranking when changed the useState', async () => {
const categoryMock = 'global';
const setCategoryMock = jest.fn();

React.useState = jest.fn().mockReturnValue([categoryMock, setCategoryMock])

render(<RankingLayout />);

setCategoryMock.mockImplementation(newValue => newValue('cities'));
const citiesButton = screen.getByRole('button', { name: /Cities/i });
fireEvent.click(citiesButton);

const category = screen.getAllByText(/cities/i);
expect(category.length).toBe(2);
})
})
2 changes: 1 addition & 1 deletion webapp/src/components/ranking/RankingTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const RankingsTable = ({ filter }) => {
}, [filter]);

return (
<div className="flex flex-col">
<div data-testid='ranking-table' className="flex flex-col">
<div className="overflow-x-auto sm:mx-6 lg:mx-8">
<div className="py-2 inline-block min-w-full sm:px-6 lg:px-8">
<div className="overflow-hidden">
Expand Down