Initial commit
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:smplayer/core/contracts/playback.dart';
|
||||
import 'package:smplayer/core/domain/ports/emby_gateway.dart';
|
||||
import 'package:smplayer/features/player/services/emby_playback_reporter.dart';
|
||||
|
||||
class _CountingEmbyGateway implements EmbyGateway {
|
||||
int startedCount = 0;
|
||||
int progressCount = 0;
|
||||
int stoppedCount = 0;
|
||||
|
||||
@override
|
||||
Future<void> reportPlaybackProgress({
|
||||
required AuthedRequestContext ctx,
|
||||
required PlaybackReportPayload payload,
|
||||
}) async {
|
||||
progressCount++;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> reportPlaybackStarted({
|
||||
required AuthedRequestContext ctx,
|
||||
required PlaybackReportPayload payload,
|
||||
}) async {
|
||||
startedCount++;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> reportPlaybackStopped({
|
||||
required AuthedRequestContext ctx,
|
||||
required PlaybackReportPayload payload,
|
||||
}) async {
|
||||
stoppedCount++;
|
||||
}
|
||||
|
||||
@override
|
||||
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('禁用的上报器不会向 Emby 发送任何播放事件', () async {
|
||||
final gateway = _CountingEmbyGateway();
|
||||
final reporter = EmbyPlaybackReporter(
|
||||
gateway: gateway,
|
||||
context: const AuthedRequestContext(baseUrl: '', token: '', userId: ''),
|
||||
enabled: false,
|
||||
);
|
||||
addTearDown(reporter.dispose);
|
||||
const payload = PlaybackReportPayload(itemId: 'direct', positionTicks: 0);
|
||||
|
||||
await reporter.reportStarted(payload);
|
||||
await reporter.reportProgress(payload);
|
||||
await reporter.reportStopped(payload);
|
||||
reporter.startProgressTimer(
|
||||
({required bool isPaused, String? eventName}) => PlaybackReportPayload(
|
||||
itemId: 'direct',
|
||||
positionTicks: 0,
|
||||
isPaused: isPaused,
|
||||
eventName: eventName,
|
||||
),
|
||||
);
|
||||
|
||||
expect(gateway.startedCount, 0);
|
||||
expect(gateway.progressCount, 0);
|
||||
expect(gateway.stoppedCount, 0);
|
||||
expect(reporter.startedReported, isFalse);
|
||||
expect(reporter.stoppedReported, isFalse);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user