Files
cutdex/packages/cutdex_native/test/device_info_test.dart
lingjhf 27e77fff39 feat: initial Cutdex application
Add the Flutter video editing application with project management, media
import, timeline editing, preview, AI assistance, diagnostics and settings.

Include shared UI and native host packages, platform runners, application
tests and release tooling.

Provide usage and contribution guides, the MIT license and third-party
notices. Exclude local credentials, build outputs and validation data.
2026-10-05 23:36:23 +08:00

64 lines
2.2 KiB
Dart

import 'package:cutdex_native/cutdex_native.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
const channel = MethodChannel('cutdex_native/device_info');
final messenger =
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
tearDown(() => messenger.setMockMethodCallHandler(channel, null));
test(
'Android display facts accept integer and floating point values',
() async {
for (final value in [600, 599.5]) {
messenger.setMockMethodCallHandler(channel, (call) async {
expect(call.method, 'getDeviceInfo');
return {'displayShortestSideDp': value};
});
final info = await NativeDeviceInfo.read();
expect(info?.displayShortestSideDp, value.toDouble());
expect(info?.interfaceIdiom, isNull);
}
},
);
test('iOS idioms remain raw device facts', () async {
for (final idiom in NativeInterfaceIdiom.values) {
messenger.setMockMethodCallHandler(
channel,
(call) async => {'interfaceIdiom': idiom.name},
);
final info = await NativeDeviceInfo.read();
expect(info?.interfaceIdiom, idiom);
expect(info?.displayShortestSideDp, isNull);
}
});
test('invalid responses do not expose unusable device facts', () async {
for (final value in <Object?>[
null,
'phone',
<String, Object?>{},
{'interfaceIdiom': 'unknown'},
{'displayShortestSideDp': '600'},
{'displayShortestSideDp': 0},
{'displayShortestSideDp': -1},
{'displayShortestSideDp': double.nan},
{'displayShortestSideDp': double.infinity},
]) {
messenger.setMockMethodCallHandler(channel, (call) async => value);
expect(await NativeDeviceInfo.read(), isNull, reason: '$value');
}
});
test('unregistered and unavailable native hosts return no facts', () async {
expect(await NativeDeviceInfo.read(), isNull);
messenger.setMockMethodCallHandler(channel, (call) async {
throw PlatformException(code: 'unavailable');
});
expect(await NativeDeviceInfo.read(), isNull);
});
}