import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:chanora_flutter/widgets/talk_power_warning.dart';

void main() {
  test('talk power policy only blocks insufficient ungranted clients', () {
    expect(
      isTalkPowerBlocked(
        talkPower: 5,
        neededTalkPower: 10,
        talkPowerGranted: false,
      ),
      isTrue,
    );
    expect(
      isTalkPowerBlocked(
        talkPower: 10,
        neededTalkPower: 10,
        talkPowerGranted: false,
      ),
      isFalse,
    );
    expect(
      isTalkPowerBlocked(
        talkPower: 5,
        neededTalkPower: 10,
        talkPowerGranted: true,
      ),
      isFalse,
    );
    expect(
      isTalkPowerBlocked(
        talkPower: null,
        neededTalkPower: 10,
        talkPowerGranted: false,
      ),
      isFalse,
    );
  });

  testWidgets('talk power warning hides when not blocked', (tester) async {
    await tester.pumpWidget(
      const MaterialApp(
        home: TalkPowerWarning(
          talkPower: 10,
          neededTalkPower: 10,
          talkPowerGranted: false,
        ),
      ),
    );

    expect(find.textContaining('Insufficient talk power'), findsNothing);
    expect(find.byType(SizedBox), findsOneWidget);
  });

  testWidgets('talk power warning renders blocked values', (tester) async {
    await tester.pumpWidget(
      const MaterialApp(
        home: Scaffold(
          body: TalkPowerWarning(
            talkPower: 5,
            neededTalkPower: 10,
            talkPowerGranted: false,
          ),
        ),
      ),
    );

    expect(find.text('Insufficient talk power (5 < 10)'), findsOneWidget);
    expect(find.byIcon(Icons.warning_amber), findsOneWidget);
  });
}
