Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File detail page and Repository detail page tests implementation #17

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions test/api_service_mock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<ApiResponse<List<Branch>>> getRepositoryBranches({
required String projectName,
required String repoName,
}) {
throw UnimplementedError();
}) async {
return ApiResponse.ok(<Branch>[]);
}

@override
Expand All @@ -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
Expand Down
35 changes: 35 additions & 0 deletions test/file_detail_test.dart
Original file line number Diff line number Diff line change
@@ -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);
});
}
33 changes: 33 additions & 0 deletions test/repository_detail_test.dart
Original file line number Diff line number Diff line change
@@ -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);
});
}
Loading