import 'package:flutter_test/flutter_test.dart';
import 'package:cashumit/services/esc_pos_print_service.dart';
import 'package:cashumit/models/receipt_item.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() {
  group('EscPosPrintService Unit Tests', () {
    setUp(() async {
      // Inisialisasi shared preferences untuk testing
      SharedPreferences.setMockInitialValues({});
    });

    test('StoreConfig fromSharedPreferences should return default values',
        () async {
      final storeConfig = await StoreConfig.fromSharedPreferences();

      expect(storeConfig.name, 'TOKO SEMBAKO MURAH');
      expect(storeConfig.address, 'Jl. Merdeka No. 123');
      expect(storeConfig.adminName, 'Budi Santoso');
      expect(storeConfig.adminPhone, '08123456789');
    });

    test('PaymentInfo should handle default values correctly', () {
      final paymentInfo = PaymentInfo();

      expect(paymentInfo.paymentAmount, 0.0);
      expect(paymentInfo.isTip, false);
    });

    test('PaymentInfo should handle custom values correctly', () {
      final paymentInfo = PaymentInfo(
        paymentAmount: 500.0,
        isTip: true,
      );

      expect(paymentInfo.paymentAmount, 500.0);
      expect(paymentInfo.isTip, true);
    });

    test('StoreConfig should handle custom values correctly', () async {
      SharedPreferences.setMockInitialValues({
        'store_name': 'TOKO BARU',
        'store_address': 'Jl. Sudirman No. 1',
        'admin_name': 'Admin Baru',
        'admin_phone': '081234567890',
        'store_disclaimer_text': 'Disclaimer baru',
        'thank_you_text': 'Terima kasih baru',
        'pantun_text': 'Pantun baru',
      });

      final storeConfig = await StoreConfig.fromSharedPreferences();

      expect(storeConfig.name, 'TOKO BARU');
      expect(storeConfig.address, 'Jl. Sudirman No. 1');
      expect(storeConfig.adminName, 'Admin Baru');
      expect(storeConfig.adminPhone, '081234567890');
      expect(storeConfig.disclaimer, 'Disclaimer baru');
      expect(storeConfig.thankYouText, 'Terima kasih baru');
      expect(storeConfig.pantunText, 'Pantun baru');
    });

    test('ReceiptItem total calculation should be correct', () {
      final item = ReceiptItem(
        description: 'Test Item',
        quantity: 3,
        price: 15000.0,
      );

      expect(item.total, 45000.0);
      expect(item.description, 'Test Item');
      expect(item.quantity, 3);
      expect(item.price, 15000.0);
    });

    test('PaymentInfo null handling should work', () {
      final paymentInfo = PaymentInfo(
        paymentAmount: 75000.0,
        isTip: false,
      );

      expect(paymentInfo.paymentAmount, 75000.0);
      expect(paymentInfo.isTip, false);
    });
  });
}
