-
Notifications
You must be signed in to change notification settings - Fork 0
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 #64 from ES2-UFPI/paulo-47
Create PressaoArterial.teste.js
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 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,39 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react-native'; | ||
import RegistroPressaoArterial from '../../components/screens/PressaoArterial'; | ||
|
||
describe('RegistroPressaoArterial', () => { | ||
it('should add a new record when all fields are filled and the button is pressed', () => { | ||
const { getByPlaceholderText, getByText, queryByText } = render(<RegistroPressaoArterial />); | ||
|
||
// Fill the input fields | ||
fireEvent.changeText(getByPlaceholderText('Digite a pressão sistólica'), '120'); | ||
fireEvent.changeText(getByPlaceholderText('Digite a pressão diastólica'), '80'); | ||
fireEvent.changeText(getByPlaceholderText('Digite o pulso'), '70'); | ||
|
||
// Press the button to add the record | ||
fireEvent.press(getByText('Adicionar Registro')); | ||
|
||
// Confirm the record in the modal | ||
fireEvent.press(getByText('Confirmar')); | ||
|
||
// Check if the record was added | ||
expect(queryByText('Sistólica: 120')).toBeTruthy(); | ||
expect(queryByText('Diastólica: 80')).toBeTruthy(); | ||
expect(queryByText('Pulso: 70')).toBeTruthy(); | ||
}); | ||
|
||
it('should show an alert when not all fields are filled', () => { | ||
const { getByPlaceholderText, getByText } = render(<RegistroPressaoArterial />); | ||
|
||
// Fill only some input fields | ||
fireEvent.changeText(getByPlaceholderText('Digite a pressão sistólica'), '120'); | ||
fireEvent.changeText(getByPlaceholderText('Digite a pressão diastólica'), '80'); | ||
|
||
// Mock the alert function | ||
jest.spyOn(global, 'alert').mockImplementation(() => {}); | ||
|
||
// Press the button to add the record | ||
fireEvent.press(getByText('Adicionar Registro')); | ||
}); | ||
}); |