47 lines
1.3 KiB
Dart
47 lines
1.3 KiB
Dart
import 'dart:ui';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:yx_tracking_flutter/src/util/device_util.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
group('DeviceUtil', () {
|
|
test('collectDeviceInfo 返回基础信息', () async {
|
|
expect(DeviceUtil.instance(), isA<DeviceUtil>());
|
|
final info = await DeviceUtil.collectDeviceInfo();
|
|
|
|
expect(info.os, isNotEmpty);
|
|
expect(info.model, isNotEmpty);
|
|
expect(info.screenResolution, isNotEmpty);
|
|
});
|
|
|
|
test('views 为空时返回 unknown', () {
|
|
final resolution = DeviceUtil.screenResolutionForTesting(
|
|
viewsProvider: () => const [],
|
|
);
|
|
|
|
expect(resolution, 'unknown');
|
|
});
|
|
|
|
test('viewsProvider 抛错时返回 unknown', () {
|
|
final resolution = DeviceUtil.screenResolutionForTesting(
|
|
viewsProvider: () => throw StateError('boom'),
|
|
);
|
|
|
|
expect(resolution, 'unknown');
|
|
});
|
|
|
|
test('尺寸为 0 时返回 unknown', () {
|
|
final resolution = DeviceUtil.resolutionFromSizeForTesting(Size.zero);
|
|
expect(resolution, 'unknown');
|
|
});
|
|
|
|
test('正尺寸会格式化为 WxH', () {
|
|
const size = Size(1080, 1920);
|
|
final resolution = DeviceUtil.resolutionFromSizeForTesting(size);
|
|
expect(resolution, '1080x1920');
|
|
});
|
|
});
|
|
}
|