mirror of
https://github.com/hanskokx/arcane_framework.git
synced 2026-08-12 06:10:55 +02:00
0078e344fd
* Update Logging feature to replace @LoggingFeature annotation with LoggerName mixin for runtime accessibility Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com> * Bump version to 2.0.2 in pubspec.yaml and update CHANGELOG to reflect the new version Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com> * Add migration steps for replacing @LoggingFeature annotation with LoggerName mixin in CHANGELOG Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com> * Fix class declaration in migration example for LoggerName mixin Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com> * Enhance CI workflow, coverage enforcement, and environment tests (#10) * Enhance CI workflow and coverage enforcement; update tests and add new environment tests Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com> * Revert version bump in pubspec.yaml and remove test coverage note from CHANGELOG Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com> * Update test to expect a thrown exception when no interfaces are registered Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com> * Add ArcaneEnvironmentModeController and related tests for debug mode management Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com> * Refactor theme switcher tests to use platform dispatcher for brightness change simulation Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com> --------- Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com> * refactor(api): Remove export of Error and Ok from result_monad (#11) The `Error` and `Ok` symbols from the `result_monad` package are no longer re-exported directly by `arcane_framework`. Consumers needing these symbols must now explicitly import them from `package:result_monad`. This clarifies dependency ownership and reduces `arcane_framework`'s public API surface. --------- Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
225 lines
6.2 KiB
Dart
225 lines
6.2 KiB
Dart
import "package:arcane_framework/arcane_framework.dart";
|
|
import "package:flutter/material.dart";
|
|
import "package:flutter_test/flutter_test.dart";
|
|
|
|
void main() {
|
|
group("ArcaneEnvironment", () {
|
|
setUp(() {
|
|
Arcane.environment.reset();
|
|
});
|
|
|
|
testWidgets("maybeOf returns null without provider", (tester) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Builder(
|
|
builder: (context) {
|
|
expect(ArcaneEnvironment.maybeOf(context), isNull);
|
|
return const SizedBox();
|
|
},
|
|
),
|
|
),
|
|
);
|
|
});
|
|
|
|
testWidgets("of throws without provider", (tester) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Builder(
|
|
builder: (context) {
|
|
expect(
|
|
() => ArcaneEnvironment.of(context),
|
|
throwsA(isA<StateError>()),
|
|
);
|
|
return const SizedBox();
|
|
},
|
|
),
|
|
),
|
|
);
|
|
});
|
|
|
|
test("updateShouldNotify changes only when environment changes", () {
|
|
final normalA = ArcaneEnvironment(
|
|
environment: Environment.normal,
|
|
switchEnvironment: (_) {},
|
|
child: const SizedBox(),
|
|
);
|
|
final normalB = ArcaneEnvironment(
|
|
environment: Environment.normal,
|
|
switchEnvironment: (_) {},
|
|
child: const SizedBox(),
|
|
);
|
|
final debug = ArcaneEnvironment(
|
|
environment: Environment.debug,
|
|
switchEnvironment: (_) {},
|
|
child: const SizedBox(),
|
|
);
|
|
|
|
expect(normalA.updateShouldNotify(normalB), isFalse);
|
|
expect(debug.updateShouldNotify(normalB), isTrue);
|
|
});
|
|
});
|
|
|
|
group("ArcaneEnvironmentProvider", () {
|
|
setUp(() {
|
|
Arcane.environment.reset();
|
|
});
|
|
|
|
testWidgets("uses widget initial environment on init", (tester) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: ArcaneEnvironmentProvider(
|
|
environment: Environment.debug,
|
|
child: Builder(
|
|
builder: (context) {
|
|
final env = ArcaneEnvironment.of(context);
|
|
expect(env.environment, Environment.debug);
|
|
expect(env.current, Environment.debug);
|
|
return const SizedBox();
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
});
|
|
|
|
testWidgets("setEnvironment updates service and inherited widget",
|
|
(tester) async {
|
|
late BuildContext capturedContext;
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: ArcaneEnvironmentProvider(
|
|
child: Builder(
|
|
builder: (context) {
|
|
capturedContext = context;
|
|
return const SizedBox();
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
ArcaneEnvironment.of(capturedContext).setEnvironment(Environment.debug);
|
|
await tester.pump();
|
|
expect(Arcane.environment.current, Environment.debug);
|
|
});
|
|
|
|
testWidgets("enableDebugMode and disableDebugMode proxy correctly",
|
|
(tester) async {
|
|
late BuildContext capturedContext;
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: ArcaneEnvironmentProvider(
|
|
child: Builder(
|
|
builder: (context) {
|
|
capturedContext = context;
|
|
return const SizedBox();
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
ArcaneEnvironment.of(capturedContext).enableDebugMode();
|
|
await tester.pump();
|
|
expect(Arcane.environment.current, Environment.debug);
|
|
|
|
ArcaneEnvironment.of(capturedContext).disableDebugMode();
|
|
await tester.pump();
|
|
expect(Arcane.environment.current, Environment.normal);
|
|
});
|
|
|
|
testWidgets("provider rebuilds when service environment changes",
|
|
(tester) async {
|
|
var buildCount = 0;
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: ArcaneEnvironmentProvider(
|
|
child: Builder(
|
|
builder: (context) {
|
|
buildCount++;
|
|
// ignore: unnecessary_statements
|
|
ArcaneEnvironment.of(context).environment;
|
|
return const SizedBox();
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(buildCount, 1);
|
|
|
|
Arcane.environment.setEnvironment(Environment.debug);
|
|
await tester.pump();
|
|
expect(buildCount, 2);
|
|
});
|
|
|
|
testWidgets(
|
|
"state enableDebugMode updates to debug and no-ops when already debug",
|
|
(tester) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: ArcaneEnvironmentProvider(
|
|
child: Builder(
|
|
builder: (context) {
|
|
return const SizedBox();
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
final ArcaneEnvironmentModeController state =
|
|
tester.state<State<ArcaneEnvironmentProvider>>(
|
|
find.byType(ArcaneEnvironmentProvider),
|
|
) as ArcaneEnvironmentModeController;
|
|
|
|
expect(Arcane.environment.current, Environment.normal);
|
|
|
|
state.enableDebugMode();
|
|
await tester.pump();
|
|
expect(Arcane.environment.current, Environment.debug);
|
|
|
|
state.enableDebugMode();
|
|
await tester.pump();
|
|
expect(Arcane.environment.current, Environment.debug);
|
|
},
|
|
);
|
|
|
|
testWidgets(
|
|
"state disableDebugMode updates to normal and no-ops when already normal",
|
|
(tester) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: ArcaneEnvironmentProvider(
|
|
environment: Environment.debug,
|
|
child: Builder(
|
|
builder: (context) {
|
|
return const SizedBox();
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
final ArcaneEnvironmentModeController state =
|
|
tester.state<State<ArcaneEnvironmentProvider>>(
|
|
find.byType(ArcaneEnvironmentProvider),
|
|
) as ArcaneEnvironmentModeController;
|
|
|
|
expect(Arcane.environment.current, Environment.debug);
|
|
|
|
state.disableDebugMode();
|
|
await tester.pump();
|
|
expect(Arcane.environment.current, Environment.normal);
|
|
|
|
state.disableDebugMode();
|
|
await tester.pump();
|
|
expect(Arcane.environment.current, Environment.normal);
|
|
},
|
|
);
|
|
});
|
|
}
|