62 lines
2.1 KiB
Dart
62 lines
2.1 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:yumi/app/config/app_config.dart';
|
|
import 'package:yumi/app/constants/sc_global_config.dart';
|
|
import 'package:yumi/ui_kit/widgets/room/rocket/room_rocket_pag_effect_overlay.dart';
|
|
|
|
void main() {
|
|
setUpAll(() {
|
|
AppConfig.initialize();
|
|
});
|
|
|
|
test('normalizes unescaped pag network urls', () {
|
|
final uri = debugRoomRocketPagNetworkUri(
|
|
'https://example.com/assets/火箭 输出/火箭1级.pag?name=火箭 1',
|
|
);
|
|
|
|
expect(uri, isNotNull);
|
|
expect(uri!.scheme, 'https');
|
|
expect(uri.host, 'example.com');
|
|
expect(uri.toString(), contains('%E7%81%AB%E7%AE%AD'));
|
|
expect(uri.toString(), contains('%20'));
|
|
});
|
|
|
|
test('normalizes protocol-relative and server-relative pag urls', () {
|
|
final apiUri = Uri.parse(SCGlobalConfig.apiHost);
|
|
final apiScheme = apiUri.scheme == 'http' ? 'http' : 'https';
|
|
expect(
|
|
debugNormalizeRoomRocketPagResource('//cdn.example.com/rocket.pag'),
|
|
'$apiScheme://cdn.example.com/rocket.pag',
|
|
);
|
|
expect(
|
|
debugNormalizeRoomRocketPagResource('/external/oss/local/火箭.pag'),
|
|
apiUri.resolve('/external/oss/local/火箭.pag').toString(),
|
|
);
|
|
});
|
|
|
|
test('detects local file sources before falling back to assets', () {
|
|
expect(
|
|
debugRoomRocketPagFilePath('file:///tmp/%E7%81%AB%E7%AE%AD.pag'),
|
|
'/tmp/火箭.pag',
|
|
);
|
|
expect(debugRoomRocketPagSourceKind('/tmp/rocket.pag'), 'file');
|
|
expect(debugRoomRocketPagSourceKind('assets/rocket/rocket.pag'), 'asset');
|
|
});
|
|
|
|
test('keeps pag bytes in memory for five minutes by default', () {
|
|
expect(debugRoomRocketPagMemoryTtl(), const Duration(minutes: 5));
|
|
});
|
|
|
|
test('releases pag bytes when the configured ttl expires', () async {
|
|
var released = false;
|
|
final timer = debugScheduleRoomRocketPagMemoryRelease(
|
|
memoryTtl: const Duration(milliseconds: 10),
|
|
onRelease: () => released = true,
|
|
);
|
|
|
|
expect(released, isFalse);
|
|
await Future<void>.delayed(const Duration(milliseconds: 30));
|
|
expect(released, isTrue);
|
|
timer?.cancel();
|
|
});
|
|
}
|