Skip to content

Commit

Permalink
feat: updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jhomlala committed Jul 3, 2024
1 parent a9c80af commit 111cb8a
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 3 deletions.
84 changes: 84 additions & 0 deletions packages/alice/test/alice_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import 'package:alice/alice.dart';
import 'package:alice/core/alice_adapter.dart';
import 'package:alice/core/alice_logger.dart';
import 'package:alice/core/alice_storage.dart';
import 'package:alice/model/alice_configuration.dart';
import 'package:alice/model/alice_http_call.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

import 'mock/mocked_data.dart';

void main() {
group("Alice", () {
late Alice alice;
late AliceStorage aliceStorage;
late AliceLogger aliceLogger;
setUp(() {
aliceStorage = AliceMemoryStorage(maxCallsCount: 1000);
aliceLogger = AliceLogger(maximumSize: 1000);
alice = Alice(
configuration: AliceConfiguration(
showInspectorOnShake: false,
showNotification: false,
logger: aliceLogger,
storage: aliceStorage,
),
);
});

test("should set new navigator key", () {
final navigatorKey = GlobalKey<NavigatorState>();

expect(alice.getNavigatorKey() != navigatorKey, true);

alice.setNavigatorKey(navigatorKey);

expect(alice.getNavigatorKey() == navigatorKey, true);
});

test("should add log", () {
final log = AliceLog(message: "test");

alice.addLog(log);

expect(aliceLogger.logs, [log]);
});

test("should add logs", () {
final logs = [AliceLog(message: "test 1"), AliceLog(message: "test 2")];

alice.addLogs(logs);

expect(aliceLogger.logs, logs);
});

test("should add call", () {
final call = MockedData.getFilledHttpCall();

alice.addHttpCall(call);

expect(aliceStorage.getCalls(), [call]);
});

test("should add adapter", () {
final call = MockedData.getFilledHttpCall();
final adapter = FakeAdapter();
alice.addAdapter(adapter);

adapter.addCallLog(call);

expect(aliceStorage.getCalls(), [call]);
});

test("should return is inspector opened flag", () {
expect(alice.isInspectorOpened, false);
});
});
}

class FakeAdapter with AliceAdapter {
void addCallLog(AliceHttpCall call) {
aliceCore.addCall(call);
}
}
2 changes: 1 addition & 1 deletion packages/alice/test/core/alice_core_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:mocktail/mocktail.dart';

import '../mock/alice_logger_mock.dart';
import '../mock/alice_storage_mock.dart';
import '../mocked_data.dart';
import '../mock/mocked_data.dart';

void main() {
late AliceCore aliceCore;
Expand Down
2 changes: 1 addition & 1 deletion packages/alice/test/core/alice_memory_storage_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:alice/model/alice_http_response.dart';
import 'package:test/expect.dart';
import 'package:test/scaffolding.dart';

import '../mocked_data.dart';
import '../mock/mocked_data.dart';

void main() {
late AliceMemoryStorage storage;
Expand Down
2 changes: 1 addition & 1 deletion packages/alice/test/helper/alice_export_helper_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:package_info_plus/package_info_plus.dart';

import '../mock/build_context_mock.dart';
import '../mocked_data.dart';
import '../mock/mocked_data.dart';

void main() {
late BuildContext context;
Expand Down
File renamed without changes.

0 comments on commit 111cb8a

Please sign in to comment.