import 'package:flutter_test/flutter_test.dart';

import 'package:chanora_flutter/services/android_audio_output_devices.dart';

void main() {
  test('parses Android audio output devices and skips non-maps', () {
    final devices = parseAndroidAudioOutputDevices([
      {
        'id': 12,
        'name': 'Speaker',
        'type': 'speaker',
        'isSelected': true,
        'isAvailableForCommunication': true,
      },
      'bad',
      {'id': null, 'name': null},
    ]);

    expect(devices, hasLength(2));
    expect(devices.first.id, '12');
    expect(devices.first.name, 'Speaker');
    expect(devices.first.type, 'speaker');
    expect(devices.first.isSelected, isTrue);
    expect(devices.first.isAvailableForCommunication, isTrue);
    expect(devices.last.id, isEmpty);
    expect(devices.last.name, isEmpty);
    expect(devices.last.type, 'unknown');
  });

  test('finds selected Android audio output device', () {
    final selected = selectedAndroidAudioOutputDevice([
      const AndroidAudioOutputDevice(
        id: '1',
        name: 'Speaker',
        type: 'speaker',
        isSelected: false,
        isAvailableForCommunication: true,
      ),
      const AndroidAudioOutputDevice(
        id: '2',
        name: 'Headset',
        type: 'wiredHeadset',
        isSelected: true,
        isAvailableForCommunication: true,
      ),
    ]);

    expect(selected?.id, '2');
    expect(selectedAndroidAudioOutputDevice(const []), isNull);
  });
}
