mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-23 16:26:29 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,free-days-interop) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / free-days-interop (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Flutter 3.50 deprecates package:flutter/material.dart, so the app moves to material_ui 1.11.0 together with sync_settings_ui 0.8.0 and github_device_auth 0.5.0 (crdt_sync 0.13.1 rides along). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
163 lines
4.6 KiB
Dart
163 lines
4.6 KiB
Dart
/// Tests for cues.dart: haptic feedback and semantics behavior.
|
|
library;
|
|
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:material_ui/material_ui.dart';
|
|
import 'package:wake_alarm_sync/ui/cues.dart';
|
|
|
|
void main() {
|
|
group('StatusCue haptics', () {
|
|
testWidgets('error triggers heavyImpact haptic', (tester) async {
|
|
final calls = <MethodCall>[];
|
|
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
SystemChannels.platform,
|
|
(call) async {
|
|
calls.add(call);
|
|
return null;
|
|
},
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
const MaterialApp(
|
|
home: Scaffold(body: StatusCue(semanticLabel: 'Error: x')),
|
|
),
|
|
);
|
|
|
|
expect(calls, isNotEmpty);
|
|
final heavyCalls = calls.where(
|
|
(c) =>
|
|
c.method == 'HapticFeedback.vibrate' &&
|
|
c.arguments == 'HapticFeedbackType.heavyImpact',
|
|
);
|
|
expect(heavyCalls, isNotEmpty);
|
|
});
|
|
|
|
testWidgets('ok triggers lightImpact on kind change', (tester) async {
|
|
final calls = <MethodCall>[];
|
|
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
SystemChannels.platform,
|
|
(call) async {
|
|
calls.add(call);
|
|
return null;
|
|
},
|
|
);
|
|
|
|
var currentKind = CueKind.info;
|
|
var currentLabel = 'Syncing';
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: StatefulBuilder(
|
|
builder: (context, setState) {
|
|
return Column(
|
|
children: [
|
|
StatusCue(semanticLabel: currentLabel, kind: currentKind),
|
|
TextButton(
|
|
onPressed: () {
|
|
setState(() {
|
|
currentKind = CueKind.ok;
|
|
currentLabel = 'Synced ✓';
|
|
});
|
|
},
|
|
child: const Text('Change'),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
calls.clear();
|
|
|
|
await tester.tap(find.byType(TextButton));
|
|
await tester.pump();
|
|
|
|
final lightCalls = calls.where(
|
|
(c) =>
|
|
c.method == 'HapticFeedback.vibrate' &&
|
|
c.arguments == 'HapticFeedbackType.lightImpact',
|
|
);
|
|
expect(lightCalls, isNotEmpty);
|
|
});
|
|
|
|
void expectHeavyCalls(int expected, List<MethodCall> calls) {
|
|
final count = calls
|
|
.where(
|
|
(c) =>
|
|
c.method == 'HapticFeedback.vibrate' &&
|
|
c.arguments == 'HapticFeedbackType.heavyImpact',
|
|
)
|
|
.length;
|
|
expect(count, equals(expected));
|
|
}
|
|
|
|
testWidgets('haptic fires once on MediaQuery change with same error kind', (
|
|
tester,
|
|
) async {
|
|
final calls = <MethodCall>[];
|
|
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
SystemChannels.platform,
|
|
(call) async {
|
|
calls.add(call);
|
|
return null;
|
|
},
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
const MaterialApp(
|
|
home: Scaffold(body: StatusCue(semanticLabel: 'Error: x')),
|
|
),
|
|
);
|
|
calls.clear();
|
|
|
|
// Pump again inside a MediaQuery with different viewInsets
|
|
await tester.pumpWidget(
|
|
const MaterialApp(
|
|
home: MediaQuery(
|
|
data: MediaQueryData(viewInsets: EdgeInsets.only(bottom: 300)),
|
|
child: Scaffold(body: StatusCue(semanticLabel: 'Error: x')),
|
|
),
|
|
),
|
|
);
|
|
|
|
// Should NOT fire again - same error kind, same label
|
|
expectHeavyCalls(1, calls);
|
|
});
|
|
|
|
testWidgets(
|
|
'haptic fires again when semanticLabel changes with same error kind',
|
|
(tester) async {
|
|
final calls = <MethodCall>[];
|
|
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
SystemChannels.platform,
|
|
(call) async {
|
|
calls.add(call);
|
|
return null;
|
|
},
|
|
);
|
|
|
|
// Initial pump with error cue
|
|
await tester.pumpWidget(
|
|
const MaterialApp(
|
|
home: Scaffold(body: StatusCue(semanticLabel: 'Error: first')),
|
|
),
|
|
);
|
|
calls.clear();
|
|
|
|
// Pump with different semanticLabel but same error kind
|
|
await tester.pumpWidget(
|
|
const MaterialApp(
|
|
home: Scaffold(body: StatusCue(semanticLabel: 'Error: second')),
|
|
),
|
|
);
|
|
|
|
// Should fire again because semanticLabel changed
|
|
expectHeavyCalls(1, calls);
|
|
},
|
|
);
|
|
});
|
|
}
|