diff --git a/lib/components/dialogs/login/entrarDialog.dart b/lib/components/dialogs/login/entrarDialog.dart index 1db3f92..d532da4 100644 --- a/lib/components/dialogs/login/entrarDialog.dart +++ b/lib/components/dialogs/login/entrarDialog.dart @@ -42,6 +42,7 @@ Future entrar(BuildContext context) { Padding( padding: EdgeInsets.only(bottom: 16), child: input( + key: Key("keyTextEmail"), onSaved: loginController.loginUsuario, textController: loginController.controllerUsuario, @@ -51,6 +52,7 @@ Future entrar(BuildContext context) { Padding( padding: EdgeInsets.only(bottom: 16), child: input( + key: Key("keyTextSenha"), onSaved: loginController.loginSenha, textController: loginController.controllerSenha, @@ -60,7 +62,7 @@ Future entrar(BuildContext context) { Padding( padding: const EdgeInsets.fromLTRB(0, 0, 0, 16.0), child: Botao( - key: Key("BB"), + key: Key("keyEntrarButton"), texto: 'Entrar', cor: const Color(0xFF6BC8E4), clicar: () async { diff --git a/lib/components/input.dart b/lib/components/input.dart index 277cde2..482fd16 100644 --- a/lib/components/input.dart +++ b/lib/components/input.dart @@ -1,62 +1,79 @@ import 'package:flutter/material.dart'; -Widget input( - {dynamic onSaved, - TextEditingController? textController, - String? label, - bool senha = false, - bool readOnly = false, - String? placeholder = '', - bool excluir = false, - Function? funcao}) { - return Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - label!, - style: const TextStyle( - color: Colors.black, - fontSize: 16, - fontWeight: FontWeight.w400, +class input extends StatelessWidget { + const input( + {Key? key, + this.onSaved, + this.textController, + this.label, + this.funcao, + this.senha = false, + this.excluir = false, + this.readOnly = false, + this.placeholder = ''}) + : super(key: key); + + final dynamic onSaved; + final TextEditingController? textController; + final String? label; + final bool? senha; + final bool? readOnly; + final String? placeholder; + final bool? excluir; + final Function? funcao; + + @override + Widget build(BuildContext context) { + return Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + label!, + style: const TextStyle( + color: Colors.black, + fontSize: 16, + fontWeight: FontWeight.w400, + ), ), - ), - Material( - color: Colors.white.withOpacity(0), - child: TextFormField( - obscureText: senha, - readOnly: readOnly, - onSaved: onSaved, - controller: textController, - decoration: InputDecoration( - suffixIcon: excluir - ? GestureDetector( - onTap: () { - funcao!(); - }, - child: const Icon(Icons.close)) - : null, - hintText: placeholder, - fillColor: Colors.white, - filled: true, - enabledBorder: OutlineInputBorder( - borderSide: const BorderSide( - color: Colors.black, - width: 3.0, + Material( + color: Colors.white.withOpacity(0), + child: TextFormField( + //key: key ?? Key("keyTesteButton"), + obscureText: senha!, + readOnly: readOnly!, + onSaved: onSaved, + controller: textController, + decoration: InputDecoration( + suffixIcon: excluir! + ? GestureDetector( + onTap: () { + funcao!(); + }, + child: const Icon(Icons.close)) + : null, + hintText: placeholder, + fillColor: Colors.white, + filled: true, + enabledBorder: OutlineInputBorder( + borderSide: const BorderSide( + color: Colors.black, + width: 3.0, + ), + borderRadius: BorderRadius.circular(16.0), ), - borderRadius: BorderRadius.circular(16.0), - ), - focusedBorder: OutlineInputBorder( - borderSide: const BorderSide( - color: Colors.black, - width: 3.0, + focusedBorder: OutlineInputBorder( + borderSide: const BorderSide( + color: Colors.black, + width: 3.0, + ), + borderRadius: BorderRadius.circular(16.0), ), - borderRadius: BorderRadius.circular(16.0), - ), - //labelText: 'Password', + //labelText: 'Password', + ), ), - ), - ) - ]); + ) + ]); + } } diff --git a/test/empresa_test.dart b/test/empresa_test.dart deleted file mode 100644 index a944443..0000000 --- a/test/empresa_test.dart +++ /dev/null @@ -1,89 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:organizei/components/botao.dart'; -import 'package:organizei/components/dialogs/login/entrarDialog.dart'; - -void main() { - group('LOGIN', () { - testWidgets('Email e CPF/CNPJ vazio', (WidgetTester tester) async { - await tester.pumpWidget( - MaterialApp( - home: Material( - child: Builder( - builder: (BuildContext context) { - return Botao( - key: Key("keyEntrarButton"), - texto: 'Entrar', - cor: const Color(0xFF74C198), - clicar: () { - print('aaaa'); - entrar(context); - }); - }, - ), - ), - ), - ); - //Entra no widget - - //Pressiona o botão de "Entrar" - await tester.tap(find.byKey(ValueKey("keyEntrarButton"))); - - //Atualiza o estado da tela - await tester.pump(); - - expect(find.text('e-mail'), findsOneWidget); - expect(find.text('senha'), findsOneWidget); - - //Verifica se ambas validações aparecem em tela - // expect(find.text('Informe o CPF/CNPJ'), findsOneWidget); - // expect(find.text('Informe o Email'), findsOneWidget); - }); - testWidgets('Senha vazia', (WidgetTester tester) async { - await tester.pumpWidget(MaterialApp( - home: Material( - child: Builder( - builder: (BuildContext context) { - return Botao( - key: Key("keyEntrarButton"), - texto: 'clicar', - cor: const Color(0xFF74C198), - clicar: () { - print('aaaa'); - entrar(context); - }); - }, - ), - ), - )); - - await tester.tap(find.byKey(ValueKey("keyEntrarButton"))); - await tester.pump(); - - await tester.enterText(find.text('nome'), "email@empresa.com"); - - // await tester.tap(find.byKey(ValueKey("BB"))); - - //await tester.enterText(find.byKey(ValueKey("BB")), "email@empresa.com"); - // await tester.tap(find.text('Entrar')); - //await tester.tap(find.byKey(ValueKey("BB"))); - //await tester.tap(find.text('Entrar')); - - // await tester.enterText( - // find.byKey(ValueKey("keyTextFieldEmail")), "email@empresa.com"); - - //await tester.enterText(find.text('e-mail'), "email@empresa.com"); - - // await tester.enterText( - // find.byKey(ValueKey("keyTextFieldEmail")), "email@empresa.com"); - // await tester.tap(find.byKey(ValueKey("keyEntrarButton"))); - // await tester.pump(); - // expect(find.text('Informe o CPF/CNPJ'), findsOneWidget); - // expect(find.text('Informe o Email'), findsNothing); - }); - - //Verifica se ambas validações aparecem em tela - // expect(find.text('Informe o CPF/CNPJ'), findsOneWidget); - // expect(find.text('Informe o Email'), findsOneWidget); - }); -} diff --git a/test/login_test.dart b/test/login_test.dart new file mode 100644 index 0000000..5849450 --- /dev/null +++ b/test/login_test.dart @@ -0,0 +1,91 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:organizei/components/botao.dart'; +import 'package:organizei/components/dialogs/login/entrarDialog.dart'; + +void main() { + group('LOGIN', () { + testWidgets('E-mail e senha vazios', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: Material( + child: Builder( + builder: (BuildContext context) { + return Botao( + key: Key("keyTesteButton"), + texto: 'Entrar', + cor: const Color(0xFF74C198), + clicar: () { + entrar(context); + }); + }, + ), + ), + ), + ); + + await tester.tap(find.byKey(ValueKey("keyTesteButton"))); + await tester.pump(); + await tester.ensureVisible(find.byKey(Key("keyEntrarButton"))); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(ValueKey("keyEntrarButton"))); + }); + + testWidgets('E-mail vazio', (WidgetTester tester) async { + await tester.pumpWidget(MaterialApp( + home: Material( + child: Builder( + builder: (BuildContext context) { + return Botao( + key: Key("keyTesteButton"), + texto: 'clicar', + cor: const Color(0xFF74C198), + clicar: () { + entrar(context); + }); + }, + ), + ), + )); + + await tester.tap(find.byKey(ValueKey("keyTesteButton"))); + await tester.pump(); + + await tester.ensureVisible(find.byKey(Key("keyEntrarButton"))); + await tester.pumpAndSettle(); + + await tester.enterText(find.byKey(ValueKey("keyTextSenha")), "senha"); + + await tester.tap(find.byKey(ValueKey("keyEntrarButton"))); + }); + + testWidgets('Senha vazia', (WidgetTester tester) async { + await tester.pumpWidget(MaterialApp( + home: Material( + child: Builder( + builder: (BuildContext context) { + return Botao( + key: Key("keyTesteButton"), + texto: 'clicar', + cor: const Color(0xFF74C198), + clicar: () { + entrar(context); + }); + }, + ), + ), + )); + + await tester.tap(find.byKey(ValueKey("keyTesteButton"))); + await tester.pump(); + + await tester.ensureVisible(find.byKey(Key("keyEntrarButton"))); + await tester.pumpAndSettle(); + + await tester.enterText( + find.byKey(ValueKey("keyTextEmail")), "email@organizei.com"); + + await tester.tap(find.byKey(ValueKey("keyEntrarButton"))); + }); + }); +}