Skip to content

Commit

Permalink
refactor: dart format & minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jhomlala committed Jul 3, 2024
1 parent 9c4f4ca commit 6c0731b
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 70 deletions.
5 changes: 3 additions & 2 deletions packages/alice/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 1.0.0-dev.9
* Added tests.
* General code refactor.
* Added unit tests.
* Updated CI/CD task for tests.
* General overhaul of code base.

# 1.0.0-dev.8
* Added storage abstractions (by Klemen Tusar https://github.com/techouse).
Expand Down
1 change: 0 additions & 1 deletion packages/alice/lib/alice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class Alice {
/// Navigator key used for navigating to inspector
GlobalKey<NavigatorState>? _navigatorKey;


/// Creates alice instance.
Alice({
GlobalKey<NavigatorState>? navigatorKey,
Expand Down
2 changes: 1 addition & 1 deletion packages/alice/lib/core/alice_logger.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'dart:io' show Process, ProcessResult;
import 'dart:io' show Process, ProcessResult;

import 'package:alice/helper/operating_system.dart';
import 'package:alice/model/alice_log.dart';
Expand Down
2 changes: 0 additions & 2 deletions packages/alice/lib/core/alice_memory_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class AliceMemoryStorage implements AliceStorage {

final BehaviorSubject<List<AliceHttpCall>> callsSubject;


@override
Stream<List<AliceHttpCall>> get callsStream => callsSubject.stream;

Expand Down Expand Up @@ -105,5 +104,4 @@ class AliceMemoryStorage implements AliceStorage {
@override
AliceHttpCall? selectCall(int requestId) => callsSubject.value
.firstWhereOrNull((AliceHttpCall call) => call.id == requestId);

}
2 changes: 0 additions & 2 deletions packages/alice/lib/model/alice_http_call.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


import 'package:alice/model/alice_http_error.dart';
import 'package:alice/model/alice_http_request.dart';
import 'package:alice/model/alice_http_response.dart';
Expand Down
1 change: 0 additions & 1 deletion packages/alice/lib/model/alice_http_error.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import 'package:equatable/equatable.dart';

/// Definition of http error data holder.
Expand Down
3 changes: 1 addition & 2 deletions packages/alice/lib/model/alice_http_request.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import 'dart:io' show Cookie;

import 'package:alice/model/alice_form_data_file.dart';
Expand All @@ -9,7 +8,7 @@ import 'package:equatable/equatable.dart';
class AliceHttpRequest with EquatableMixin {
int size = 0;
DateTime time = DateTime.now();
Map<String,String> headers = <String,String>{};
Map<String, String> headers = <String, String>{};
dynamic body = '';
String? contentType = '';
List<Cookie> cookies = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class _AliceCallDetailsPageState extends State<AliceCallDetailsPage>
? FloatingActionButton(
backgroundColor: AliceTheme.lightRed,
key: const Key('share_key'),
onPressed: () async => _shareCall(),
onPressed: _shareCall,
child: const Icon(
Icons.share,
color: AliceTheme.white,
Expand Down
47 changes: 22 additions & 25 deletions packages/alice/lib/ui/calls_list/page/alice_calls_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -273,31 +273,28 @@ class _AliceCallsListPageState extends State<AliceCallsListPage>
OperatingSystem.isAndroid() ? OpenFilex.open(result.path) : null,
);
} else {
var title = "";
var description = "";
switch (result.error) {
case AliceExportResultError.logGenerate:
title =
context.i18n(AliceTranslationKey.saveDialogPermissionErrorTitle);
description = context
.i18n(AliceTranslationKey.saveDialogPermissionErrorDescription);

case AliceExportResultError.empty:
title = context.i18n(AliceTranslationKey.saveDialogEmptyErrorTitle);
description =
context.i18n(AliceTranslationKey.saveDialogEmptyErrorDescription);
case AliceExportResultError.permission:
title =
context.i18n(AliceTranslationKey.saveDialogPermissionErrorTitle);
description = context
.i18n(AliceTranslationKey.saveDialogPermissionErrorDescription);
case AliceExportResultError.file:
title =
context.i18n(AliceTranslationKey.saveDialogFileSaveErrorTitle);
description = context
.i18n(AliceTranslationKey.saveDialogFileSaveErrorDescription);
default:
}
final [String title, String description] = switch (result.error) {
AliceExportResultError.logGenerate => [
context.i18n(AliceTranslationKey.saveDialogPermissionErrorTitle),
context
.i18n(AliceTranslationKey.saveDialogPermissionErrorDescription),
],
AliceExportResultError.empty => [
context.i18n(AliceTranslationKey.saveDialogEmptyErrorTitle),
context.i18n(AliceTranslationKey.saveDialogEmptyErrorDescription),
],
AliceExportResultError.permission => [
context.i18n(AliceTranslationKey.saveDialogPermissionErrorTitle),
context
.i18n(AliceTranslationKey.saveDialogPermissionErrorDescription),
],
AliceExportResultError.file => [
context.i18n(AliceTranslationKey.saveDialogFileSaveErrorTitle),
context
.i18n(AliceTranslationKey.saveDialogFileSaveErrorDescription),
],
_ => ["", ""],
};

AliceGeneralDialog.show(
context: context,
Expand Down
2 changes: 1 addition & 1 deletion packages/alice/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: alice
description: Alice is an HTTP Inspector tool which helps debugging http requests. It catches and stores http requests and responses, which can be viewed via simple UI.
version: 1.0.0-dev.8
version: 1.0.0-dev.9
homepage: https://github.com/jhomlala/alice
repository: https://github.com/jhomlala/alice

Expand Down
10 changes: 8 additions & 2 deletions packages/alice/test/core/alice_logger_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ void main() {
});

test("should clear logs", () {
final logs = [AliceLog(message: "test"), AliceLog(message: "test2"),];
final logs = [
AliceLog(message: "test"),
AliceLog(message: "test2"),
];

aliceLogger.addAll(logs);

Expand All @@ -39,7 +42,10 @@ void main() {
});

test("should set maximum size", () {
final logs = [AliceLog(message: "test"), AliceLog(message: "test2"),];
final logs = [
AliceLog(message: "test"),
AliceLog(message: "test2"),
];

aliceLogger.addAll(logs);

Expand Down
1 change: 0 additions & 1 deletion packages/alice/test/core/alice_memory_storage_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,5 @@ void main() {
test("should return null if call doesn't exist", () {
expect(null, storage.selectCall(1));
});

});
}
11 changes: 5 additions & 6 deletions packages/alice/test/helper/alice_conversion_helper_test.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:alice/helper/alice_conversion_helper.dart';
import 'package:test/test.dart';

void main(){
group("AliceConversionHelper", (){
test("should format bytes", (){
void main() {
group("AliceConversionHelper", () {
test("should format bytes", () {
expect(AliceConversionHelper.formatBytes(-100), "-1 B");
expect(AliceConversionHelper.formatBytes(0), "0 B");
expect(AliceConversionHelper.formatBytes(100), "100 B");
Expand All @@ -16,8 +16,7 @@ void main(){
expect(AliceConversionHelper.formatBytes(100000000), "100.00 MB");
});


test("should format time", (){
test("should format time", () {
expect(AliceConversionHelper.formatTime(-100), "-1 ms");
expect(AliceConversionHelper.formatTime(0), "0 ms");
expect(AliceConversionHelper.formatTime(100), "100 ms");
Expand All @@ -29,4 +28,4 @@ void main(){
expect(AliceConversionHelper.formatTime(85000), "1 min 25 s 0 ms");
});
});
}
}
4 changes: 1 addition & 3 deletions packages/alice/test/mock/alice_logger_mock.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:alice/core/alice_logger.dart';
import 'package:mocktail/mocktail.dart';

class AliceLoggerMock extends Mock implements AliceLogger{

}
class AliceLoggerMock extends Mock implements AliceLogger {}
4 changes: 1 addition & 3 deletions packages/alice/test/mock/alice_storage_mock.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:alice/core/alice_storage.dart';
import 'package:mocktail/mocktail.dart';

class AliceStorageMock extends Mock implements AliceStorage{

}
class AliceStorageMock extends Mock implements AliceStorage {}
2 changes: 1 addition & 1 deletion packages/alice/test/mock/build_context_mock.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:flutter/material.dart';
import 'package:mocktail/mocktail.dart';

class BuildContextMock extends Mock implements BuildContext {}
class BuildContextMock extends Mock implements BuildContext {}
1 change: 0 additions & 1 deletion packages/alice_objectbox/lib/alice_objectbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class AliceObjectBox implements AliceStorage {
@override
Future<void> removeCalls() => _store.httpCalls.removeAllAsync();


@override
AliceStats getStats() => (
total: _store.httpCalls.count(),
Expand Down
30 changes: 15 additions & 15 deletions packages/alice_objectbox/lib/model/cached_alice_http_call.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,21 @@ class CachedAliceHttpCall implements AliceHttpCall {
}

@override
List<Object?> get props => [
id,
createdTime,
client,
loading,
secure,
method,
endpoint,
server,
uri,
duration,
request,
response,
error
];
List<Object?> get props => [
id,
createdTime,
client,
loading,
secure,
method,
endpoint,
server,
uri,
duration,
request,
response,
error
];

@override
bool? get stringify => true;
Expand Down

0 comments on commit 6c0731b

Please sign in to comment.