Skip to content

Commit

Permalink
Merge pull request #60 from fga-eps-mds/feat#59/adiciona-requestButton
Browse files Browse the repository at this point in the history
FEAT: adiciona o componente de botão para manter padronização (#59)
  • Loading branch information
GabrielCostaDeOliveira committed Jan 10, 2025
2 parents 3d334cb + b9998c3 commit 0e43f8b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 54 deletions.
68 changes: 23 additions & 45 deletions lib/ui/register_account/view/register_account_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:aranduapp/ui/login/view/login_view.dart';
import 'package:aranduapp/ui/shared/OrDivider.dart';
import 'package:aranduapp/ui/shared/TextAndLink.dart';
import 'package:aranduapp/ui/shared/TextName.dart';
import 'package:aranduapp/ui/shared/requestbutton.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:aranduapp/core/log/Log.dart';
Expand Down Expand Up @@ -88,17 +89,14 @@ class RegisterAccountScreen extends StatelessWidget {

Widget _buildTermsCheckbox(BuildContext context) {
final viewModel = Provider.of<RegisterAccountViewModel>(context);

return Row(
children: [
Checkbox(
value: viewModel.isTermsAccepted,
onChanged: (value) {
// Ação ao clicar no checkbox
if (value != null) {
viewModel.toggleTermsAccepted(value);
}
},
),
value: viewModel.isTermsAccepted,
onChanged: (value) {
viewModel.setToggleTermsAccepted(value ?? false);
}),
Expanded(
child: Text(
'Aceite os termos de privacidade',
Expand All @@ -112,43 +110,23 @@ class RegisterAccountScreen extends StatelessWidget {
Widget _buildRegisterButton(BuildContext context) {
final viewModel = Provider.of<RegisterAccountViewModel>(context);

return ListenableBuilder(
listenable: viewModel.registerCommand,
builder: (context, child) {
if (viewModel.registerCommand.isError) {
WidgetsBinding.instance.addPostFrameCallback((_) {
showDialog<Object>(
context: context,
builder: (BuildContext context) => ErrorPopUp(
content: Text(viewModel.registerCommand.result!.asError!.error
.toString()),
),
);
});
}

if (viewModel.registerCommand.isOk) {
WidgetsBinding.instance.addPostFrameCallback((_) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('conta criada com sucesso!!!')),
);
});
}

return SizedBox(
width: 291,
height: 64,
child: ElevatedButton(
onPressed: () async {
viewModel.registerCommand.execute();
},
child: viewModel.registerCommand.running
? const CircularProgressIndicator(value: null)
: const Text('Registrar'),
),
);
},
);
return Requestbutton(
command: viewModel.registerCommand,
nameButton: 'Registrar',
onSuccessCallback: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('conta criada com sucesso!!!')),
);
},
onErrorCallback: (e) {
showDialog<Object>(
context: context,
builder: (BuildContext context) => ErrorPopUp(
content: Text(
viewModel.registerCommand.result!.asError!.error.toString()),
),
);
});
}

Widget _buildGoogleLoginButton(BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/register_account/viewModel/register_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RegisterAccountViewModel extends ChangeNotifier {
return Result.value(null);
}

void toggleTermsAccepted(bool value) {
void setToggleTermsAccepted(bool value) {
isTermsAccepted = value;
notifyListeners();
}
Expand Down
35 changes: 29 additions & 6 deletions test/ui/register_account/view/register_account_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ void main() {
testWidgets('Test sending the request', (WidgetTester tester) async {
await tester.pumpWidget(createLoginScreen(mockViewModel));

when(mockViewModel.registerCommand).thenReturn(mockCommand0);

final sendButton = find.text('Registrar');

await tester.tap(sendButton);
Expand All @@ -80,8 +78,6 @@ void main() {
});

testWidgets('Register Account Test User Input', (WidgetTester tester) async {
when(mockViewModel.registerCommand).thenReturn(mockCommand0);

await tester.pumpWidget(createLoginScreen(mockViewModel));

const name = 'test';
Expand All @@ -103,9 +99,37 @@ void main() {
expect(mockViewModel.emailController.text, email);
});

testWidgets('Checkbox shows correct value when initially unchecked', (WidgetTester tester) async {
when(mockViewModel.isTermsAccepted).thenReturn(false);

await tester.pumpWidget(createLoginScreen(mockViewModel));
await tester.pumpAndSettle();

Checkbox checkbox = tester.widget(find.byType(Checkbox));
expect(checkbox.value, false);

await tester.tap(find.byType(Checkbox));

verify(mockViewModel.setToggleTermsAccepted(true)).called(1);
});


testWidgets('Checkbox shows correct value when initially checked', (WidgetTester tester) async {
when(mockViewModel.isTermsAccepted).thenReturn(true);

await tester.pumpWidget(createLoginScreen(mockViewModel));
await tester.pumpAndSettle();

Checkbox checkbox = tester.widget(find.byType(Checkbox));
expect(checkbox.value, true);

await tester.tap(find.byType(Checkbox));

verify(mockViewModel.setToggleTermsAccepted(false)).called(1);
});

testWidgets('Register Account user notification snackbar',
(WidgetTester tester) async {
when(mockViewModel.registerCommand).thenReturn(mockCommand0);
when(mockCommand0.isOk).thenReturn(true);

await tester.pumpWidget(createLoginScreen(mockViewModel));
Expand All @@ -129,5 +153,4 @@ void main() {
expect(find.byType(ErrorPopUp), findsOneWidget);
expect(find.text(error), findsOneWidget);
});

}
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ class MockRegisterAccountViewModel extends _i2.Mock
) as bool);

@override
void toggleTermsAccepted(bool? value) => super.noSuchMethod(
void setToggleTermsAccepted(bool? value) => super.noSuchMethod(
Invocation.method(
#toggleTermsAccepted,
#setToggleTermsAccepted,
[value],
),
returnValueForMissingStub: null,
Expand Down

0 comments on commit 0e43f8b

Please sign in to comment.