Skip to content

Commit

Permalink
add Favorite actions provider tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Jun 4, 2024
1 parent 7b67551 commit 261855a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/Backend/favorite_actions_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart' as flTest;
import 'package:flutter_test/flutter_test.dart';
import 'package:tail_app/Backend/Definitions/Action/base_action.dart';
import 'package:tail_app/Backend/favorite_actions.dart';
import 'package:tail_app/Backend/sensors.dart';

import '../testing_utils/hive_utils.dart';

void main() {
setUp(() async {
flTest.TestWidgetsFlutterBinding.ensureInitialized();
await setupHive();
});
tearDown(() async {
await deleteHive();
});
test('Create Favorite', () async {
final container = ProviderContainer(
overrides: [],
);
BaseAction? baseAction = container.read(getActionFromUUIDProvider('c53e980e-899e-4148-a13e-f57a8f9707f4'));
expect(baseAction != null, true);
await container.read(favoriteActionsProvider.notifier).add(baseAction!);
expect(container.read(favoriteActionsProvider).length, 1);
expect(container.read(favoriteActionsProvider).first.actionUUID, 'c53e980e-899e-4148-a13e-f57a8f9707f4');

// force re-open of provider

container.invalidate(favoriteActionsProvider);
expect(container.read(favoriteActionsProvider).length, 1);
expect(container.read(favoriteActionsProvider).first.actionUUID, 'c53e980e-899e-4148-a13e-f57a8f9707f4');

// remove
await container.read(favoriteActionsProvider.notifier).remove(baseAction);
expect(container.read(favoriteActionsProvider).length, 0);
});
}

0 comments on commit 261855a

Please sign in to comment.