Files
LN-Code-Editor/test/app_update_service_test.dart

76 lines
2.9 KiB
Dart

import 'package:code_editor/l10n/app_localizations.dart';
import 'package:code_editor/services/app_update_service.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('AppUpdateService', () {
test('isNewerVersion compares semantic versions accurately', () {
expect(AppUpdateService.isNewerVersion('1.0.4', '1.0.3'), isTrue);
expect(AppUpdateService.isNewerVersion('v1.1.0', '1.0.3'), isTrue);
expect(AppUpdateService.isNewerVersion('1.0.3', '1.0.3'), isFalse);
expect(AppUpdateService.isNewerVersion('1.0.2', '1.0.3'), isFalse);
expect(AppUpdateService.isNewerVersion('v1.0.10', '1.0.9'), isTrue);
});
test('parseVersionCode produces monotonic integer codes', () {
expect(AppUpdateService.parseVersionCode('v1.0.3'), 10003);
expect(AppUpdateService.parseVersionCode('1.2.4'), 10204);
expect(AppUpdateService.parseVersionCode('1.0.10'), 10010);
});
test('parseReleaseJson selects universal or matching ABI APK asset', () {
const sampleJson = '''
{
"tag_name": "v1.0.4",
"name": "LN Code Editor v1.0.4",
"body": "- Fix something\\n- Improve speed",
"html_url": "https://gitea.lzxnone.cloud/lzxnone/LN-Code-Editor/releases/tag/v1.0.4",
"assets": [
{
"name": "LN-Code-Editor-v1.0.4-universal.apk",
"size": 104857600,
"browser_download_url": "https://gitea.lzxnone.cloud/attachments/univ"
},
{
"name": "LN-Code-Editor-v1.0.4-arm64-v8a.apk",
"size": 83886080,
"browser_download_url": "https://gitea.lzxnone.cloud/attachments/arm64"
}
]
}
''';
final arm64Info = AppUpdateService.parseReleaseJson(
sampleJson,
currentVersion: '1.0.3',
supportedAbis: ['arm64-v8a', 'armeabi-v7a'],
);
expect(arm64Info.hasUpdate, isTrue);
expect(arm64Info.versionName, '1.0.4');
expect(arm64Info.versionCode, 10004);
expect(arm64Info.downloadUrl, 'https://gitea.lzxnone.cloud/attachments/arm64');
expect(arm64Info.apkSize, '80.00 MB');
final fallbackUniv = AppUpdateService.parseReleaseJson(
sampleJson,
currentVersion: '1.0.4',
supportedAbis: [],
);
expect(fallbackUniv.hasUpdate, isFalse);
expect(fallbackUniv.downloadUrl, 'https://gitea.lzxnone.cloud/attachments/univ');
expect(fallbackUniv.apkSize, '100.00 MB');
});
test('update l10n keys exist in zh and en', () {
final zh = lookupAppLocalizations(const Locale('zh'));
final en = lookupAppLocalizations(const Locale('en'));
expect(zh.aboutAndUpdatesSection, '关于与更新');
expect(en.aboutAndUpdatesSection, 'About & Updates');
expect(zh.newVersionAvailableTitle('V1.0.4'), '发现新版本 V1.0.4');
expect(en.newVersionAvailableTitle('V1.0.4'), 'New Version V1.0.4');
});
});
}