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

Fix the warning when running the localization tests #127

Merged
merged 1 commit into from
Mar 21, 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
11 changes: 11 additions & 0 deletions webapp/src/tests/Dashboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ import Dashboard from '../pages/Dashboard';
import ButtonEf from '../components/ButtonEf';
import * as LogoutModule from '../components/game/Logout';

jest.mock('react-i18next', () => ({
useTranslation: () => {
return {
t: (str) => str,
i18n: {
changeLanguage: () => new Promise(() => {}),
},
}
},
}));

describe('Dashboard component', () => {
it('renders dashboard elements correctly', async () => {
const { getByText } = render(<MemoryRouter><Dashboard/></MemoryRouter>);
Expand Down
11 changes: 11 additions & 0 deletions webapp/src/tests/Game.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import { render, fireEvent } from '@testing-library/react';
import { MemoryRouter } from 'react-router';
import Game from '../pages/Game';

jest.mock('react-i18next', () => ({
useTranslation: () => {
return {
t: (str) => str,
i18n: {
changeLanguage: () => new Promise(() => {}),
},
}
},
}));

describe('Game component', () => {
test('renders without crashing', () => {
render(<MemoryRouter><Game/></MemoryRouter>);
Expand Down
10 changes: 10 additions & 0 deletions webapp/src/tests/Login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ jest.mock('../components/game/Logout', () => ({
logoutUser: jest.fn(),
}));

jest.mock('react-i18next', () => ({
useTranslation: () => {
return {
t: (str) => str,
i18n: {
changeLanguage: () => new Promise(() => {}),
},
}
},
}));

describe('Login Component', () => {
beforeEach(() => {
Expand Down
11 changes: 11 additions & 0 deletions webapp/src/tests/Logout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ import {logoutUser} from "components/game/Logout";

const mockAxios = new MockAdapter(axios);

jest.mock('react-i18next', () => ({
useTranslation: () => {
return {
t: (str) => str,
i18n: {
changeLanguage: () => new Promise(() => {}),
},
}
},
}));

describe("Logout User tests", () => {
beforeEach(() => {
sessionStorage.clear();
Expand Down
11 changes: 11 additions & 0 deletions webapp/src/tests/Questions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ import axios, { HttpStatusCode } from "axios";

const mockAxios = new MockAdapter(axios);

jest.mock('react-i18next', () => ({
useTranslation: () => {
return {
t: (str) => str,
i18n: {
changeLanguage: () => new Promise(() => {}),
},
}
},
}));

describe("Question Service tests", () => {
describe("getQuestion function", () => {
beforeEach(() => {
Expand Down
11 changes: 11 additions & 0 deletions webapp/src/tests/Results.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ jest.mock('react-router-dom', () => ({
}),
}));

jest.mock('react-i18next', () => ({
useTranslation: () => {
return {
t: (str) => str,
i18n: {
changeLanguage: () => new Promise(() => {}),
},
}
},
}));

describe('Results Component', () => {
test('renders results with correct answers', () => {
const { getByText, getByTestId } = render(
Expand Down
11 changes: 11 additions & 0 deletions webapp/src/tests/Root.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import { render, screen, fireEvent, getByTestId } from '@testing-library/react';
import { MemoryRouter, createMemoryRouter } from 'react-router';
import Root from '../pages/Root';

jest.mock('react-i18next', () => ({
useTranslation: () => {
return {
t: (str) => str,
i18n: {
changeLanguage: () => new Promise(() => {}),
},
}
},
}));

describe('Root component', () => {

it('renders WIQ-EN2B heading', () => {
Expand Down
11 changes: 11 additions & 0 deletions webapp/src/tests/Rules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import { render } from '@testing-library/react';
import { MemoryRouter } from 'react-router';
import Rules from '../pages/Rules';

jest.mock('react-i18next', () => ({
useTranslation: () => {
return {
t: (str) => str,
i18n: {
changeLanguage: () => new Promise(() => {}),
},
}
},
}));

describe('Rules component', () => {
it('renders rules elements correctly', async () => {
const { getByText, getByTestId } = render(<MemoryRouter><Rules/></MemoryRouter>);
Expand Down
22 changes: 18 additions & 4 deletions webapp/src/tests/Signup.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, fireEvent, getByTestId, getAllByTestId, waitFor } from '@testing-library/react';
import { render, fireEvent, getByTestId, getAllByTestId, waitFor, act } from '@testing-library/react';
import { MemoryRouter } from 'react-router';
import Signup from '../pages/Signup';
import * as AuthUtils from '../components/auth/AuthUtils';
Expand All @@ -9,6 +9,17 @@ jest.mock('../components/auth/AuthUtils', () => ({
register: jest.fn(),
}));

jest.mock('react-i18next', () => ({
useTranslation: () => {
return {
t: (str) => str,
i18n: {
changeLanguage: () => new Promise(() => {}),
},
}
},
}));

describe('Signup Component', () => {

it('renders form elements correctly', () => {
Expand Down Expand Up @@ -84,8 +95,9 @@ describe('Signup Component', () => {

// Asegúrate de que la función de navegación se haya llamado
expect(registerSpy.mock.calls[0][1]).toBeInstanceOf(Function); // Esto verifica que se pase una función como segundo argumento
registerSpy.mock.calls[0][1](); // Llama a la función de navegación

act(() => {
registerSpy.mock.calls[0][1](); // Llama a la función de navegación
})
// Verifica que la navegación se haya realizado correctamente
// Puedes agregar más expectativas aquí según tus necesidades

Expand Down Expand Up @@ -115,7 +127,9 @@ describe('Signup Component', () => {

// Verifica que la función de manejo de error se haya llamado
expect(registerSpy.mock.calls[0][2]).toBeInstanceOf(Function); // Verifica que se pase una función como tercer argumento
registerSpy.mock.calls[0][2](); // Llama a la función de manejo de error
act(() => {
registerSpy.mock.calls[0][2](); // Llama a la función de manejo de error
});

// Verifica que la variable de estado `hasError` se haya establecido correctamente
// Puedes agregar más expectativas aquí según tus necesidades
Expand Down