From 1c214328bceeebd79d48b9bc80618c8060acaa1b Mon Sep 17 00:00:00 2001 From: Bruno Gabriel dos Santos Date: Wed, 30 Oct 2024 12:43:04 -0300 Subject: [PATCH] test: add application cache unit test --- pokedex/pubspec.yaml | 1 + .../test/cache/application_cache_test.dart | 18 +++++++++++ pokedex/test/widget_test.dart | 30 ------------------- 3 files changed, 19 insertions(+), 30 deletions(-) create mode 100644 pokedex/test/cache/application_cache_test.dart delete mode 100644 pokedex/test/widget_test.dart diff --git a/pokedex/pubspec.yaml b/pokedex/pubspec.yaml index 4a58dd3..d3c3d42 100644 --- a/pokedex/pubspec.yaml +++ b/pokedex/pubspec.yaml @@ -34,6 +34,7 @@ dev_dependencies: build_runner: ^2.4.6 freezed: ^2.4.1 json_serializable: ^6.7.1 + mocktail: ^1.0.4 flutter: uses-material-design: true diff --git a/pokedex/test/cache/application_cache_test.dart b/pokedex/test/cache/application_cache_test.dart new file mode 100644 index 0000000..9781155 --- /dev/null +++ b/pokedex/test/cache/application_cache_test.dart @@ -0,0 +1,18 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:pokedex_flutter/cache/application_cache.dart'; + +void main() { + late ApplicationCache applicationCache; + + setUp(() { + applicationCache = MemoryCacheImpl(); + }); + + test( + 'should save data ' + 'in memory', () { + final dynamic = {'object': 'value'}; + applicationCache.putValue('key', dynamic); + expect(applicationCache.getValue('key'), dynamic); + }); +} diff --git a/pokedex/test/widget_test.dart b/pokedex/test/widget_test.dart deleted file mode 100644 index 9ae0677..0000000 --- a/pokedex/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 in the flutter_test package. 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:pokedex_flutter/main.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(const PokemonApplication()); - - // 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); - }); -}