import 'package:flutter_test/flutter_test.dart';
import 'package:recording_tool/features/recording/utils/recording_display_name.dart';

void main() {
  group('sanitizeRecordingBaseName', () {
    test('removes invalid path characters', () {
      expect(
        sanitizeRecordingBaseName(r'a/b:c*d?e"f<g>h|i'),
        'a_b_c_d_e_f_g_h_i',
      );
    });

    test('returns null for blank input', () {
      expect(sanitizeRecordingBaseName('   '), isNull);
    });

    test('truncates overly long names', () {
      final long = 'a' * 200;
      expect(sanitizeRecordingBaseName(long)!.length, 120);
    });
  });

  group('resolveRecordingDisplayName', () {
    test('uses sanitized clipboard filename when present', () {
      expect(
        resolveRecordingDisplayName('选手名称_选手ID_赛事名称_赛项'),
        '选手名称_选手ID_赛事名称_赛项',
      );
    });

    test('falls back to REC_ prefix when clipboard filename is empty', () {
      expect(resolveRecordingDisplayName(null), startsWith('REC_'));
      expect(resolveRecordingDisplayName(''), startsWith('REC_'));
    });
  });

  group('withVideoExtension', () {
    test('appends mp4 on Android', () {
      expect(
        withVideoExtension('match', isIOS: false),
        'match.mp4',
      );
    });

    test('appends mov on iOS', () {
      expect(
        withVideoExtension('match', isIOS: true),
        'match.mov',
      );
    });

    test('keeps existing extension', () {
      expect(withVideoExtension('a.mp4', isIOS: false), 'a.mp4');
      expect(withVideoExtension('a.MOV', isIOS: true), 'a.MOV');
    });
  });

  group('recordingFileNameForPlatform', () {
    test('combines clipboard name with platform extension', () {
      expect(
        recordingFileNameForPlatform(
          '选手名称_选手ID_赛事名称_赛项',
          isIOS: false,
        ),
        '选手名称_选手ID_赛事名称_赛项.mp4',
      );
    });
  });
}
