diff --git a/test/api_service_mock.dart b/test/api_service_mock.dart index f017a4f5..e9ee7240 100644 --- a/test/api_service_mock.dart +++ b/test/api_service_mock.dart @@ -583,16 +583,28 @@ class AzureApiServiceMock implements AzureApiService { required String repoName, required String path, String? branch, - }) { - throw UnimplementedError(); + }) async { + final item1 = RepoItem( + objectId: 'item 1 ID', + commitId: '111111', + path: 'item 1', + url: '', + ); + final item2 = RepoItem( + objectId: 'item 2 ID', + commitId: '222222', + path: 'item 2', + url: '', + ); + return ApiResponse.ok([item1, item2]); } @override Future>> getRepositoryBranches({ required String projectName, required String repoName, - }) { - throw UnimplementedError(); + }) async { + return ApiResponse.ok([]); } @override @@ -603,8 +615,10 @@ class AzureApiServiceMock implements AzureApiService { String? branch, String? commitId, bool previousChange = false, - }) { - throw UnimplementedError(); + }) async { + return ApiResponse.ok( + FileDetailResponse(content: 'body test', isBinary: false), + ); } @override diff --git a/test/file_detail_test.dart b/test/file_detail_test.dart new file mode 100644 index 00000000..e8df457a --- /dev/null +++ b/test/file_detail_test.dart @@ -0,0 +1,35 @@ +import 'package:azure_devops/src/router/router.dart'; +import 'package:azure_devops/src/screens/file_detail/base_file_detail.dart'; +import 'package:azure_devops/src/services/azure_api_service.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'api_service_mock.dart'; + +/// Mock file is taken from [AzureApiServiceMock.getFileDetail] +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('File detail page showing correcly file content', (t) async { + final detailPage = AzureApiServiceInherited( + apiService: AzureApiServiceMock(), + child: MaterialApp( + onGenerateRoute: (_) => MaterialPageRoute( + builder: (_) => FileDetailPage(), + settings: RouteSettings( + arguments: RepoDetailArgs( + projectName: 'project name', + repositoryName: 'repo name', + filePath: 'path', + branch: 'branch test', + ), + ), + ), + ), + ); + + await t.pumpWidget(detailPage); + await t.pumpAndSettle(); + + expect(find.text('body test', findRichText: true), findsOneWidget); + }); +} diff --git a/test/repository_detail_test.dart b/test/repository_detail_test.dart new file mode 100644 index 00000000..72625de7 --- /dev/null +++ b/test/repository_detail_test.dart @@ -0,0 +1,33 @@ +import 'package:azure_devops/src/router/router.dart'; +import 'package:azure_devops/src/screens/repository_detail/base_repository_detail.dart'; +import 'package:azure_devops/src/services/azure_api_service.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'api_service_mock.dart'; + +/// Mock repository items are taken from [AzureApiServiceMock.getRepositoryItems] +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('Repository detail page showing all items', (t) async { + final repoDetailPage = AzureApiServiceInherited( + apiService: AzureApiServiceMock(), + child: MaterialApp( + onGenerateRoute: (_) => MaterialPageRoute( + builder: (_) => RepositoryDetailPage(), + settings: RouteSettings( + arguments: RepoDetailArgs( + projectName: '', + repositoryName: '', + ), + ), + ), + ), + ); + + await t.pumpWidget(repoDetailPage); + await t.pump(); + + expect(find.text('item 2', findRichText: true), findsWidgets); + }); +}