import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:smplayer/features/detail/android/android_detail_geometry.dart';
import 'package:smplayer/features/detail/widgets/detail_scroll_progress.dart';

void main() {
  testWidgets('landscape banner height respects the body height limit', (
    tester,
  ) async {
    late double bannerHeight;
    late double collapseExtent;

    await tester.pumpWidget(
      MediaQuery(
        data: const MediaQueryData(
          size: Size(800, 400),
          padding: EdgeInsets.only(top: 24),
        ),
        child: Builder(
          builder: (context) {
            bannerHeight = computeAndroidDetailBannerHeight(context);
            collapseExtent = computeAndroidDetailCollapseExtent(context);
            return const SizedBox.shrink();
          },
        ),
      ),
    );

    expect(bannerHeight, closeTo(206.8, 0.01));
    expect(collapseExtent, closeTo(138.8, 0.01));
  });

  testWidgets('scroll progress reaches one at the collapse extent', (
    tester,
  ) async {
    late double halfProgress;
    late double completeProgress;

    await tester.pumpWidget(
      MediaQuery(
        data: const MediaQueryData(size: Size(400, 800)),
        child: Builder(
          builder: (context) {
            halfProgress = computeDetailScrollProgress(
              context,
              120,
              collapseExtent: 240,
            );
            completeProgress = computeDetailScrollProgress(
              context,
              240,
              collapseExtent: 240,
            );
            return const SizedBox.shrink();
          },
        ),
      ),
    );

    expect(halfProgress, 0.5);
    expect(completeProgress, 1.0);
  });
}
