Skip to content

Commit

Permalink
updated tests with Page building test (#36)
Browse files Browse the repository at this point in the history
Co-authored-by: Matteo Bucci <matteo.bucci@purplesoft.io>
  • Loading branch information
matte118 and Matteo Bucci authored May 8, 2024
1 parent b874e2f commit 7f1f3fb
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 105 deletions.
48 changes: 40 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.8.1"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
url: "https://pub.dev"
source: hosted
version: "10.0.0"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
url: "https://pub.dev"
source: hosted
version: "2.0.1"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
url: "https://pub.dev"
source: hosted
version: "2.0.1"
markdown:
dependency: transitive
description:
Expand All @@ -484,26 +508,26 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev"
source: hosted
version: "0.12.16"
version: "0.12.16+1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.11.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -572,10 +596,10 @@ packages:
dependency: "direct main"
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
source: hosted
version: "1.8.3"
version: "1.9.0"
path_parsing:
dependency: transitive
description:
Expand Down Expand Up @@ -1007,6 +1031,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.3.3"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "13.0.0"
web:
dependency: transitive
description:
Expand Down
13 changes: 5 additions & 8 deletions test/choose_projects_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import 'api_service_mock.dart';

void main() {
testWidgets('Projects are visible', (t) async {
TestWidgetsFlutterBinding.ensureInitialized();

testWidgets('Page building test', (t) async {
final app = AzureApiServiceInherited(
apiService: AzureApiServiceMock(),
child: StorageServiceInherited(
Expand All @@ -25,15 +27,10 @@ void main() {

await t.pumpWidget(app);

final pageTitle = find.textContaining('Choose projects');
expect(pageTitle, findsOneWidget);

await t.pumpAndSettle();
await t.pump();

final firstProject = find.textContaining('p1');
expect(firstProject, findsOneWidget);
expect(find.byType(ChooseProjectsPage), findsOneWidget);
});

testWidgets('All projects are selected by default', (t) async {
final app = AzureApiServiceInherited(
apiService: AzureApiServiceMock(),
Expand Down
19 changes: 6 additions & 13 deletions test/commit_detail_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import 'api_service_mock.dart';

/// Mock commit is taken from [AzureApiServiceMock.getCommitDetail]
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

testWidgets(
'Commit detail page shows all the details',
'Page building test',
(t) async {
final detailPage = AzureApiServiceInherited(
final app = AzureApiServiceInherited(
apiService: AzureApiServiceMock(),
child: MaterialApp(
onGenerateRoute: (_) => MaterialPageRoute(
Expand All @@ -22,19 +24,10 @@ void main() {
),
);

await t.pumpWidget(detailPage);
await t.pumpWidget(app);
await t.pump();

// commit info
expect(find.text('TestProject'), findsOneWidget);
expect(find.text('test_repo'), findsOneWidget);
expect(find.text('Test commit message'), findsOneWidget);
expect(find.text('123456789'), findsOneWidget);

// edited files details
expect(find.text('5 edited files'), findsOneWidget);
expect(find.text('3 added files'), findsOneWidget);
expect(find.text('1 deleted file'), findsOneWidget);
expect(find.byType(CommitDetailPage), findsOneWidget);
},
);
}
21 changes: 21 additions & 0 deletions test/commits_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ import 'api_service_mock.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

testWidgets(
'Page building test',
(t) async {
final app = MaterialApp(
home: AzureApiServiceInherited(
apiService: AzureApiServiceMock(),
child: StorageServiceInherited(
storageService: StorageServiceMock(),
child: CommitsPage(),
),
),
);

await t.pumpWidget(app);

await t.pump();

expect(find.byType(CommitsPage), findsOneWidget);
},
);

testWidgets(
'Commits are sorted by date descending',
(t) async {
Expand Down
8 changes: 4 additions & 4 deletions test/file_detail_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import 'api_service_mock.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

testWidgets('File detail page showing correcly file content', (t) async {
final detailPage = AzureApiServiceInherited(
testWidgets('Page building test', (t) async {
final app = AzureApiServiceInherited(
apiService: AzureApiServiceMock(),
child: MaterialApp(
onGenerateRoute: (_) => MaterialPageRoute(
Expand All @@ -27,9 +27,9 @@ void main() {
),
);

await t.pumpWidget(detailPage);
await t.pumpWidget(app);
await t.pumpAndSettle();

expect(find.text('body test', findRichText: true), findsOneWidget);
expect(find.byType(FileDetailPage), findsOneWidget);
});
}
21 changes: 21 additions & 0 deletions test/login_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@ import 'package:flutter_test/flutter_test.dart';
import 'api_service_mock.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();

testWidgets('Page building test', (t) async {
final app = AzureApiServiceInherited(
apiService: AzureApiServiceMock(),
child: StorageServiceInherited(
storageService: StorageServiceMock(),
child: MaterialApp(
navigatorKey: AppRouter.navigatorKey,
routes: AppRouter.routes,
home: LoginPage(),
),
),
);

await t.pumpWidget(app);

await t.pump();

expect(find.byType(LoginPage), findsOneWidget);
});
testWidgets('Login with invalid token shows error alert', (t) async {
final app = MaterialApp(
navigatorKey: AppRouter.navigatorKey,
Expand Down
4 changes: 2 additions & 2 deletions test/member_detail_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'api_service_mock.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

testWidgets('Member detail page shows all details', (t) async {
testWidgets('Page building test', (t) async {
final memberPage = AzureApiServiceInherited(
apiService: AzureApiServiceMock(),
child: MaterialApp(
Expand All @@ -25,6 +25,6 @@ void main() {
await t.pumpWidget(memberPage);
await t.pumpAndSettle();

expect(find.text('Name: name test', findRichText: true), findsWidgets);
expect(find.byType(MemberDetailPage), findsOneWidget);
});
}
23 changes: 6 additions & 17 deletions test/pipeline_detail_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import 'api_service_mock.dart';
void main() {
setUp(() => VisibilityDetectorController.instance.updateInterval = Duration.zero);

TestWidgetsFlutterBinding.ensureInitialized();

testWidgets(
'Pipeline detail page shows all the details',
'Page building test',
(t) async {
final detailPage = AzureApiServiceInherited(
final app = AzureApiServiceInherited(
apiService: AzureApiServiceMock(),
child: MaterialApp(
onGenerateRoute: (_) => MaterialPageRoute(
Expand All @@ -25,24 +27,11 @@ void main() {
),
);

await t.pumpWidget(detailPage);
await t.pumpWidget(app);

await t.pump();

// pipeline info
expect(find.text('Test User'), findsOneWidget);
expect(find.text('now'), findsOneWidget);
expect(find.text('TestProject'), findsOneWidget);
expect(find.text('test_repo'), findsOneWidget);

// commit info
expect(find.text('Test commit message'), findsOneWidget);
expect(find.text('123456789'), findsOneWidget);
expect(find.text('Branch: test_branch', findRichText: true), findsOneWidget);

// build info
expect(find.text('Id: 1234', findRichText: true), findsOneWidget);
expect(find.text('Number: 5678', findRichText: true), findsOneWidget);
expect(find.byType(PipelineDetailPage), findsOneWidget);
},
);
}
4 changes: 2 additions & 2 deletions test/pipeline_logs_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'api_service_mock.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

testWidgets('Pipeline logs page shows all logs', (t) async {
testWidgets('Page building test', (t) async {
final pipelineLogsPage = AzureApiServiceInherited(
apiService: AzureApiServiceMock(),
child: MaterialApp(
Expand All @@ -31,6 +31,6 @@ void main() {
await t.pumpWidget(pipelineLogsPage);
await t.pump();

expect(find.text('log test', findRichText: true), findsOneWidget);
expect(find.byType(PipelineLogsPage), findsOneWidget);
});
}
21 changes: 21 additions & 0 deletions test/pipelines_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ void main() {

TestWidgetsFlutterBinding.ensureInitialized();

testWidgets(
'Page building test',
(t) async {
final app = MaterialApp(
home: StorageServiceInherited(
storageService: StorageServiceMock(),
child: AzureApiServiceInherited(
apiService: AzureApiServiceMock(),
child: PipelinesPage(),
),
),
);

await t.pumpWidget(app);

await t.pump();

expect(find.byType(PipelinesPage), findsOneWidget);
},
);

testWidgets(
'Pipelines are sorted by status',
(t) async {
Expand Down
8 changes: 4 additions & 4 deletions test/project_detail_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import 'api_service_mock.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

testWidgets("Project detail page shows all project's informations", (t) async {
final projectPage = AzureApiServiceInherited(
testWidgets('Page building test', (t) async {
final app = AzureApiServiceInherited(
apiService: AzureApiServiceMock(),
child: MaterialApp(
onGenerateRoute: (_) => MaterialPageRoute(
Expand All @@ -22,9 +22,9 @@ void main() {
),
);

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

expect(find.text('member_2_name', findRichText: true), findsOneWidget);
expect(find.byType(ProjectDetailPage), findsOneWidget);
});
}
17 changes: 6 additions & 11 deletions test/pull_request_detail_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import 'api_service_mock.dart';
void main() {
setUp(() => VisibilityDetectorController.instance.updateInterval = Duration.zero);

TestWidgetsFlutterBinding.ensureInitialized();

testWidgets(
'Pull request detail page shows all the details',
'Page building test',
(t) async {
final detailPage = AzureApiServiceInherited(
final app = AzureApiServiceInherited(
apiService: AzureApiServiceMock(),
child: StorageServiceInherited(
storageService: StorageServiceMock(),
Expand All @@ -29,18 +31,11 @@ void main() {
),
);

await t.pumpWidget(detailPage);
await t.pumpWidget(app);

await t.pump();

expect(find.text('Id: 1234', findRichText: true), findsOneWidget);
expect(find.text('Created by: Test User Creator', findRichText: true), findsOneWidget);
expect(find.text('Active'), findsOneWidget);
expect(find.text('now'), findsOneWidget);
expect(find.text('TestProject'), findsOneWidget);
expect(find.text('Test pull request title'), findsOneWidget);
expect(find.text('From: dev', findRichText: true), findsOneWidget);
expect(find.text('To: main', findRichText: true), findsOneWidget);
expect(find.byType(PullRequestDetailPage), findsOneWidget);
},
);
}
Loading

0 comments on commit 7f1f3fb

Please sign in to comment.