Skip to content

Commit

Permalink
[Tests] Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Jun 25, 2024
1 parent 5585049 commit 4a7499f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
32 changes: 22 additions & 10 deletions test/application/splash/splash_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ void main() {
int resourceVersion = defaultResourcesVersion,
String? jsonFileName,
List<String> keyNames = const <String>[],
}) =>
CheckForUpdatesResult(resourceVersion: resourceVersion, type: type, jsonFileKeyName: jsonFileName, keyNames: keyNames);
}) {
return CheckForUpdatesResult(
resourceVersion: resourceVersion,
type: type,
jsonFileKeyName: jsonFileName,
keyNames: keyNames,
downloadTotalSize: 100,
);
}

test('Initial state', () => expect(getBloc(MockResourceService()).state, const SplashState.loading()));

Expand Down Expand Up @@ -409,14 +416,15 @@ void main() {
),
build: () => getBloc(MockResourceService()),
act: (bloc) => bloc
..add(const SplashEvent.progressChanged(progress: 10))
..add(const SplashEvent.progressChanged(progress: 50))
..add(const SplashEvent.progressChanged(progress: 100)),
..add(const SplashEvent.progressChanged(progress: 10, downloadedBytes: 10))
..add(const SplashEvent.progressChanged(progress: 50, downloadedBytes: 50))
..add(const SplashEvent.progressChanged(progress: 100, downloadedBytes: 100)),
expect: () => [
SplashState.loaded(
updateResultType: AppResourceUpdateResultType.updatesAvailable,
language: language,
progress: 10,
downloadedBytes: 10,
result: getUpdateResult(AppResourceUpdateResultType.updatesAvailable),
noResourcesHasBeenDownloaded: false,
isLoading: false,
Expand All @@ -430,6 +438,7 @@ void main() {
updateResultType: AppResourceUpdateResultType.updatesAvailable,
language: language,
progress: 50,
downloadedBytes: 50,
result: getUpdateResult(AppResourceUpdateResultType.updatesAvailable),
noResourcesHasBeenDownloaded: false,
isLoading: false,
Expand All @@ -443,6 +452,7 @@ void main() {
updateResultType: AppResourceUpdateResultType.updatesAvailable,
language: language,
progress: 100,
downloadedBytes: 100,
result: getUpdateResult(AppResourceUpdateResultType.updatesAvailable),
noResourcesHasBeenDownloaded: false,
isLoading: false,
Expand Down Expand Up @@ -471,13 +481,14 @@ void main() {
),
build: () => getBloc(MockResourceService()),
act: (bloc) => bloc
..add(const SplashEvent.progressChanged(progress: 100))
..add(const SplashEvent.progressChanged(progress: 110)),
..add(const SplashEvent.progressChanged(progress: 100, downloadedBytes: 100))
..add(const SplashEvent.progressChanged(progress: 110, downloadedBytes: 110)),
expect: () => [
SplashState.loaded(
updateResultType: AppResourceUpdateResultType.updatesAvailable,
language: language,
progress: 100,
downloadedBytes: 100,
result: getUpdateResult(AppResourceUpdateResultType.updatesAvailable),
noResourcesHasBeenDownloaded: false,
isLoading: false,
Expand Down Expand Up @@ -506,13 +517,14 @@ void main() {
),
build: () => getBloc(MockResourceService()),
act: (bloc) => bloc
..add(const SplashEvent.progressChanged(progress: 10))
..add(const SplashEvent.progressChanged(progress: 10.1)),
..add(const SplashEvent.progressChanged(progress: 10, downloadedBytes: 10))
..add(const SplashEvent.progressChanged(progress: 10.1, downloadedBytes: 10)),
expect: () => [
SplashState.loaded(
updateResultType: AppResourceUpdateResultType.updatesAvailable,
language: language,
progress: 10,
downloadedBytes: 10,
result: getUpdateResult(AppResourceUpdateResultType.updatesAvailable),
noResourcesHasBeenDownloaded: false,
isLoading: false,
Expand Down Expand Up @@ -540,7 +552,7 @@ void main() {
needsLatestAppVersionOnFirstInstall: false,
),
build: () => getBloc(MockResourceService()),
act: (bloc) => bloc.add(const SplashEvent.progressChanged(progress: -1)),
act: (bloc) => bloc.add(const SplashEvent.progressChanged(progress: -1, downloadedBytes: 0)),
errors: () => [isA<Exception>()],
);
});
Expand Down
8 changes: 4 additions & 4 deletions test/infrastructure/resource_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ void main() {
final networkService = MockNetworkService();
when(networkService.isInternetAvailable()).thenAnswer((_) => Future.value(true));
final apiService = MockApiService();
when(apiService.downloadAsset(allJson, path.join(tempDir.path, allJson))).thenAnswer((_) => Future.value(false));
when(apiService.downloadAsset(allJson, path.join(tempDir.path, allJson))).thenAnswer((_) => Future.value());

final service = ResourceServiceImpl(
MockLoggingService(),
Expand Down Expand Up @@ -479,9 +479,9 @@ void main() {
'characters/ganyu$imageFileExtension',
];

when(apiService.downloadAsset(keyNames[0], path.join(tempDir.path, keyNames[0]))).thenAnswer((_) => Future.value(true));
when(apiService.downloadAsset(keyNames[1], path.join(tempDir.path, keyNames[1]))).thenAnswer((_) => Future.value(true));
when(apiService.downloadAsset(keyNames[2], path.join(tempDir.path, keyNames[2]))).thenAnswer((_) => Future.value(false));
when(apiService.downloadAsset(keyNames[0], path.join(tempDir.path, keyNames[0]))).thenAnswer((_) => Future.value(1));
when(apiService.downloadAsset(keyNames[1], path.join(tempDir.path, keyNames[1]))).thenAnswer((_) => Future.value(2));
when(apiService.downloadAsset(keyNames[2], path.join(tempDir.path, keyNames[2]))).thenAnswer((_) => Future.value());

await File(path.join(path.join(tempDir.path, 'keqing$imageFileExtension'))).create();
await File(path.join(path.join(tempDir.path, 'kamisato_ayaka$imageFileExtension'))).create();
Expand Down

0 comments on commit 4a7499f

Please sign in to comment.