Skip to content

Commit

Permalink
Project detail test (#18)
Browse files Browse the repository at this point in the history
* Checked out project detail test from branch all-commits

* implemented all methods

* refactor

* formatting

* revert unwanted change and small code cleaning

---------

Co-authored-by: Simone Stasi <[email protected]>
  • Loading branch information
AlbertoFurlan20 and sstasi95 authored Dec 11, 2023
1 parent f229b1a commit 302bdc7
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 26 deletions.
14 changes: 7 additions & 7 deletions lib/src/models/team.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'dart:convert';
import 'package:azure_devops/src/models/team_member.dart';
import 'package:http/http.dart';

typedef TeamWithMembers = ({_Team team, List<TeamMember> members});
typedef TeamWithMembers = ({Team team, List<TeamMember> members});

class GetTeamsResponse {
GetTeamsResponse({
Expand All @@ -16,27 +16,27 @@ class GetTeamsResponse {
factory GetTeamsResponse.fromJson(Map<String, dynamic> json) => GetTeamsResponse(
teams: json['value'] == null
? []
: List<_Team?>.from((json['value'] as List<dynamic>).map((x) => _Team.fromJson(x as Map<String, dynamic>))),
: List<Team?>.from((json['value'] as List<dynamic>).map((x) => Team.fromJson(x as Map<String, dynamic>))),
count: json['count'] as int?,
);

static List<_Team?> fromResponse(Response res) =>
static List<Team?> fromResponse(Response res) =>
GetTeamsResponse.fromJson(jsonDecode(res.body) as Map<String, dynamic>).teams ?? [];

final List<_Team?>? teams;
final List<Team?>? teams;
final int? count;
}

class _Team {
_Team({
class Team {
Team({
required this.id,
required this.name,
required this.description,
required this.projectName,
required this.projectId,
});

factory _Team.fromJson(Map<String, dynamic> json) => _Team(
factory Team.fromJson(Map<String, dynamic> json) => Team(
id: json['id'] as String?,
name: json['name'] as String?,
description: json['description'] as String?,
Expand Down
17 changes: 9 additions & 8 deletions lib/src/models/team_member.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ class GetTeamMembersResponse {
count: json['count'] as int?,
);

static List<TeamMember>? fromResponse(Response res) =>
GetTeamMembersResponse.fromJson(jsonDecode(res.body) as Map<String, dynamic>).members;
static List<TeamMember>? fromResponse(Response res) => GetTeamMembersResponse.fromJson(
jsonDecode(res.body) as Map<String, dynamic>,
).members;

final List<TeamMember>? members;
final int? count;
Expand All @@ -34,11 +35,11 @@ class TeamMember {

factory TeamMember.fromJson(Map<String, dynamic> json) => TeamMember(
isTeamAdmin: json['isTeamAdmin'] as bool?,
identity: _Identity.fromJson(json['identity'] as Map<String, dynamic>),
identity: Identity.fromJson(json['identity'] as Map<String, dynamic>),
);

final bool? isTeamAdmin;
final _Identity? identity;
final Identity? identity;

@override
String toString() => 'TeamMember(isTeamAdmin: $isTeamAdmin, identity: $identity)';
Expand All @@ -54,16 +55,16 @@ class TeamMember {
int get hashCode => isTeamAdmin.hashCode ^ identity.hashCode;
}

class _Identity {
_Identity({
class Identity {
Identity({
required this.displayName,
required this.id,
required this.uniqueName,
required this.imageUrl,
required this.descriptor,
});

factory _Identity.fromJson(Map<String, dynamic> json) => _Identity(
factory Identity.fromJson(Map<String, dynamic> json) => Identity(
displayName: json['displayName'] as String?,
id: json['id'] as String?,
uniqueName: json['uniqueName'] as String?,
Expand All @@ -86,7 +87,7 @@ class _Identity {
bool operator ==(Object other) {
if (identical(this, other)) return true;

return other is _Identity &&
return other is Identity &&
other.displayName == displayName &&
other.id == id &&
other.uniqueName == uniqueName &&
Expand Down
2 changes: 1 addition & 1 deletion lib/src/services/azure_api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import 'package:azure_devops/src/models/repository.dart';
import 'package:azure_devops/src/models/repository_branches.dart';
import 'package:azure_devops/src/models/repository_items.dart';
import 'package:azure_devops/src/models/team.dart';
import 'package:azure_devops/src/models/team_member.dart';
import 'package:azure_devops/src/models/team_member.dart' show GetTeamMembersResponse;
import 'package:azure_devops/src/models/timeline.dart';
import 'package:azure_devops/src/models/user.dart';
import 'package:azure_devops/src/models/user_entitlements.dart';
Expand Down
57 changes: 47 additions & 10 deletions test/api_service_mock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import 'package:azure_devops/src/models/repository.dart';
import 'package:azure_devops/src/models/repository_branches.dart';
import 'package:azure_devops/src/models/repository_items.dart';
import 'package:azure_devops/src/models/team.dart';
import 'package:azure_devops/src/models/team_member.dart' as t;
import 'package:azure_devops/src/models/user.dart';
import 'package:azure_devops/src/models/work_item_fields.dart';
import 'package:azure_devops/src/models/work_item_updates.dart';
Expand Down Expand Up @@ -159,13 +160,43 @@ class AzureApiServiceMock implements AzureApiService {
}

@override
Future<ApiResponse<List<GitRepository>>> getProjectRepositories({required String projectName}) {
throw UnimplementedError();
Future<ApiResponse<List<GitRepository>>> getProjectRepositories({required String projectName}) async {
return ApiResponse.ok(<GitRepository>[]);
}

@override
Future<ApiResponse<List<TeamWithMembers>>> getProjectTeams({required String projectId}) {
throw UnimplementedError();
Future<ApiResponse<List<TeamWithMembers>>> getProjectTeams({required String projectId}) async {
final team = Team(
id: 'team id',
name: 'team name',
description: 'team description',
projectName: 'team projectName',
projectId: projectId,
);
final member1 = t.TeamMember(
isTeamAdmin: false,
identity: t.Identity(
displayName: 'member_1_name',
id: 'member 1 id',
uniqueName: 'aabbcc',
imageUrl: null,
descriptor: '',
),
);
final member2 = t.TeamMember(
isTeamAdmin: true,
identity: t.Identity(
displayName: 'member_2_name',
id: 'member 2 id',
uniqueName: 'ddeeff',
imageUrl: null,
descriptor: null,
),
);
final x = [member1, member2];
final teamsWithMembers1 = <TeamWithMembers>[(members: x, team: team)];

return ApiResponse.ok(teamsWithMembers1);
}

@override
Expand Down Expand Up @@ -501,15 +532,21 @@ class AzureApiServiceMock implements AzureApiService {
}

@override
Future<ApiResponse<ProjectDetail>> getProject({required String projectName}) {
throw UnimplementedError();
Future<ApiResponse<ProjectDetail>> getProject({required String projectName}) async {
final data = ProjectDetail(
project: Project(
id: 'project id',
name: 'project name',
description: 'description',
url: '',
),
);
return ApiResponse.ok(data);
}

@override
Future<ApiResponse<List<LanguageBreakdown>>> getProjectLanguages({
required String projectName,
}) {
throw UnimplementedError();
Future<ApiResponse<List<LanguageBreakdown>>> getProjectLanguages({required String projectName}) async {
return ApiResponse.ok([LanguageBreakdown(name: 'en-EN')]);
}

@override
Expand Down
30 changes: 30 additions & 0 deletions test/project_detail_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:azure_devops/src/screens/project_detail/base_project_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 details taken from [AzureApiServiceMock.getProjectTeams]
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

testWidgets("Project detail page shows all project's informations", (t) async {
final projectPage = AzureApiServiceInherited(
apiService: AzureApiServiceMock(),
child: MaterialApp(
onGenerateRoute: (_) => MaterialPageRoute(
builder: (_) => ProjectDetailPage(),
settings: RouteSettings(
arguments: 'test name',
),
),
),
);

await t.pumpWidget(projectPage);
await t.pumpAndSettle();

expect(find.text('member_2_name', findRichText: true), findsOneWidget);
});
}

0 comments on commit 302bdc7

Please sign in to comment.