Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create PressaoArterial.teste.js #64

Merged
merged 3 commits into from
Jan 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'));
});
});
Loading