Skip to content

Commit

Permalink
fix(#59): Corrige register_account viewModel, shared e test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasm1nNasc1mento committed Dec 26, 2024
1 parent 288039a commit a172397
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 36 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 @@ -121,13 +121,18 @@ class _RegisterAccountState extends State<_RegisterAccount> {
width: 291,
height: 64,
child: ElevatedButton(
onPressed: () {
viewModel.register(context).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
7 changes: 1 addition & 6 deletions lib/ui/register_account/viewModel/RegisterViewModel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,8 @@ class RegisterAccountViewModel extends ChangeNotifier {
);
// Chamada do serviço de registro
await RegisterService.register(request);
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')),
);
throw e;
} finally {
isLoading = false;
notifyListeners();
Expand Down
12 changes: 6 additions & 6 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 @@ -24,17 +25,16 @@ class TextEmail extends StatelessWidget{
child: TextFormField(
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'Campo Obrigatório';
return '$label Obrigatório.';
} else if (!emailRegex.hasMatch(value.trim())) {
return 'E-mail inválido (Ex: [email protected])';
return 'Opa, $label inválido! (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
6 changes: 4 additions & 2 deletions lib/ui/shared/TextName.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ class TextName extends StatelessWidget {
child: TextFormField(
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'Campo Obrigatório';
return '$label Obrigatório.';
} else if (value.trim().length < 2) {
return 'Opa, seu $label está pequeno! \n acrescente mais caracteres. (Ex: Ana)';
} else if (value.trim().length < 3) {
return 'Nome inválido (Ex: Ana)';
return 'Opa, seu $label está pequeno!\n acrescente mais um caractere. (Ex: Ana)';
}
return null;
},
Expand Down
16 changes: 11 additions & 5 deletions lib/ui/shared/TextPassword.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
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() {
Expand All @@ -23,9 +28,9 @@ class _TextPassWord extends State<TextPassWord> {
child: TextFormField(
validator: (value) {
if (value == null || value.isEmpty) {
return 'Campo Obrigatório';
return '${widget.label} Obrigatória.';
} else if (value.length < 8) {
return 'Mínimo 8 caracteres (Ex: @abd1234)';
return '${widget.label} deve ter no mínimo 8 caracteres. (Ex: @abd1234)';
}
return null;
},
Expand All @@ -43,7 +48,8 @@ class _TextPassWord extends State<TextPassWord> {
? Icons.visibility_off_outlined
: Icons.visibility_outlined,
color: Theme.of(context).colorScheme.primary)),
labelText: 'Senha'),
labelText: widget.label,
),
),
);
}
Expand Down
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
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("", "Campo Obrigatório"); // Campo vazio
await testEmail("joaozinhi", "E-mail inválido (Ex: [email protected])"); // Sem '@'
await testEmail("joaozinhi@", "E-mail inválido (Ex: [email protected])"); // Sem domínio
await testEmail("joao@domain", "E-mail inválido (Ex: [email protected])"); // Sem extensão
await testEmail("", "E-mail Obrigatório."); // Campo vazio
await testEmail("joaozinhi", "Opa, E-mail inválido! (Ex: [email protected])"); // Sem '@'
await testEmail("joaozinhi@", "Opa, E-mail inválido! (Ex: [email protected])"); // Sem domínio
await testEmail("joao@domain", "Opa, E-mail inválido! (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("", 'Campo Obrigatório'); // Campo vazio
await testName(" a", 'Nome inválido (Ex: Ana)'); // Nome com menos de 3 caracteres
await testName("Jo", 'Nome inválido (Ex: Ana)'); // Nome com 2 caracteres
await testName("", 'Nome Obrigatório.'); // Campo vazio
await testName(" a", 'Opa, seu Nome está pequeno! \n acrescente mais caracteres. (Ex: Ana)'); // Nome com menos de 3 caracteres
await testName("Jo", 'Opa, seu Nome está pequeno!\n acrescente 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', "Mínimo 8 caracteres (Ex: @abd1234)"); // Senha muito curta
await testPassword('12345', "Senha deve ter no mínimo 8 caracteres. (Ex: @abd1234)"); // Senha muito curta
await testPassword('validPassword123', null); // Senha válida
await testPassword('', 'Campo Obrigatório'); // Campo vazio
await testPassword('', 'Senha Obrigatória.'); // Campo vazio
});

// Testa a funcionalidade de visibilidade da senha
Expand Down

0 comments on commit a172397

Please sign in to comment.