-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
161 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,89 @@ | ||
// This is a basic Flutter widget test. | ||
// | ||
// To perform an interaction with a widget in your test, use the WidgetTester | ||
// utility in the flutter_test package. For example, you can send tap and scroll | ||
// gestures. You can also use WidgetTester to find child widgets in the widget | ||
// tree, read text, and verify that the values of widget properties are correct. | ||
import 'dart:io'; | ||
|
||
import 'package:catcher_2/catcher_2.dart'; // Import Catcher | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; // Import flutter services | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:sanmill/game_page/services/engine/bitboard.dart'; | ||
import 'package:sanmill/generated/intl/l10n.dart'; | ||
import 'package:sanmill/home/home.dart'; | ||
import 'package:sanmill/main.dart'; | ||
import 'package:sanmill/shared/database/database.dart'; | ||
|
||
void main() { | ||
testWidgets('Counter increments smoke test', (WidgetTester tester) async { | ||
// Build our app and trigger a frame. | ||
// Ensure the binding is initialized before tests run | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
// Define the MethodChannel to be mocked | ||
const MethodChannel engineChannel = | ||
MethodChannel("com.calcitem.sanmill/engine"); | ||
|
||
// Set up a mock method channel handler for 'path_provider' | ||
const MethodChannel pathProviderChannel = | ||
MethodChannel('plugins.flutter.io/path_provider'); | ||
|
||
setUpAll(() async { | ||
// Mock the `catcher` initialization for testing | ||
catcher = Catcher2( | ||
rootWidget: const Placeholder(), // Use a minimal widget for testing | ||
ensureInitialized: true, | ||
); | ||
|
||
// Use the new API to set up mock handlers for MethodChannel | ||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger | ||
.setMockMethodCallHandler(engineChannel, (MethodCall methodCall) async { | ||
switch (methodCall.method) { | ||
case 'send': | ||
return null; // Return a success response | ||
case 'shutdown': | ||
return null; // Return a success response | ||
case 'startup': | ||
return null; // Return a success response | ||
case 'read': | ||
return 'bestmove d2'; // Simulate a response for the 'read' method | ||
case 'isThinking': | ||
return false; // Simulate the 'isThinking' method response | ||
default: | ||
return null; // For unhandled methods, return null | ||
} | ||
}); | ||
|
||
// Mock the 'getApplicationDocumentsDirectory' method | ||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger | ||
.setMockMethodCallHandler(pathProviderChannel, | ||
(MethodCall methodCall) async { | ||
if (methodCall.method == 'getApplicationDocumentsDirectory') { | ||
// Return a temporary directory path | ||
final Directory directory = Directory.systemTemp.createTempSync(); | ||
return directory.path; | ||
} | ||
return null; | ||
}); | ||
|
||
// Initialize the database and other services | ||
await DB.init(); | ||
await initializeUI(true); | ||
initBitboards(); | ||
}); | ||
|
||
testWidgets('SanmillApp smoke test', (WidgetTester tester) async { | ||
// Build the app and trigger a frame | ||
await tester.pumpWidget(const SanmillApp()); | ||
|
||
// Verify that our counter starts at 0. | ||
expect(find.text('0'), findsOneWidget); | ||
expect(find.text('1'), findsNothing); | ||
// Verify that MaterialApp and Scaffold are present | ||
expect(find.byType(MaterialApp), findsOneWidget); | ||
expect(find.byType(Scaffold), findsWidgets); | ||
}); | ||
|
||
testWidgets('Verify app navigation and localization', | ||
(WidgetTester tester) async { | ||
// Build the app and trigger a frame | ||
await tester.pumpWidget(const SanmillApp()); | ||
|
||
// Tap the '+' icon and trigger a frame. | ||
await tester.tap(find.byIcon(Icons.add)); | ||
await tester.pump(); | ||
// Check that the supported locales include English | ||
expect(S.supportedLocales.contains(const Locale('en')), isTrue); | ||
|
||
// Verify that our counter has incremented. | ||
expect(find.text('0'), findsNothing); | ||
expect(find.text('1'), findsOneWidget); | ||
// Verify that the Home widget is present | ||
expect(find.byType(Home), findsOneWidget); | ||
}); | ||
} |