Skip to content

Commit

Permalink
fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelaziz-mahdy committed Dec 22, 2023
1 parent 0931b1e commit 4df7200
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 31 deletions.
24 changes: 14 additions & 10 deletions integration_test/test.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:io';

import 'package:bouncy_ball_physics/ball_painter.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

Expand All @@ -13,15 +13,16 @@ void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
const String screenshotMode =
String.fromEnvironment('SCREENSHOT_MODE', defaultValue: 'desktop');

group('Test App', () {
// Test for 'Line' Dropdown
testWidgets('Test with take screenshot for Line', (tester) async {
Widget app = MyApp();
Widget app = const MyApp();
await tester.pumpFrames(app, const Duration(seconds: 5));

// try to find the dropdown
expect(find.byType(DropdownButton<TrailShape>), findsOneWidget);
// Open the dropdown
await tester.tap(find.byType(DropdownButton));
await tester.tap(find.byType(DropdownButton<TrailShape>));
await tester.pumpFrames(
app, const Duration(milliseconds: 500)); // Adjust time as needed

Expand All @@ -37,11 +38,12 @@ void main() {
// Test for 'Single Triangle' Dropdown
testWidgets('Test with take screenshot for Single Triangle',
(tester) async {
Widget app = MyApp();
Widget app = const MyApp();
await tester.pumpFrames(app, const Duration(seconds: 5));

// try to find the dropdown
expect(find.byType(DropdownButton<TrailShape>), findsOneWidget);
// Open the dropdown
await tester.tap(find.byType(DropdownButton));
await tester.tap(find.byType(DropdownButton<TrailShape>));
await tester.pumpFrames(app, const Duration(milliseconds: 500));

var label = 'Single Triangle';
Expand All @@ -55,11 +57,13 @@ void main() {
// Test for 'Multiple Triangles' Dropdown
testWidgets('Test with take screenshot for Multiple Triangles',
(tester) async {
Widget app = MyApp();
Widget app = const MyApp();
await tester.pumpFrames(app, const Duration(seconds: 5));

// try to find the dropdown
expect(find.byType(DropdownButton<TrailShape>), findsOneWidget);
// Open the dropdown
await tester.tap(find.byType(DropdownButton));
await tester.tap(find.byType(DropdownButton<TrailShape>));
await tester.pumpFrames(app, const Duration(milliseconds: 500));

var label = 'Multiple Triangles';
Expand Down
10 changes: 5 additions & 5 deletions lib/ball_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class BallPainter extends CustomPainter {
List<Ball> balls;
TrailShape trailShape;

BallPainter(
{required this.balls, this.trailShape = TrailShape.line});
BallPainter({required this.balls, this.trailShape = TrailShape.line});

final Map<Color, Paint> _paintCache = {};

Expand Down Expand Up @@ -49,9 +48,10 @@ class BallPainter extends CustomPainter {
}

void _drawLineTrail(Canvas canvas, Ball ball, Paint paint) {
for (var i = 0; i < ball.trail.length - 1; i++) {
canvas.drawLine(ball.trail[i], ball.trail[i + 1], paint..strokeWidth = ball.radius / 10);
}
for (var i = 0; i < ball.trail.length - 1; i++) {
canvas.drawLine(ball.trail[i], ball.trail[i + 1],
paint..strokeWidth = ball.radius / 10);
}
}

void _drawSingleTriangleTrail(Canvas canvas, Ball ball, Paint paint) {
Expand Down
19 changes: 7 additions & 12 deletions lib/ball_physics_widget.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import 'dart:math';

import 'package:bouncy_ball_physics/ball.dart';
import 'package:bouncy_ball_physics/trail_shape_selector.dart';
import 'package:flutter/material.dart';

import 'ball_painter.dart';

import 'dart:math';
import 'package:flutter/material.dart';
import 'package:bouncy_ball_physics/ball_painter.dart';
import 'package:bouncy_ball_physics/trail_shape_selector.dart';
import 'package:bouncy_ball_physics/ball_physics_manager.dart';

class BallPhysicsWidget extends StatefulWidget {
Expand Down Expand Up @@ -110,13 +103,15 @@ class BallPhysicsWidgetState extends State<BallPhysicsWidget>
children: [
const Text("Balls Limit"),
ValueListenableBuilder(
valueListenable:manager. ballLimitNotifier,
valueListenable: manager.ballLimitNotifier,
builder: (BuildContext context, int value, Widget? child) {
return Slider(
value: manager.ballLimitNotifier.value.toDouble(),
min: manager.slidersMinValue,
max: manager.slidersMaxValue,
divisions: (manager.slidersMaxValue - manager.slidersMinValue).toInt(),
divisions:
(manager.slidersMaxValue - manager.slidersMinValue)
.toInt(),
label: manager.ballLimitNotifier.value.toString(),
onChanged: (double value) {
manager.ballLimitNotifier.value = value.toInt();
Expand All @@ -131,7 +126,9 @@ class BallPhysicsWidgetState extends State<BallPhysicsWidget>
value: manager.tailLengthNotifier.value.toDouble(),
min: manager.slidersMinValue,
max: manager.slidersMaxValue,
divisions: (manager.slidersMaxValue - manager.slidersMinValue).toInt(),
divisions:
(manager.slidersMaxValue - manager.slidersMinValue)
.toInt(),
label: manager.tailLengthNotifier.value.toString(),
onChanged: (double value) {
manager.tailLengthNotifier.value = value.toInt();
Expand All @@ -153,8 +150,6 @@ class BallPhysicsWidgetState extends State<BallPhysicsWidget>
@override
void dispose() {
_controller.dispose();
manager.ballCountNotifier.dispose();
// ... [dispose other notifiers in manager]
super.dispose();
}
}
6 changes: 3 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import 'package:bouncy_ball_physics/ball_physics_widget.dart';
import 'package:flutter/material.dart';

void main() {
runApp(MyApp());
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
MyApp({super.key});
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Ball Physics')),
body: BallPhysicsWidget(), // Use the key here
body: const BallPhysicsWidget(), // Use the key here
floatingActionButton: FloatingActionButton(
onPressed: () {
// Call the reset method using the key
Expand Down
Binary file modified screenshots/test-Line-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/test-Multiple-Triangles-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/test-Single-Triangle-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());
await tester.pumpWidget(const MyApp());

// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
Expand Down

0 comments on commit 4df7200

Please sign in to comment.