Skip to content

Commit

Permalink
Merge pull request #53 from fga-eps-mds/fix#59/ajusta-menssagem-regis…
Browse files Browse the repository at this point in the history
…ter_account

fix#59/melhora menssagem de erro e ajusta casos de teste (fga-eps-mds/2024.2-ARANDU-DOC#59)
  • Loading branch information
GabrielCostaDeOliveira authored Dec 26, 2024
2 parents 7d2832d + 0d1a76b commit 05ac25a
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 60 deletions.
19 changes: 12 additions & 7 deletions lib/ui/register_account/view/RegisterAccount.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,18 @@ class _RegisterAccountState extends State<_RegisterAccount> {
width: 291,
height: 64,
child: ElevatedButton(
onPressed: () {
viewModel.register().catchError((e) => showDialog<Object>(
context: context,
builder: (BuildContext context) =>
ErrorPopUp(content: Text('$e')),
));
// Ação ao clicar no botão de cadastro
onPressed: () async {
try {
await viewModel.register(context);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Cadastro concluído com sucesso!")));
} catch(e) {
showDialog<Object>(
context: context,
builder: (BuildContext context) => ErrorPopUp(content: Text('$e')),
//Ação ao clicar no botão de cadastro
);
}
},
child: Consumer<RegisterAccountViewModel>(
builder: (context, value, child) => value.isLoading
Expand Down
9 changes: 5 additions & 4 deletions lib/ui/register_account/viewModel/RegisterViewModel.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:aranduapp/ui/shared/ErrorPopUp.dart';
import 'package:flutter/material.dart';
import '../model/RegisterRequest.dart';
import '../service/RegisterService.dart';

class RegisterAccountViewModel extends ChangeNotifier {

final GlobalKey<FormState> formKey = GlobalKey<FormState>();
final TextEditingController nameController = TextEditingController();
final TextEditingController emailController = TextEditingController();
Expand All @@ -13,14 +13,14 @@ class RegisterAccountViewModel extends ChangeNotifier {
final TextEditingController confPasswordController = TextEditingController();

bool isLoading = false;
bool isTermsAccepted = false;
bool isTermsAccepted = false;

void toggleTermsAccepted(bool value) {
isTermsAccepted = value;
notifyListeners();
}

Future<void> register() async {
Future<void> register(BuildContext context) async {
if (isLoading) return;
// Valida se os termos foram aceitos
if (!isTermsAccepted) {
Expand All @@ -43,10 +43,11 @@ class RegisterAccountViewModel extends ChangeNotifier {
);
// Chamada do serviço de registro
await RegisterService.register(request);
} catch (e) {
rethrow;
} finally {
isLoading = false;
notifyListeners();
}
}
}

17 changes: 12 additions & 5 deletions lib/ui/shared/TextEmail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';

class TextEmail extends StatelessWidget{


final String label;
final TextEditingController controller;
final EdgeInsetsGeometry padding;

Expand All @@ -11,8 +11,9 @@ class TextEmail extends StatelessWidget{

const TextEmail ({
super.key,
this.label = 'E-mail',
required this.padding,
required this.controller
required this.controller,
});


Expand All @@ -22,12 +23,18 @@ class TextEmail extends StatelessWidget{
return Padding(
padding: padding,
child: TextFormField(
validator: (value) => value == null|| emailRegex.hasMatch(value) ? null : 'E-mail inválido',
validator: (value) {
if (value == null || value.trim().isEmpty) {
return '$label Obrigatório.';
} else if (!emailRegex.hasMatch(value.trim())) {
return 'Opa, $label inválido!\n(Ex: [email protected])';
}
return null;
},
controller: controller,
decoration: InputDecoration (
prefixIcon: Icon ( Icons.email_outlined, color: Theme.of(context).colorScheme.primary),
labelText: 'E-mail'
),
labelText: label),
),
);
}
Expand Down
12 changes: 10 additions & 2 deletions lib/ui/shared/TextName.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ class TextName extends StatelessWidget {
return Padding(
padding: padding,
child: TextFormField(
validator: (value) =>
value == null || value.trim().length < 3 ? '$label inválido' : null,
validator: (value) {
if (value == null || value.trim().isEmpty) {
return '$label Obrigatório.';
} else if (value.trim().length < 2) {
return 'Opa, seu $label está pequeno!\nacrescente mais caracteres. (Ex: Ana)';
} else if (value.trim().length < 3) {
return 'Opa, seu $label está pequeno!\nacrescente mais um caractere. (Ex: Ana)';
}
return null;
},
controller: controller,
decoration: InputDecoration(
prefixIcon: Icon(Icons.person_outline,
Expand Down
62 changes: 31 additions & 31 deletions lib/ui/shared/TextPassword.dart
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
import 'package:flutter/material.dart';

class TextPassWord extends StatefulWidget {

final String label;
final TextEditingController controller;
final EdgeInsetsGeometry padding;

const TextPassWord ({
super.key,
required this.padding,
required this.controller
const TextPassWord({
super.key,
this.label = 'Senha',
required this.padding,
required this.controller,
});


@override
State<StatefulWidget> createState() {
return _TextPassWord();
}
}
}


class _TextPassWord extends State<TextPassWord> {
bool _hidePassord = true;

@override
Widget build(BuildContext context) {

return
Padding(
padding: widget.padding,
child: TextFormField(
return Padding(
padding: widget.padding,
child: TextFormField(
validator: (value) {
if (value == null || value.isEmpty || value.length < 8) {
return 'Senha inválida';
if (value == null || value.isEmpty) {
return '${widget.label} Obrigatória.';
} else if (value.length < 8) {
return '${widget.label} deve ter no mínimo 8 caracteres.\n(Ex: @abd1234)';
}
return null;
},
controller: widget.controller,
obscureText: _hidePassord,
decoration: InputDecoration (
prefixIcon: Icon ( Icons.lock_outline, color: Theme.of(context).colorScheme.primary),
suffixIcon: GestureDetector (
onTap: () => setState(() { _hidePassord = !_hidePassord; }),
child: Icon(
_hidePassord ? Icons.visibility_off_outlined : Icons.visibility_outlined,
color: Theme.of(context).colorScheme.primary
)
),
labelText: 'Senha'
),
obscureText: _hidePassord,
decoration: InputDecoration(
prefixIcon: Icon(Icons.lock_outline,
color: Theme.of(context).colorScheme.primary),
suffixIcon: GestureDetector(
onTap: () => setState(() {
_hidePassord = !_hidePassord;
}),
child: Icon(
_hidePassord
? Icons.visibility_off_outlined
: Icons.visibility_outlined,
color: Theme.of(context).colorScheme.primary)),
labelText: widget.label,
),
);


}
),
);
}
}
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ packages:
dependency: transitive
description:
name: path
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
url: "https://pub.dev"
source: hosted
version: "1.9.0"
Expand Down
4 changes: 3 additions & 1 deletion test/ui/Shared/ErrorPopUp_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ void main() {
// Rebuild após o tap para processar a navegação
await tester.pumpAndSettle();

expect(find.text('OK'), findsNothing); // O popup desapareceu
expect(find.text('OK'), findsNothing);
expect(find.byIcon(Icons.error), findsNothing);
expect(find.text('Este é um erro'), findsNothing); // O popup desapareceu
});
}
8 changes: 4 additions & 4 deletions test/ui/Shared/TextEmail_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ void main() {
}

// Teste de validação para diferentes casos
await testEmail("", "E-mail inválido"); // Campo vazio
await testEmail("joaozinhi", "E-mail inválido"); // Sem '@'
await testEmail("joaozinhi@", "E-mail inválido"); // Sem domínio
await testEmail("joao@domain", "E-mail inválido"); // Sem extensão
await testEmail("", "E-mail Obrigatório."); // Campo vazio
await testEmail("joaozinhi", "Opa, E-mail inválido!\n(Ex: [email protected])"); // Sem '@'
await testEmail("joaozinhi@", "Opa, E-mail inválido!\n(Ex: [email protected])"); // Sem domínio
await testEmail("joao@domain", "Opa, E-mail inválido!\n(Ex: [email protected])"); // Sem extensão
await testEmail("[email protected]", null); // Entrada válida
});
}
6 changes: 3 additions & 3 deletions test/ui/Shared/TextName_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ void main() {
}

// Teste de validação para diferentes casos de nome
await testName("", 'Nome inválido'); // Campo vazio
await testName(" a", 'Nome inválido'); // Nome com menos de 3 caracteres
await testName("Jo", 'Nome inválido'); // Nome com 2 caracteres
await testName("", 'Nome Obrigatório.'); // Campo vazio
await testName(" a", 'Opa, seu Nome está pequeno!\nacrescente mais caracteres. (Ex: Ana)'); // Nome com menos de 3 caracteres
await testName("Jo", 'Opa, seu Nome está pequeno!\nacrescente mais um caractere. (Ex: Ana)'); // Nome com 2 caracteres
await testName("João", null); // Nome válido
await testName("Maria", null); // Outro nome válido
});
Expand Down
4 changes: 2 additions & 2 deletions test/ui/Shared/TextPassword_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ void main() {
}

// Testa senhas inválidas, válidas e campo vazio
await testPassword('12345', "Senha inválida"); // Senha muito curta
await testPassword('12345', "Senha deve ter no mínimo 8 caracteres.\n(Ex: @abd1234)"); // Senha muito curta
await testPassword('validPassword123', null); // Senha válida
await testPassword('', 'Senha inválida'); // Campo vazio
await testPassword('', 'Senha Obrigatória.'); // Campo vazio
});

// Testa a funcionalidade de visibilidade da senha
Expand Down

0 comments on commit 05ac25a

Please sign in to comment.