Skip to content

Commit

Permalink
test: integration_test 30% coverage on examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ali77gh committed Mar 27, 2023
1 parent b29f615 commit 60b1953
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 127 deletions.
65 changes: 65 additions & 0 deletions example/integration_test/01_simple_text_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

import 'package:app/01_simple_text_sample/main.dart' as example01;
import 'package:app/02_object_apply_sample/main.dart' as example02;
import 'package:app/03_depend_observable_sample/main.dart' as example03;

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

testWidgets('simple text', (tester) async {
example01.main();
await tester.pumpAndSettle();

expect(find.text(''), findsNWidgets(2));
expect(find.text('0'), findsOneWidget);

await tester.tap(find.text('0'));
await tester.pumpAndSettle(); // Trigger a frame.

expect(find.text('a'), findsNWidgets(2));
expect(find.text('1'), findsOneWidget);

await tester.tap(find.text('1'));
await tester.pumpAndSettle(); // Trigger a frame.

expect(find.text('aa'), findsNWidgets(2));
expect(find.text('2'), findsOneWidget);
});

testWidgets('object apply', (tester) async {
example02.main();
await tester.pumpAndSettle();

expect(find.text('Ali is 24 years old.'), findsOneWidget);

await tester.tap(find.text('Ali is 24 years old.'));
await tester.pumpAndSettle(); // Trigger a frame.

expect(find.text('Ali is 25 years old.'), findsOneWidget);
});


testWidgets('bmi', (tester) async {
example03.main();
await tester.pumpAndSettle();
var initResult = tester.allWidgets.whereType<Text>().last.data!;

await tester.tap(find.byType(Slider).first);
await tester.pumpAndSettle(); // Trigger a frame.

await tester.tap(find.byType(Slider).last);
await tester.pumpAndSettle(); // Trigger a frame.

var weight = tester.allWidgets.whereType<Slider>().first.value;
var height = tester.allWidgets.whereType<Slider>().last.value;
var result = tester.allWidgets.whereType<Text>().last.data!;

var bmi = weight/ ((height/ 100) * (height / 100));

expect(result.contains("$bmi"), true);
expect(initResult != result, true);
});
}
16 changes: 0 additions & 16 deletions example/lib/02_object_apply_sample/main.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import 'package:app/02_object_apply_sample/object_apply_sample.dart';
import 'package:flutter/material.dart';

class Human {
String name;
int age;
Human(this.name, this.age);

@override
String toString() {
return "$name is $age years old.";
}

@override
int get hashCode => (name.hashCode) * age.hashCode;

@override
bool operator ==(Object other) => hashCode == other.hashCode;
}

void main() {
runApp(const MyApp());
Expand Down
19 changes: 17 additions & 2 deletions example/lib/02_object_apply_sample/object_apply_sample.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:app/02_object_apply_sample/main.dart';
import 'package:flutter/material.dart';
import 'package:telescope/telescope.dart';

Expand All @@ -11,7 +10,7 @@ class ObjectApplySampleLayout extends StatefulWidget {
}

class ObjectApplySampleLayoutState extends State<ObjectApplySampleLayout> {
var human = Telescope<Human>(Human("Ali", 23));
var human = Telescope<Human>(Human("Ali", 24));

@override
Widget build(BuildContext context) {
Expand All @@ -36,3 +35,19 @@ class ObjectApplySampleLayoutState extends State<ObjectApplySampleLayout> {
)));
}
}
class Human {
String name;
int age;
Human(this.name, this.age);

@override
String toString() {
return "$name is $age years old.";
}

@override
int get hashCode => (name.hashCode) * age.hashCode;

@override
bool operator ==(Object other) => hashCode == other.hashCode;
}
76 changes: 38 additions & 38 deletions example/lib/03_depend_observable_sample/depends_on_sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,44 @@ class DependObservableSampleLayoutState
type: MaterialType.transparency,
child: SafeArea(
child: Container(
color: Colors.white,
child: Column(
children: [
const SizedBox(height: 20),
Text(
"Weight(kg):",
style: style,
color: Colors.white,
child: Column(
children: [
const SizedBox(height: 20),
Text(
"Weight(kg):",
style: style,
),
Slider(
value: weight.watch(this).toDouble(),
min: 1,
max: 200,
label: weight.watch(this).round().toString(),
onChanged: (double value) {
weight.value = value.toInt();
}),
Text(
"Height(cm):",
style: style,
),
Slider(
value: height.watch(this).toDouble(),
min: 1,
max: 200,
label: height.watch(this).round().toString(),
onChanged: (double value) {
height.value = value.toInt();
}),
Text(
"Result:",
style: style,
),
Text(
showingText.watch(this),
style: style,
),
],
),
Slider(
value: weight.watch(this).toDouble(),
min: 1,
max: 200,
label: weight.watch(this).round().toString(),
onChanged: (double value) {
weight.value = value.toInt();
}),
Text(
"Height(cm):",
style: style,
),
Slider(
value: height.watch(this).toDouble(),
min: 1,
max: 200,
label: height.watch(this).round().toString(),
onChanged: (double value) {
height.value = value.toInt();
}),
Text(
"Result:",
style: style,
),
Text(
showingText.watch(this),
style: style,
),
],
),
)));
)));
}
}
59 changes: 58 additions & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.11"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -43,6 +50,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.16.0"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
cupertino_icons:
dependency: "direct main"
description:
Expand Down Expand Up @@ -70,12 +84,17 @@ packages:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.4"
version: "6.1.2"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_driver:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
Expand All @@ -93,6 +112,16 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
fuchsia_remote_debug_protocol:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
integration_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
js:
dependency: transitive
description:
Expand Down Expand Up @@ -266,6 +295,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
sync_http:
dependency: transitive
description:
name: sync_http
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
telescope:
dependency: "direct main"
description:
Expand All @@ -287,13 +323,34 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
vm_service:
dependency: transitive
description:
name: vm_service
url: "https://pub.dartlang.org"
source: hosted
version: "8.2.2"
webdriver:
dependency: transitive
description:
name: webdriver
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
win32:
dependency: transitive
description:
Expand Down
Loading

0 comments on commit 60b1953

Please sign in to comment.