forked 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 branch 'webapp_interface' of https://github.com/Arquisoft/wiq_es6c
- Loading branch information
Showing
6 changed files
with
102 additions
and
22 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import Button from './Button'; | ||
|
||
|
||
describe('Button component', () => { | ||
|
||
test('renders button', () => { | ||
const { getByText } = render(<Button text="Click me" />); | ||
|
||
//Comprobamos que tenemos el texto | ||
expect(getByText('Click me')).toBeInTheDocument(); | ||
}); | ||
|
||
test('clicamos el boton', () => { | ||
const handleClick = jest.fn(); | ||
|
||
const { getByText } = render(<Button text="Click me" onClick={handleClick} />); | ||
|
||
//intentamos clicar el botón con una tecla que no sea enter | ||
fireEvent.keyDown(getByText('Click me'), { key: 'Space' }); | ||
expect(handleClick).not.toHaveBeenCalled(); | ||
//hacemos click normal | ||
fireEvent.click(getByText('Click me')); | ||
expect(handleClick).toHaveBeenCalled(); | ||
//clicamos el boton con la tecla enter | ||
fireEvent.keyDown(getByText('Click me'), { key: 'Enter' }); | ||
expect(handleClick).toHaveBeenCalled(); | ||
|
||
}); | ||
|
||
}); |
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
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { shuffleArray, secureRandomNumber } from './Util'; | ||
|
||
jest.mock('axios'); | ||
|
||
describe('shuffleArray function', () => { | ||
// Mocking window.crypto.getRandomValues | ||
beforeEach(() => { | ||
const max = 100; | ||
global.crypto = { | ||
getRandomValues: jest.fn().mockImplementation((array) => { | ||
for (let i = 0; i < array.length; i++) { | ||
array[i] = i; | ||
} | ||
}), | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('shuffles the array', () => { | ||
const array = [1, 2, 3, 4, 5]; | ||
const shuffledArray = shuffleArray(array); | ||
expect(shuffledArray).not.toEqual(array); | ||
}); | ||
|
||
test('does not mutate the original array', () => { | ||
const array = [1, 2, 3, 4, 5]; | ||
const originalArray = [...array]; | ||
shuffleArray(array); | ||
expect(array).toEqual(originalArray); | ||
}); | ||
}); | ||
|
||
describe('secureRandomNumber function', () => { | ||
|
||
test('generates a secure random number', () => { | ||
const max = 100; | ||
const randomNumber = secureRandomNumber(max); | ||
|
||
//comprobamos que el numero obtenido es < que el máximo | ||
expect(randomNumber).toBeLessThan(max); | ||
//comprobamos que el numero obtenido es >= 0 | ||
expect(randomNumber).toBeGreaterThanOrEqual(0); | ||
}); | ||
|
||
}); |
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