From 5894197710a9fcd84a08a4bb6966c88f4a135111 Mon Sep 17 00:00:00 2001 From: Willian <47341070+wjrcode@users.noreply.github.com> Date: Wed, 19 Oct 2022 17:59:36 -0300 Subject: [PATCH] testes --- .vscode/launch.json | 25 ++++++ lib/Controller/UsuarioController.dart | 1 + lib/Model/API/APIModel.dart | 4 +- .../dialogs/login/entrarDialog.dart | 4 + test/empresa_test.dart | 89 +++++++++++++++++++ test/widget_test.dart | 30 ------- 6 files changed, 121 insertions(+), 32 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 test/empresa_test.dart delete mode 100644 test/widget_test.dart diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..96c72d8 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,25 @@ +{ + // Use o IntelliSense para saber mais sobre os atributos possíveis. + // Focalizar para exibir as descrições dos atributos existentes. + // Para obter mais informações, acesse: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "organizei-mobile", + "request": "launch", + "type": "dart" + }, + { + "name": "organizei-mobile (profile mode)", + "request": "launch", + "type": "dart", + "flutterMode": "profile" + }, + { + "name": "organizei-mobile (release mode)", + "request": "launch", + "type": "dart", + "flutterMode": "release" + } + ] +} \ No newline at end of file diff --git a/lib/Controller/UsuarioController.dart b/lib/Controller/UsuarioController.dart index ad00def..ecd6b90 100644 --- a/lib/Controller/UsuarioController.dart +++ b/lib/Controller/UsuarioController.dart @@ -38,6 +38,7 @@ class UsuarioController extends Base { try { if (model.id == null) { + print('a'); return await repository.addUsuario(model).then((value) { ScaffoldMessenger.of(context).showSnackBar(SnackBar( elevation: 6.0, diff --git a/lib/Model/API/APIModel.dart b/lib/Model/API/APIModel.dart index 0958137..fe5582e 100644 --- a/lib/Model/API/APIModel.dart +++ b/lib/Model/API/APIModel.dart @@ -7,11 +7,11 @@ class ApiModel { Future> getHeaders() async { SharedPreferences prefs = await SharedPreferences.getInstance(); - String? token = prefs.getString('UsuarioToken'); + String token = prefs.getString('UsuarioToken') ?? ''; Map headers = { "Content-Type": "application/json", - "Authorization": "Bearer " + token! + "Authorization": "Bearer " + token }; return headers; } diff --git a/lib/components/dialogs/login/entrarDialog.dart b/lib/components/dialogs/login/entrarDialog.dart index b9f559d..1db3f92 100644 --- a/lib/components/dialogs/login/entrarDialog.dart +++ b/lib/components/dialogs/login/entrarDialog.dart @@ -12,6 +12,8 @@ Future entrar(BuildContext context) { loginController = LoginController(LoginRepository(), context); + print('chmei'); + return showDialog( barrierDismissible: false, barrierColor: Colors.white.withOpacity(0), @@ -58,9 +60,11 @@ Future entrar(BuildContext context) { Padding( padding: const EdgeInsets.fromLTRB(0, 0, 0, 16.0), child: Botao( + key: Key("BB"), texto: 'Entrar', cor: const Color(0xFF6BC8E4), clicar: () async { + print('over'); bool succes = await loginController.autentica(); diff --git a/test/empresa_test.dart b/test/empresa_test.dart new file mode 100644 index 0000000..a944443 --- /dev/null +++ b/test/empresa_test.dart @@ -0,0 +1,89 @@ +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/widget_test.dart b/test/widget_test.dart deleted file mode 100644 index d3d0ed2..0000000 --- a/test/widget_test.dart +++ /dev/null @@ -1,30 +0,0 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility that Flutter provides. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -//import 'package:organizei/main.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - //await tester.pumpWidget(const MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); -}