Skip to content

Commit

Permalink
fix unstable widget test on windows/ubuntu (#47)
Browse files Browse the repository at this point in the history
* fix wrong path string
* check mounted? See: https://github.com/sensuikan1973/pedax/runs/1963322568
* 200millisec -> 400millisec
* use path package
  • Loading branch information
sensuikan1973 committed Feb 23, 2021
1 parent a422a10 commit 3b2f913
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 37 deletions.
4 changes: 2 additions & 2 deletions integration_test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ Future<void> main() async {
expect(find.byType(Home), findsOneWidget);
expect(find.byType(PedaxBoard), findsOneWidget);

await delay200millisec(tester);
await delay400millisec(tester);
await tester.pump();
expectStoneNum(tester, SquareType.black, 2); // e4, d5

await tester.tap(findByCoordinate('f5'));
await delay200millisec(tester);
await delay400millisec(tester);
await tester.pump();
expectStoneNum(tester, SquareType.black, 4); // e4, d5, e5, f5
});
Expand Down
1 change: 1 addition & 0 deletions lib/board/pedax_board.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class _PedaxBoardState extends State<PedaxBoard> {
const BookFileOption().val.then(
(path) {
WidgetsBinding.instance?.addPostFrameCallback((_) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(AppLocalizations.of(context)!.loadingBookFile, textAlign: TextAlign.center),
Expand Down
5 changes: 3 additions & 2 deletions lib/engine/edax_asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as p;

import 'options/book_file_option.dart';
import 'options/edax_option.dart';
Expand Down Expand Up @@ -39,8 +40,8 @@ class EdaxAsset {
if (Platform.isMacOS) return defaultLibedaxName;
// FIXME: temporary implement.
final docDir = await _docDir;
if (Platform.isWindows) return '${docDir.path}/$defaultLibedaxName';
if (Platform.isLinux) return '${docDir.path}/$defaultLibedaxName';
if (Platform.isWindows) return p.join(docDir.path, defaultLibedaxName);
if (Platform.isLinux) return p.join(docDir.path, defaultLibedaxName);
throw Exception('${Platform.operatingSystem} is not supported');
}

Expand Down
5 changes: 3 additions & 2 deletions lib/engine/options/book_file_option.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:logger/logger.dart';
import 'package:path/path.dart' as p;

import 'edax_option.dart';

Expand All @@ -15,10 +16,10 @@ class BookFileOption extends EdaxOption<String> {
String get prefKey => 'bookFilePath';

@override
String get nativeDefaultValue => 'data/$_defaultFileName'; // relative path
String get nativeDefaultValue => p.join('data', _defaultFileName); // relative path

@override
Future<String> get appDefaultValue async => '${(await docDir).path}/$_defaultFileName';
Future<String> get appDefaultValue async => p.join((await docDir).path, _defaultFileName);

String get _defaultFileName => 'book.dat';

Expand Down
5 changes: 3 additions & 2 deletions lib/engine/options/eval_file_option.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:logger/logger.dart';
import 'package:path/path.dart' as p;

import 'edax_option.dart';

Expand All @@ -15,10 +16,10 @@ class EvalFileOption extends EdaxOption<String> {
String get prefKey => 'evalFilePath';

@override
String get nativeDefaultValue => 'data/$_defaultFileName'; // relative path
String get nativeDefaultValue => p.join('data', _defaultFileName); // relative path

@override
Future<String> get appDefaultValue async => '${(await docDir).path}/$_defaultFileName';
Future<String> get appDefaultValue async => p.join((await docDir).path, _defaultFileName);

String get _defaultFileName => 'eval.dat';

Expand Down
2 changes: 1 addition & 1 deletion lib/home/book_file_path_setting_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class BookFilePathSettingDialog extends StatelessWidget {
final currentBookFilePath = await _option.val;
if (newBookFilePath == currentBookFilePath) return Navigator.pop(context);
await _option.update(newBookFilePath);
edaxServerPort.send(BookLoadRequest(newBookFilePath));
edaxServerPort.send(BookLoadRequest(await _option.val));
Navigator.pop(context);
},
child: Text(AppLocalizations.of(context)!.updateSettingOnDialog),
Expand Down
8 changes: 4 additions & 4 deletions test/debug_dump_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void main() {
await tester.pumpAndSettle();
await waitEdaxSetuped(tester);
debugDumpApp();
await delay200millisec(tester);
await delay400millisec(tester);
});
});

Expand All @@ -59,7 +59,7 @@ void main() {
await tester.pumpAndSettle();
await waitEdaxSetuped(tester);
debugDumpApp();
await delay200millisec(tester);
await delay400millisec(tester);
});
});

Expand All @@ -72,7 +72,7 @@ void main() {
await tester.pumpAndSettle();
await waitEdaxSetuped(tester);
debugDumpApp();
await delay200millisec(tester);
await delay400millisec(tester);
});
});

