Hive adapter + testing

This commit is contained in:
andrei
2021-12-02 10:27:02 -05:00
parent 98942b231b
commit 5e532a132a
14 changed files with 484 additions and 14 deletions

45
test/box_test.dart Normal file
View File

@@ -0,0 +1,45 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:boxchecker/data_util.dart' as data;
import 'package:hive/hive.dart';
void main() {
Hive.init("lists");
Hive.registerAdapter(data.ListAdapter());
Hive.registerAdapter(data.CheckAdapter());
test('opening box', () async {
var box = await Hive.openBox<data.List>("lists");
expect(box, isNotNull);
box.close();
});
test('adding lists to box', () async {
var box = await Hive.openBox<data.List>("lists");
await box.clear();
expect(box.length, 0);
final data.List list = data.List("test_list");
box.add(list);
expect(box.length, 1);
var l = box.get(0);
expect(l, isNotNull);
box.close();
});
test('adding chekcs to lists', () async {
var box = await Hive.openBox<data.List>("lists");
var l = box.get(0);
expect(l, isNotNull);
expect(l!.checks, isEmpty);
//print(l.checks);
l.checks.add(data.Check("test Check", false));
expect(l.checks, isNotEmpty);
var l2 = box.get(0);
expect(l2, isNotNull);
expect(l2!.checks, isNotEmpty);
});
}

BIN
test/test.hive Normal file

Binary file not shown.

0
test/test.lock Normal file
View File

View File

@@ -11,20 +11,14 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:boxchecker/box_checker.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
testWidgets('swaping tabs', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
await tester.pumpWidget(const BoxChecker());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
expect(find.text('test list'), findsOneWidget);
expect(find.text('test template'), 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);
tester.tap(find.byIcon(Icons.list_alt));
});
}