From cd9af13e2719e8e19b7c48e8cd4766fc58149a15 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 20 May 2022 23:34:02 +1000 Subject: [PATCH] Adds an initial unit test --- pubspec.lock | 196 +++++++++++++++++++++++++++++++++++++++--- pubspec.yaml | 7 +- test/api_test.dart | 45 ++++++++++ test/widget_test.dart | 6 +- 4 files changed, 234 insertions(+), 20 deletions(-) create mode 100644 test/api_test.dart diff --git a/pubspec.lock b/pubspec.lock index 4fb3ba92..a418a5b4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,6 +1,20 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "40.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + url: "https://pub.dartlang.org" + source: hosted + version: "4.1.0" archive: dependency: transitive description: @@ -113,6 +127,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.15.0" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" + coverage: + dependency: transitive + description: + name: coverage + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.2" cross_file: dependency: transitive description: @@ -190,13 +218,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.6.3" - fake_async: - dependency: transitive - description: - name: fake_async - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" ffi: dependency: transitive description: @@ -263,11 +284,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.5" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" flutter_web_plugins: dependency: transitive description: flutter @@ -280,6 +296,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "9.2.0" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" + glob: + dependency: transitive + description: + name: glob + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" http: dependency: "direct main" description: @@ -287,6 +317,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.13.4" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + url: "https://pub.dartlang.org" + source: hosted + version: "3.2.0" http_parser: dependency: transitive description: @@ -336,6 +373,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.17.0" + io: + dependency: transitive + description: + name: io + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" js: dependency: transitive description: @@ -350,6 +394,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.2" + logging: + dependency: transitive + description: + name: logging + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" markdown: dependency: transitive description: @@ -378,6 +429,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.7.0" + mime: + dependency: transitive + description: + name: mime + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" + node_preamble: + dependency: transitive + description: + name: node_preamble + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" octo_image: dependency: transitive description: @@ -399,6 +464,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.2.1" + package_config: + dependency: transitive + description: + name: package_config + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" package_info_plus: dependency: "direct main" description: @@ -525,6 +597,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.2" + pool: + dependency: transitive + description: + name: pool + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.0" process: dependency: transitive description: @@ -532,6 +611,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "4.2.4" + pub_semver: + dependency: transitive + description: + name: pub_semver + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" qr_code_scanner: dependency: "direct main" description: @@ -630,6 +716,34 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + shelf: + dependency: transitive + description: + name: shelf + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.0" + shelf_packages_handler: + dependency: transitive + description: + name: shelf_packages_handler + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" + shelf_static: + dependency: transitive + description: + name: shelf_static + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" sky_engine: dependency: transitive description: flutter @@ -642,6 +756,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.2.5" + source_map_stack_trace: + dependency: transitive + description: + name: source_map_stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + source_maps: + dependency: transitive + description: + name: source_maps + url: "https://pub.dartlang.org" + source: hosted + version: "0.10.10" source_span: dependency: transitive description: @@ -705,13 +833,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.2.0" + test: + dependency: "direct dev" + description: + name: test + url: "https://pub.dartlang.org" + source: hosted + version: "1.21.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.8" + version: "0.4.9" + test_core: + dependency: transitive + description: + name: test_core + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.13" typed_data: dependency: transitive description: @@ -789,6 +931,34 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.1" + vm_service: + dependency: transitive + description: + name: vm_service + url: "https://pub.dartlang.org" + source: hosted + version: "8.3.0" + watcher: + dependency: transitive + description: + name: watcher + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0" + webkit_inspection_protocol: + dependency: transitive + description: + name: webkit_inspection_protocol + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" win32: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 9031ea5d..7489e150 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -38,10 +38,9 @@ dependencies: url_launcher: ^6.0.9 # Open link in system browser dev_dependencies: - flutter_launcher_icons: - flutter_test: - sdk: flutter - lint: ^1.0.0 + flutter_launcher_icons: ^0.9.0 + lint: ^1.8.0 + test: ^1.21.0 flutter_icons: android: true diff --git a/test/api_test.dart b/test/api_test.dart new file mode 100644 index 00000000..36baa7fc --- /dev/null +++ b/test/api_test.dart @@ -0,0 +1,45 @@ +/* + * Unit tests for the API class + */ + +import 'package:test/test.dart'; + +import 'package:inventree/api.dart'; +import 'package:inventree/user_profile.dart'; + +void main() { + + setUp(() async { + // Ensure we have a user profile available + // This profile will match the dockerized InvenTree setup, running locally + + print("Creating user profile"); + await UserProfileDBManager().addProfile(UserProfile( + username: "testuser", + password: "testpassword""", + server: "http://localhost:12345", + selected: true, + )); + + final profiles = await UserProfileDBManager().getAllProfiles(); + + // Ensure we have one profile available + expect(profiles.length, equals(1)); + + // Select the profile + await UserProfileDBManager().selectProfile(profiles.first.key ?? 1); + + }); + + test("Select Profile", () async { + // Ensure that we can select a user profile + final prf = await UserProfileDBManager().getSelectedProfile(); + + expect(prf, isNot(null)); + + expect(prf?.username, equals("testuser")); + expect(prf?.password, equals("testpassword")); + expect(prf?.server, equals("http://localhost:12345")); + }); + +} \ No newline at end of file diff --git a/test/widget_test.dart b/test/widget_test.dart index 3c73102a..4e838ac5 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -5,9 +5,9 @@ // 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_test/flutter_test.dart"; +// import "package:flutter_test/flutter_test.dart"; void main() { - testWidgets("Counter increments smoke test", (WidgetTester tester) async { - }); + // testWidgets("Counter increments smoke test", (WidgetTester tester) async { + // }); }