Expand All @@ -85,7 +85,7 @@ void main() {
await tester.pumpAndSettle();
await waitEdaxSetuped(tester);
debugDumpApp();
await delay200millisec(tester);
await delay400millisec(tester);
});
});
}
5 changes: 2 additions & 3 deletions test/first_launch_app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ void main() {
expectStoneNum(tester, SquareType.black, 2); // e4, d5

await tester.tap(findByCoordinate('f5'));
// await delay200millisec(tester);
await Future<void>.delayed(const Duration(seconds: 1));
await delay400millisec(tester);
await tester.pump();
expectStoneNum(tester, SquareType.black, 4); // e4, d5, e5, f5
await delay200millisec(tester);
await delay400millisec(tester);
});
});
}
30 changes: 14 additions & 16 deletions test/home_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,27 @@ Future<void> main() async {
expectStoneNum(tester, SquareType.black, 2); // e4, d5

await tester.tap(findByCoordinate('f5'));
// await delay200millisec(tester);
await Future<void>.delayed(const Duration(seconds: 1));
await delay400millisec(tester);
await tester.pump();
expectStoneNum(tester, SquareType.black, 4); // e4, d5, e5, f5

await tester.tap(findByCoordinate('f4'));
await delay200millisec(tester);
await delay400millisec(tester);
await tester.pump();
expectStoneNum(tester, SquareType.black, 3); // d5, e5, f5

await tester.tap(findByCoordinate('e3'));
await delay200millisec(tester);
await delay400millisec(tester);
await tester.pump();
expectStoneNum(tester, SquareType.black, 5); // e3, e4, d5, e5, f5

await tester.sendKeyEvent(LogicalKeyboardKey.keyU);
await delay200millisec(tester);
await delay400millisec(tester);
await tester.pump();
expectStoneNum(tester, SquareType.black, 3); // d5, e5, f5

await tester.sendKeyEvent(LogicalKeyboardKey.keyR);
// await delay200millisec(tester);
await Future<void>.delayed(const Duration(seconds: 1));
await delay400millisec(tester);
await tester.pump();
expectStoneNum(tester, SquareType.black, 5); // e3, e4, d5, e5, f5

Expand All @@ -74,7 +72,7 @@ Future<void> main() async {
await tester.tap(find.text(l10nEn.license));
await tester.pumpAndSettle();
expect(find.byType(LicensePage), findsOneWidget);
await delay200millisec(tester);
await delay400millisec(tester);
});
});

Expand All @@ -93,7 +91,7 @@ Future<void> main() async {
await tester.tap(find.text(l10nEn.cancelOnDialog));
await tester.pump();
expect(find.byType(PedaxApp), findsOneWidget);
await delay200millisec(tester);
await delay400millisec(tester);
});
});

Expand All @@ -113,7 +111,7 @@ Future<void> main() async {
await tester.tap(find.text(l10nEn.updateSettingOnDialog));
await tester.pumpAndSettle();
expect(find.byType(BookFilePathSettingDialog), findsOneWidget); // nothing happens and dialog isn't closed
await delay200millisec(tester);
await delay400millisec(tester);
});
});

Expand All @@ -134,7 +132,7 @@ Future<void> main() async {
await tester.pumpAndSettle();
await Future<void>.delayed(const Duration(seconds: 1));
expect(find.byType(BookFilePathSettingDialog), findsNothing);
await delay200millisec(tester);
await delay400millisec(tester);
});
});

Expand All @@ -154,7 +152,7 @@ Future<void> main() async {
await tester.pumpAndSettle();
await Future<void>.delayed(const Duration(seconds: 1));
expect(find.byType(BookFilePathSettingDialog), findsNothing);
await delay200millisec(tester);
await delay400millisec(tester);
});
});

Expand All @@ -172,7 +170,7 @@ Future<void> main() async {
await tester.tap(find.text(l10nEn.cancelOnDialog));
await tester.pump();
expect(find.byType(PedaxApp), findsOneWidget);
await delay200millisec(tester);
await delay400millisec(tester);
});
});

Expand All @@ -193,7 +191,7 @@ Future<void> main() async {
await tester.pumpAndSettle();
await Future<void>.delayed(const Duration(seconds: 1));
expect(find.byType(NTasksSettingDialog), findsNothing);
await delay200millisec(tester);
await delay400millisec(tester);
});
});

Expand All @@ -212,7 +210,7 @@ Future<void> main() async {
await tester.tap(find.text(l10nEn.cancelOnDialog));
await tester.pump();
expect(find.byType(PedaxApp), findsOneWidget);
await delay200millisec(tester);
await delay400millisec(tester);
});
});

Expand All @@ -233,7 +231,7 @@ Future<void> main() async {
await tester.pumpAndSettle();
await Future<void>.delayed(const Duration(seconds: 1));
expect(find.byType(LevelSettingDialog), findsNothing);
await delay200millisec(tester);
await delay400millisec(tester);
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions test_helper/async_delay.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:meta/meta.dart';

// For EdaxServer: expect move response ~ rendering is less than 200 millisec
// For EdaxServer: expect move response ~ rendering is less than 400 millisec
@isTest
Future<void> delay200millisec(WidgetTester tester) async => Future<void>.delayed(const Duration(milliseconds: 200));
Future<void> delay400millisec(WidgetTester tester) async => Future<void>.delayed(const Duration(milliseconds: 400));
4 changes: 1 addition & 3 deletions test_helper/edax_server.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:meta/meta.dart';

import 'async_delay.dart';

@isTest
Future<void> waitEdaxSetuped(WidgetTester tester) async {
await Future<void>.delayed(const Duration(seconds: 1));
await tester.pump(); // after spwaning EdaxServer has completed, render UI.
await delay200millisec(tester); // awit EdaxServer execute edax_init.
await Future<void>.delayed(const Duration(seconds: 1)); // awit EdaxServer execute edax_init.
await tester.pump(); // after edax init has completed, render UI.
}

0 comments on commit 3b2f913

Please sign in to comment.