Skip to content

Commit

Permalink
Criado o teste para a tela de perfil do nutricionista #91
Browse files Browse the repository at this point in the history
  • Loading branch information
Davi-Nascimento-Santos committed Jan 21, 2025
1 parent 915a607 commit 9cca8ed
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions healthway_app/test/flutter
Submodule flutter added at 68415a
95 changes: 95 additions & 0 deletions healthway_app/test/nutricionista_profile_screen_teste.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:healthway_app/screens_nutricionist/nutritionist_profile.dart';

void main() {
testWidgets('NutritionistProfileScreen displays correctly', (WidgetTester tester) async {
// Build the NutritionistProfileScreen widget.
await tester.pumpWidget(
MaterialApp(
home: NutritionistProfileScreen(userData: {}),
),
);

// Verify if the AppBar widget is present.
expect(find.byType(AppBar), findsOneWidget);

// Verify if the Scaffold widget has the correct background color.
final scaffold = tester.widget<Scaffold>(find.byType(Scaffold));
expect(scaffold.backgroundColor, const Color(0xFFE6F7F8)); // Substitua com a cor definida por `kBackgroundColor`.

// Verify if the CircleAvatar widget is present.
expect(find.byType(CircleAvatar), findsOneWidget);

// Verify if the Form widget is present.
expect(find.byType(Form), findsOneWidget);

// Verify if the TextFormField widgets are present when editing.
await tester.tap(find.byIcon(Icons.edit)); // Tap the edit button to enable editing.
await tester.pump();
expect(find.byType(TextFormField), findsNWidgets(5)); // Nome, email, CPF, CRN, Especialidade.

// Verify if the ElevatedButton widget is present.
expect(find.widgetWithText(ElevatedButton, 'Editar Perfil Detalhado'), findsOneWidget);

// Verify if the OutlinedButton widget is present.
expect(find.widgetWithText(OutlinedButton, 'Alterar Senha'), findsOneWidget);

// Verify if the document image container is present.
expect(find.byType(Container), findsWidgets);
});

testWidgets('Toggling edit mode in NutritionistProfileScreen', (WidgetTester tester) async {
// Build the NutritionistProfileScreen widget.
await tester.pumpWidget(
MaterialApp(
home: NutritionistProfileScreen(userData: {}),
),
);

// Initial state: not editing.
expect(find.byType(TextFormField), findsNothing);

// Tap the edit button to enable editing.
await tester.tap(find.byIcon(Icons.edit));
await tester.pump();

// Verify if TextFormFields appear for editing.
expect(find.byType(TextFormField), findsWidgets);

// Tap the close button to disable editing.
await tester.tap(find.byIcon(Icons.close));
await tester.pump();

// Verify if TextFormFields disappear.
expect(find.byType(TextFormField), findsNothing);
});

testWidgets('Saving changes in NutritionistProfileScreen', (WidgetTester tester) async {
// Build the NutritionistProfileScreen widget.
await tester.pumpWidget(
MaterialApp(
home: NutritionistProfileScreen(userData: {}),
),
);

// Enable editing.
await tester.tap(find.byIcon(Icons.edit));
await tester.pump();

// Enter new values into the TextFormFields.
await tester.enterText(find.widgetWithText(TextFormField, 'Dr. Silva'), 'Dr. Teste');
await tester.enterText(find.widgetWithText(TextFormField, 'dr.silva@email.com'), 'teste@email.com');
await tester.pump();

// Tap the save button.
await tester.tap(find.byType(FloatingActionButton));
await tester.pump();

// Verify if the snackbar appears with the success message.
expect(find.text('Perfil atualizado com sucesso!'), findsOneWidget);

// Verify if editing mode is disabled.
expect(find.byType(TextFormField), findsNothing);
});
}

0 comments on commit 9cca8ed

Please sign in to comment.