generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #239 from Arquisoft/develop
More tests
- Loading branch information
Showing
9 changed files
with
437 additions
and
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,87 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { render, fireEvent ,screen, waitFor } from '@testing-library/react'; | ||
import React from 'react'; | ||
import Game from './Game'; | ||
import Game, { formatNumberWithDots} from './Game'; | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
const wait = (milliseconds: number) => { | ||
return new Promise<void>((resolve) => { | ||
setTimeout(resolve, milliseconds); | ||
}); | ||
}; | ||
|
||
jest.mock("../../services/question-service", () => { | ||
return { | ||
getHardString : () => 'hard', | ||
getQuestionsFromApi: () => { | ||
return Promise.resolve([ | ||
{ | ||
text: '¿Cuál es la capital de España?', | ||
correctAnswer: 0, | ||
answers: ['Madrid','Barcelona', 'Sevilla', 'Valencia'], | ||
wikiLink: '' | ||
}, | ||
{ | ||
text: '¿Cuál es la capital de Francia?', | ||
correctAnswer: 0, | ||
answers: ['Paris','Barcelona', 'Sevilla', 'Valencia'], | ||
wikiLink: '' | ||
} | ||
]); | ||
} | ||
} | ||
}); | ||
|
||
describe('Game component', () => { | ||
|
||
|
||
it('should render the game',async () => { | ||
await act( async () => { | ||
render(<Game difficulty='easy'/>); | ||
}); | ||
expect(screen.getByTestId('game-component')).toBeInTheDocument(); | ||
}); | ||
|
||
describe('Game component', () => { | ||
it('should render the game', () => { | ||
render( <Game difficulty='easy'/> ); | ||
it('should render the game in hard mode',async () => { | ||
await act( async () => { | ||
render(<Game difficulty='hard'/>); | ||
}); | ||
expect(screen.getByTestId('game-component')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should go to the next question', async () => { | ||
await act( async () => { | ||
render(<Game difficulty='easy'/>); | ||
}); | ||
|
||
expect(screen.getByTestId('game-container')).toBeInTheDocument(); | ||
|
||
expect(screen.getByText('Madrid')).toBeInTheDocument(); | ||
fireEvent.click(screen.getByText('Madrid')); | ||
|
||
await wait(4000); | ||
expect(screen.getByText('Paris')).toBeInTheDocument(); | ||
|
||
}); | ||
|
||
it('format a number with the dots', () => { | ||
const shortNumber = '700'; | ||
expect(formatNumberWithDots(shortNumber)).toBe('700'); | ||
|
||
const number = '100000'; | ||
expect(formatNumberWithDots(number)).toBe('100.000'); | ||
}); | ||
|
||
//mockear la llegada de preguntas de la api | ||
it('should display the question and answers when the questions arrive', async () => { | ||
|
||
await act( async () => { | ||
render(<Game difficulty='easy'/>); | ||
}); | ||
|
||
expect(screen.getByText('Madrid')).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
Oops, something went wrong.