Files
cutdex/test/device_experience_test.dart
T
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

129 lines
3.8 KiB
Dart

import 'package:cutdex/integrations/platform/device_experience.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final messenger =
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
const channel = MethodChannel('cutdex_native/device_info');
tearDown(() => messenger.setMockMethodCallHandler(channel, null));
Future<DeviceExperience> detect(
TargetPlatform platform, {
Size displaySize = const Size(390, 844),
double pixelRatio = 1,
bool web = false,
}) => DeviceExperienceDetector.detect(
platform: platform,
displaySize: displaySize,
pixelRatio: pixelRatio,
web: web,
);
test('desktop and web hosts do not query mobile device facts', () async {
var nativeCalls = 0;
messenger.setMockMethodCallHandler(channel, (call) async {
nativeCalls++;
return {'interfaceIdiom': 'phone'};
});
for (final platform in [
TargetPlatform.macOS,
TargetPlatform.windows,
TargetPlatform.linux,
]) {
expect(await detect(platform), DeviceExperience.desktop);
}
expect(
await detect(TargetPlatform.android, web: true),
DeviceExperience.phone,
);
expect(nativeCalls, 0);
});
test('iOS device identity takes precedence over display size', () async {
for (final entry in {
'phone': DeviceExperience.phone,
'pad': DeviceExperience.tablet,
'mac': DeviceExperience.desktop,
}.entries) {
messenger.setMockMethodCallHandler(channel, (call) async {
expect(call.method, 'getDeviceInfo');
return {'interfaceIdiom': entry.key};
});
expect(await detect(TargetPlatform.iOS), entry.value);
}
});
test(
'Android classification applies the app threshold to native bounds',
() async {
for (final entry in {
599.5: DeviceExperience.phone,
600.0: DeviceExperience.tablet,
800.0: DeviceExperience.tablet,
}.entries) {
messenger.setMockMethodCallHandler(
channel,
(call) async => {'displayShortestSideDp': entry.key},
);
expect(await detect(TargetPlatform.android), entry.value);
}
messenger.setMockMethodCallHandler(
channel,
(call) async => {'displayShortestSideDp': 390},
);
expect(
await detect(
TargetPlatform.android,
displaySize: const Size(1600, 2560),
pixelRatio: 2,
),
DeviceExperience.phone,
);
},
);
test(
'missing platform facts fall back to full display logical size',
() async {
for (final value in [
<String, Object?>{},
{'interfaceIdiom': 'pad'},
{'displayShortestSideDp': 0},
]) {
messenger.setMockMethodCallHandler(channel, (call) async => value);
expect(
await detect(
TargetPlatform.android,
displaySize: const Size(1200, 1920),
pixelRatio: 2,
),
DeviceExperience.tablet,
);
}
messenger.setMockMethodCallHandler(
channel,
(call) async => {'displayShortestSideDp': 800},
);
expect(await detect(TargetPlatform.iOS), DeviceExperience.phone);
messenger.setMockMethodCallHandler(channel, (call) async {
throw PlatformException(code: 'unavailable');
});
expect(
await detect(
TargetPlatform.iOS,
displaySize: const Size(1170, 2532),
pixelRatio: 3,
),
DeviceExperience.phone,
);
messenger.setMockMethodCallHandler(channel, null);
expect(
await detect(TargetPlatform.android, displaySize: Size.zero),
DeviceExperience.phone,
);
},
);
}