mirror of
https://github.com/foss42/apidash.git
synced 2025-08-26 14:24:03 +08:00
hive updates
This commit is contained in:
@ -120,7 +120,7 @@ class DashApp extends ConsumerWidget {
|
||||
home: showWorkspaceSelector
|
||||
? WorkspaceSelector(
|
||||
onContinue: (val) async {
|
||||
await openBoxes(kIsDesktop, val);
|
||||
await initHiveBoxes(kIsDesktop, val);
|
||||
ref
|
||||
.read(settingsProvider.notifier)
|
||||
.update(workspaceFolderPath: val);
|
||||
|
@ -42,7 +42,7 @@ Future<bool> initApp(
|
||||
try {
|
||||
debugPrint("initializeUsingPath: $initializeUsingPath");
|
||||
debugPrint("workspaceFolderPath: ${settingsModel?.workspaceFolderPath}");
|
||||
final openBoxesStatus = await openBoxes(
|
||||
final openBoxesStatus = await initHiveBoxes(
|
||||
initializeUsingPath,
|
||||
settingsModel?.workspaceFolderPath,
|
||||
);
|
||||
|
@ -11,7 +11,7 @@ const String kHistoryMetaBox = "apidash-history-meta";
|
||||
const String kHistoryBoxIds = "historyIds";
|
||||
const String kHistoryLazyBox = "apidash-history-lazy";
|
||||
|
||||
Future<bool> openBoxes(
|
||||
Future<bool> initHiveBoxes(
|
||||
bool initializeUsingPath,
|
||||
String? workspaceFolderPath,
|
||||
) async {
|
||||
@ -25,23 +25,38 @@ Future<bool> openBoxes(
|
||||
} else {
|
||||
await Hive.initFlutter();
|
||||
}
|
||||
|
||||
await Hive.openBox(kDataBox);
|
||||
await Hive.openBox(kEnvironmentBox);
|
||||
await Hive.openBox(kHistoryMetaBox);
|
||||
await Hive.openLazyBox(kHistoryLazyBox);
|
||||
await openHiveBoxes();
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> openHiveBoxes() async {
|
||||
try {
|
||||
await Hive.openBox(kDataBox);
|
||||
await Hive.openBox(kEnvironmentBox);
|
||||
await Hive.openBox(kHistoryMetaBox);
|
||||
await Hive.openLazyBox(kHistoryLazyBox);
|
||||
} catch (e) {
|
||||
debugPrint("ERROR OPEN HIVE BOXES: $e");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> clearHiveBoxes() async {
|
||||
try {
|
||||
await Hive.box(kDataBox).clear();
|
||||
await Hive.box(kEnvironmentBox).clear();
|
||||
await Hive.box(kHistoryMetaBox).clear();
|
||||
await Hive.lazyBox(kHistoryLazyBox).clear();
|
||||
if (Hive.isBoxOpen(kDataBox)) {
|
||||
await Hive.box(kDataBox).clear();
|
||||
}
|
||||
if (Hive.isBoxOpen(kEnvironmentBox)) {
|
||||
await Hive.box(kEnvironmentBox).clear();
|
||||
}
|
||||
if (Hive.isBoxOpen(kHistoryMetaBox)) {
|
||||
await Hive.box(kHistoryMetaBox).clear();
|
||||
}
|
||||
if (Hive.isBoxOpen(kHistoryLazyBox)) {
|
||||
await Hive.lazyBox(kHistoryLazyBox).clear();
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint("ERROR CLEAR HIVE BOXES: $e");
|
||||
}
|
||||
@ -49,10 +64,19 @@ Future<void> clearHiveBoxes() async {
|
||||
|
||||
Future<void> deleteHiveBoxes() async {
|
||||
try {
|
||||
await Hive.box(kDataBox).deleteFromDisk();
|
||||
await Hive.box(kEnvironmentBox).deleteFromDisk();
|
||||
await Hive.box(kHistoryMetaBox).deleteFromDisk();
|
||||
await Hive.lazyBox(kHistoryLazyBox).deleteFromDisk();
|
||||
if (Hive.isBoxOpen(kDataBox)) {
|
||||
await Hive.box(kDataBox).deleteFromDisk();
|
||||
}
|
||||
if (Hive.isBoxOpen(kEnvironmentBox)) {
|
||||
await Hive.box(kEnvironmentBox).deleteFromDisk();
|
||||
}
|
||||
if (Hive.isBoxOpen(kHistoryMetaBox)) {
|
||||
await Hive.box(kHistoryMetaBox).deleteFromDisk();
|
||||
}
|
||||
if (Hive.isBoxOpen(kHistoryLazyBox)) {
|
||||
await Hive.lazyBox(kHistoryLazyBox).deleteFromDisk();
|
||||
}
|
||||
await Hive.close();
|
||||
} catch (e) {
|
||||
debugPrint("ERROR DELETE HIVE BOXES: $e");
|
||||
}
|
||||
|
@ -8,7 +8,11 @@ import 'package:apidash/providers/providers.dart';
|
||||
import 'helpers.dart';
|
||||
|
||||
void main() async {
|
||||
setUp(() async => await testSetUp());
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setUp(() async {
|
||||
await testSetUpTempDirForHive();
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'Request method changes from GET to POST when body is added and Snackbar is shown',
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'dart:io';
|
||||
import 'package:apidash/services/hive_services.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
@ -23,10 +24,9 @@ ProviderContainer createContainer({
|
||||
return container;
|
||||
}
|
||||
|
||||
Future<void> testSetUp() async {
|
||||
Future<void> testSetUpForHive() async {
|
||||
// override path_provider methodCall to point
|
||||
// path to temporary location for all unit tests
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
const MethodChannel channel =
|
||||
MethodChannel('plugins.flutter.io/path_provider');
|
||||
|
||||
@ -35,7 +35,23 @@ Future<void> testSetUp() async {
|
||||
return './test-hive-storage/';
|
||||
});
|
||||
|
||||
await openBoxes(false, null);
|
||||
await deleteHiveBoxes();
|
||||
await openBoxes(false, null);
|
||||
await initHiveBoxes(false, null);
|
||||
// await deleteHiveBoxes();
|
||||
// await openHiveBoxes();
|
||||
}
|
||||
|
||||
Future<void> testSetUpTempDirForHive() async {
|
||||
const MethodChannel channel =
|
||||
MethodChannel('plugins.flutter.io/path_provider');
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
|
||||
if (methodCall.method == 'getApplicationDocumentsDirectory') {
|
||||
// Create a mock app doc directory for testing
|
||||
Directory tempDir =
|
||||
await Directory.systemTemp.createTemp('mock_app_doc_dir');
|
||||
return tempDir.path; // Return the path to the mock directory
|
||||
}
|
||||
return null;
|
||||
});
|
||||
await initHiveBoxes(false, null);
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
import 'dart:io';
|
||||
//import 'package:spot/spot.dart';
|
||||
import 'package:apidash/providers/providers.dart';
|
||||
import 'package:apidash/screens/common_widgets/common_widgets.dart';
|
||||
@ -12,7 +11,6 @@ import 'package:apidash/screens/home_page/editor_pane/url_card.dart';
|
||||
import 'package:apidash/screens/home_page/home_page.dart';
|
||||
import 'package:apidash/screens/settings_page.dart';
|
||||
import 'package:apidash/screens/history/history_page.dart';
|
||||
import 'package:apidash/services/hive_services.dart';
|
||||
import 'package:apidash/widgets/widgets.dart';
|
||||
import 'package:extended_text_field/extended_text_field.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -22,24 +20,13 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import '../extensions/widget_tester_extensions.dart';
|
||||
import '../test_consts.dart';
|
||||
import 'helpers.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setUp(() async {
|
||||
const MethodChannel channel =
|
||||
MethodChannel('plugins.flutter.io/path_provider');
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
|
||||
if (methodCall.method == 'getApplicationDocumentsDirectory') {
|
||||
// Create a mock app doc directory for testing
|
||||
Directory tempDir =
|
||||
await Directory.systemTemp.createTemp('mock_app_doc_dir');
|
||||
return tempDir.path; // Return the path to the mock directory
|
||||
}
|
||||
return null;
|
||||
});
|
||||
await openBoxes(false, null);
|
||||
await testSetUpTempDirForHive();
|
||||
final flamante = rootBundle.load('google_fonts/OpenSans-Medium.ttf');
|
||||
final fontLoader = FontLoader('OpenSans')..addFont(flamante);
|
||||
await fontLoader.load();
|
||||
|
Reference in New Issue
Block a user