85 lines
2.8 KiB
Dart
85 lines
2.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:reelbox/data/models.dart';
|
|
import 'package:reelbox/media/media_platform.dart';
|
|
import 'package:reelbox/ui/catalog.dart';
|
|
|
|
import 'catalog_widget_test.dart' show CatalogApi, mountCatalog;
|
|
|
|
void main() {
|
|
testWidgets(
|
|
'source has a visible external-player button independent of preference',
|
|
(tester) async {
|
|
final calls = <MethodCall>[];
|
|
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
MediaPlatform.channel,
|
|
(call) async {
|
|
calls.add(call);
|
|
return call.method == 'openExternal';
|
|
},
|
|
);
|
|
addTearDown(() {
|
|
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
MediaPlatform.channel,
|
|
null,
|
|
);
|
|
});
|
|
final state = await mountCatalog(
|
|
tester,
|
|
CatalogApi(),
|
|
const TitlePage(title: TitleRecord(id: 7, title: 'Fixture')),
|
|
);
|
|
addTearDown(state.dispose);
|
|
expect(state.prefs.externalPlayer, false);
|
|
final button = find.widgetWithText(TextButton, 'External player').first;
|
|
await tester.ensureVisible(button);
|
|
await tester.tap(button);
|
|
await tester.pumpAndSettle();
|
|
final call = calls.singleWhere((call) => call.method == 'openExternal');
|
|
expect(call.arguments['url'], 'https://media.example/movie.mp4');
|
|
expect(call.arguments['packageName'], 'ask');
|
|
expect(state.prefs.externalPlayer, false);
|
|
expect(tester.takeException(), isNull);
|
|
},
|
|
variant: TargetPlatformVariant.only(TargetPlatform.android),
|
|
);
|
|
|
|
testWidgets(
|
|
'external-player failure is recoverable without opening an internal decoder',
|
|
(tester) async {
|
|
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
MediaPlatform.channel,
|
|
(call) async {
|
|
if (call.method == 'openExternal') {
|
|
throw PlatformException(code: 'NO_PLAYER');
|
|
}
|
|
return null;
|
|
},
|
|
);
|
|
addTearDown(() {
|
|
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
MediaPlatform.channel,
|
|
null,
|
|
);
|
|
});
|
|
final state = await mountCatalog(
|
|
tester,
|
|
CatalogApi(),
|
|
const TitlePage(title: TitleRecord(id: 7, title: 'Fixture')),
|
|
);
|
|
addTearDown(state.dispose);
|
|
final button = find.widgetWithText(TextButton, 'External player').first;
|
|
await tester.ensureVisible(button);
|
|
await tester.tap(button);
|
|
await tester.pump();
|
|
expect(
|
|
find.text('No external player could open this source.'),
|
|
findsOneWidget,
|
|
);
|
|
expect(tester.takeException(), isNull);
|
|
},
|
|
variant: TargetPlatformVariant.only(TargetPlatform.android),
|
|
);
|
|
}
|