Skip to content

Commit

Permalink
Merge pull request #64 from ES2-UFPI/paulo-47
Browse files Browse the repository at this point in the history
Create PressaoArterial.teste.js
  • Loading branch information
ben-sabino authored Jan 20, 2025
2 parents 61f8ac8 + 3aaf217 commit d4e204e
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app-menu/components/__tests__/PressaoArterial.teste.js
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'));
});
});

0 comments on commit d4e204e

Please sign in to comment.