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

FEAT: adiciona o componente de botão para manter padronização (#59) #60

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
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
77 changes: 23 additions & 54 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,67 +89,35 @@ class RegisterAccountScreen extends StatelessWidget {

Widget _buildTermsCheckbox(BuildContext context) {
final viewModel = Provider.of<RegisterAccountViewModel>(context);
return Row(
children: [
Checkbox(

return Checkbox(
value: viewModel.isTermsAccepted,
onChanged: (value) {
// Ação ao clicar no checkbox
if (value != null) {
viewModel.toggleTermsAccepted(value);
}
},
),
Expanded(
child: Text(
'Aceite os termos de privacidade',
style: Theme.of(context).textTheme.bodySmall,
),
),
],
);
viewModel.setToggleTermsAccepted(value??false);
});

}

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
Loading