<?php

use App\Enums\VoucherType;
use App\Livewire\Member\Voucher;
use App\Models\Voucher as VoucherModel;
use Livewire\Livewire;

beforeEach(function () {
    $this->setupUser();
});

it('renders the voucher page', function () {
    $this->actingAs($this->user);

    Livewire::test(Voucher::class)
        ->assertStatus(200)
        ->assertSee('Voucher');
});

it('shows vouchers owned by the user', function () {
    $this->actingAs($this->user);

    $voucher = VoucherModel::factory()->create([
        'name' => 'Diskon Awal Tahun',
        'code' => 'NEWYEAR2024',
        'type' => VoucherType::FIXED,
        'discount_amount' => 10000,
    ]);

    $this->user->vouchers()->attach($voucher->id);

    Livewire::test(Voucher::class)
        ->assertSee('Diskon Awal Tahun')
        ->assertSee('NEWYEAR2024')
        ->assertSee('10.000');
});
