Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
-1
@@ -1 +0,0 @@
|
||||
include: package:very_good_analysis/analysis_options.yaml
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
import 'package:check_platform_name/check_platform_name.dart';
|
||||
import 'package:fluttium/fluttium.dart';
|
||||
|
||||
export 'src/check_platform_name.dart';
|
||||
|
||||
/// Will be executed by Fluttium on startup.
|
||||
void register(Registry registry) {
|
||||
registry.registerAction('checkPlatformName', CheckPlatformName.new);
|
||||
}
|
||||
-70
@@ -1,70 +0,0 @@
|
||||
import 'dart:io' show Platform;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:fluttium/fluttium.dart';
|
||||
|
||||
/// {@template check_platform_name}
|
||||
/// An action that checks the expected platform name.
|
||||
///
|
||||
/// Usage:
|
||||
///
|
||||
/// ```yaml
|
||||
/// - checkPlatformName:
|
||||
/// ```
|
||||
/// {@endtemplate}
|
||||
class CheckPlatformName extends Action {
|
||||
/// {@macro check_platform_name}
|
||||
const CheckPlatformName({
|
||||
@visibleForTesting bool Function() isAndroid = _platformIsAndroid,
|
||||
@visibleForTesting bool Function() isIOS = _platformIsIOS,
|
||||
@visibleForTesting bool Function() isLinux = _platformIsLinux,
|
||||
@visibleForTesting bool Function() isMacOS = _platformIsMacOS,
|
||||
@visibleForTesting bool Function() isWindows = _platformIsWindows,
|
||||
@visibleForTesting bool isWeb = kIsWeb,
|
||||
}) : _isAndroid = isAndroid,
|
||||
_isIOS = isIOS,
|
||||
_isLinux = isLinux,
|
||||
_isMacOS = isMacOS,
|
||||
_isWindows = isWindows,
|
||||
_isWeb = isWeb;
|
||||
|
||||
final bool _isWeb;
|
||||
|
||||
final bool Function() _isAndroid;
|
||||
|
||||
final bool Function() _isIOS;
|
||||
|
||||
final bool Function() _isLinux;
|
||||
|
||||
final bool Function() _isMacOS;
|
||||
|
||||
final bool Function() _isWindows;
|
||||
|
||||
String get _expectedPlatformName {
|
||||
if (_isWeb) return 'Web';
|
||||
if (_isAndroid()) return 'Android';
|
||||
if (_isIOS()) return 'iOS';
|
||||
if (_isLinux()) return 'Linux';
|
||||
if (_isMacOS()) return 'MacOS';
|
||||
if (_isWindows()) return 'Windows';
|
||||
throw UnsupportedError('Unsupported platform ${Platform.operatingSystem}');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> execute(Tester tester) async {
|
||||
return ExpectVisible(
|
||||
text: 'Platform Name: $_expectedPlatformName',
|
||||
).execute(tester);
|
||||
}
|
||||
|
||||
@override
|
||||
String description() => 'Check platform name: "$_expectedPlatformName"';
|
||||
}
|
||||
|
||||
// coverage:ignore-start these are just wrappers for overloading
|
||||
bool _platformIsAndroid() => Platform.isAndroid;
|
||||
bool _platformIsIOS() => Platform.isIOS;
|
||||
bool _platformIsLinux() => Platform.isLinux;
|
||||
bool _platformIsMacOS() => Platform.isMacOS;
|
||||
bool _platformIsWindows() => Platform.isWindows;
|
||||
// coverage:ignore-end
|
||||
@@ -1,17 +0,0 @@
|
||||
name: check_platform_name
|
||||
description: A custom action for Fluttium.
|
||||
version: 0.1.0+1
|
||||
|
||||
environment:
|
||||
sdk: ^3.11.0
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
fluttium: ^0.1.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
mocktail: ^1.0.5
|
||||
very_good_analysis: ^10.2.0
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
import 'package:check_platform_name/check_platform_name.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fluttium/fluttium.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
|
||||
class _MockRegister extends Mock implements Registry {}
|
||||
|
||||
void main() {
|
||||
test('can be registered', () {
|
||||
final registry = _MockRegister();
|
||||
when(
|
||||
() => registry.registerAction(
|
||||
any(),
|
||||
any(),
|
||||
shortHandIs: any(named: 'shortHandIs'),
|
||||
),
|
||||
).thenAnswer((_) {});
|
||||
|
||||
register(registry);
|
||||
|
||||
verify(
|
||||
() => registry.registerAction(
|
||||
any(that: equals('checkPlatformName')),
|
||||
any(that: equals(CheckPlatformName.new)),
|
||||
shortHandIs: any(named: 'shortHandIs', that: isNull),
|
||||
),
|
||||
).called(1);
|
||||
});
|
||||
}
|
||||
-136
@@ -1,136 +0,0 @@
|
||||
import 'package:check_platform_name/check_platform_name.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fluttium/fluttium.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
|
||||
class _MockTester extends Mock implements Tester {}
|
||||
|
||||
class _MockSemanticsNode extends Mock implements SemanticsNode {
|
||||
@override
|
||||
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
group(CheckPlatformName, () {
|
||||
late Tester tester;
|
||||
late SemanticsNode node;
|
||||
|
||||
setUp(() {
|
||||
tester = _MockTester();
|
||||
node = _MockSemanticsNode();
|
||||
|
||||
when(() => tester.find(any())).thenAnswer((_) async => node);
|
||||
});
|
||||
|
||||
test('executes returns true if node was found', () async {
|
||||
const action = CheckPlatformName();
|
||||
|
||||
expect(await action.execute(tester), isTrue);
|
||||
});
|
||||
|
||||
test('executes returns false if node was not found', () async {
|
||||
when(() => tester.find(any())).thenAnswer((_) async => null);
|
||||
|
||||
const action = CheckPlatformName();
|
||||
|
||||
expect(await action.execute(tester), isFalse);
|
||||
});
|
||||
|
||||
test('show correct description for every platform', () {
|
||||
bool isTrue() => true;
|
||||
bool isFalse() => false;
|
||||
|
||||
final testCases = [
|
||||
(
|
||||
'Android',
|
||||
CheckPlatformName(
|
||||
isAndroid: isTrue,
|
||||
isIOS: isFalse,
|
||||
isWeb: isFalse(),
|
||||
isWindows: isFalse,
|
||||
isLinux: isFalse,
|
||||
isMacOS: isFalse,
|
||||
),
|
||||
),
|
||||
(
|
||||
'iOS',
|
||||
CheckPlatformName(
|
||||
isAndroid: isFalse,
|
||||
isIOS: isTrue,
|
||||
isWeb: isFalse(),
|
||||
isWindows: isFalse,
|
||||
isLinux: isFalse,
|
||||
isMacOS: isFalse,
|
||||
),
|
||||
),
|
||||
(
|
||||
'Web',
|
||||
CheckPlatformName(
|
||||
isAndroid: isFalse,
|
||||
isIOS: isFalse,
|
||||
isWeb: isTrue(),
|
||||
isWindows: isFalse,
|
||||
isLinux: isFalse,
|
||||
isMacOS: isFalse,
|
||||
),
|
||||
),
|
||||
(
|
||||
'Linux',
|
||||
CheckPlatformName(
|
||||
isAndroid: isFalse,
|
||||
isIOS: isFalse,
|
||||
isWeb: isFalse(),
|
||||
isWindows: isFalse,
|
||||
isLinux: isTrue,
|
||||
isMacOS: isFalse,
|
||||
),
|
||||
),
|
||||
(
|
||||
'MacOS',
|
||||
CheckPlatformName(
|
||||
isAndroid: isFalse,
|
||||
isIOS: isFalse,
|
||||
isWeb: isFalse(),
|
||||
isWindows: isFalse,
|
||||
isLinux: isFalse,
|
||||
isMacOS: isTrue,
|
||||
),
|
||||
),
|
||||
(
|
||||
'Windows',
|
||||
CheckPlatformName(
|
||||
isAndroid: isFalse,
|
||||
isIOS: isFalse,
|
||||
isWeb: isFalse(),
|
||||
isWindows: isTrue,
|
||||
isLinux: isFalse,
|
||||
isMacOS: isFalse,
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
for (final testCase in testCases) {
|
||||
expect(
|
||||
testCase.$2.description(),
|
||||
equals('Check platform name: "${testCase.$1}"'),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('throws UnsupportedError on unknown platform', () {
|
||||
final action = CheckPlatformName(
|
||||
isAndroid: () => false,
|
||||
isIOS: () => false,
|
||||
isWeb: false,
|
||||
isWindows: () => false,
|
||||
isLinux: () => false,
|
||||
isMacOS: () => false,
|
||||
);
|
||||
|
||||
expect(action.description, throwsUnsupportedError);
|
||||
});
|
||||
});
|
||||
}
|
||||
+5
-1
@@ -9,7 +9,11 @@ dev_dependencies:
|
||||
workspace:
|
||||
- apps
|
||||
- packages/toaster_ui
|
||||
- plugins/toaster_utils/*
|
||||
- plugins/toaster_utils/toaster_utils
|
||||
- plugins/toaster_utils/toaster_utils_android
|
||||
- plugins/toaster_utils/toaster_utils_ios
|
||||
- plugins/toaster_utils/toaster_utils_macos
|
||||
- plugins/toaster_utils/toaster_utils_platform_interface
|
||||
|
||||
melos:
|
||||
scripts:
|
||||
|
||||
Reference in New Issue
Block a user