Skip to content

Commit

Permalink
added new test mock tries
Browse files Browse the repository at this point in the history
  • Loading branch information
uo289267 committed Apr 6, 2024
1 parent 5bfc9c1 commit 4467576
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion webapp/src/components/questionView/QuestionView.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function QuestionView(){
let colorCorrectAnswer='#6EF26E';//green
let colorIncorrectAnswer='#FF6666'; //red
$('.answerButton').each(function() {
var dataValue = $(this).data('value');
var dataValue = $(this).attr('data-value');
if (dataValue === false || dataValue === "false")
$(this).css('background-color', colorIncorrectAnswer); // Cambia el color de fondo del botón actual a rojo

Expand Down
22 changes: 19 additions & 3 deletions webapp/src/components/questionView/QuestionView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MemoryRouter } from 'react-router-dom';
import { act } from 'react-dom/test-utils';
import {queryHelpers, buildQueries} from '@testing-library/react'

jest.mock('./QuestionGenerator', () => require('./mocks/QuestionGenerator'));

i18en.use(initReactI18next).init({
resources: {},
Expand All @@ -17,15 +18,30 @@ i18en.use(initReactI18next).init({
global.i18en = i18en;

describe('Question View component', () => {
it('renders a question', () => {
it('renders a question',async () => {
act(() => {
render(<MemoryRouter><QuestionView /></MemoryRouter>);

});
const text = screen.getByText('Please Wait a bit...');
expect(text).toBeInTheDocument();

// Wait for questions to load
await waitFor(() => expect(getByText('Mocked Question 1')).toBeInTheDocument());
const tituloH2 = screen.getByRole('heading', { level: 2 });
expect(tituloH2).toBeInTheDocument();
});
/*
it('renders a question',async () => {
act(() => {
const { getByText } = render(<MemoryRouter><QuestionView /></MemoryRouter>);
});
//h2 con la pregunta
const tituloH2 = screen.getByRole('heading', { level: 2 });
// Verifica si el elemento h2 está presente en el documento
expect(tituloH2).toBeInTheDocument();
});
});*/
/*
it('render a question and 4 buttons for answers', () => {
act(() => {
render(<MemoryRouter><QuestionView /></MemoryRouter>);
Expand Down Expand Up @@ -61,5 +77,5 @@ describe('Question View component', () => {
// Verificar que el botón tenga el color esperado
expect(falseAnswerButton).toHaveStyle('background-color:#FF6666');
});
});*/
});
20 changes: 20 additions & 0 deletions webapp/src/components/questionView/mocks/QuestionGenerator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default class QuestionGenerator {
async generateQuestions() {
return [
{
getQuestion: () => 'Mocked Question 1',
getAnswers: () => ['Mocked Answer 1', 'Mocked Answer 2','Mocked Answer 3', 'Mocked Answer 4'],
getCorrectAnswer: () => 'Mocked Answer 1'
},
{
getQuestion: () => 'Mocked Question 2',
getAnswers: () => ['Mocked Answer 1', 'Mocked Answer 2','Mocked Answer 3', 'Mocked Answer 4'],
getCorrectAnswer: () => 'Mocked Answer 4'
},{
getQuestion: () => 'Mocked Question 3',
getAnswers: () => ['Mocked Answer 1', 'Mocked Answer 2','Mocked Answer 3', 'Mocked Answer 4'],
getCorrectAnswer: () => 'Mocked Answer 2'
}
];
}
}

0 comments on commit 4467576

Please sign in to comment.