<?php

namespace Tests\Feature;

use App\Models\Plan;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class AdminPlanIndexPaidNoReceiptGovernanceLinkTest extends TestCase
{
    use RefreshDatabase;

    protected function loginAsPlatformAdmin(): void
    {
        $this->seed();

        $this->post('/admin/login', [
            'email' => 'platform.admin@demo.local',
            'password' => 'Platform@123456',
        ])->assertRedirect('/admin');
    }

    public function test_plan_index_should_render_paid_no_receipt_governance_link(): void
    {
        $this->loginAsPlatformAdmin();

        $plan = Plan::query()->create([
            'code' => 'plan_index_paid_no_receipt_link',
            'name' => '套餐页已付无回执治理入口测试套餐',
            'billing_cycle' => 'monthly',
            'price' => 99,
            'list_price' => 99,
            'status' => 'active',
            'sort' => 10,
            'published_at' => now(),
        ]);

        $res = $this->get('/admin/plans');
        $res->assertOk();

        $html = (string) $res->getContent();
        $this->assertStringContainsString('已付无回执', $html);

        $expectedBack = urlencode('/admin/plans');
        $this->assertStringContainsString('/admin/platform-orders?plan_id=' . $plan->id . '&payment_status=paid&receipt_status=none&back=' . $expectedBack, $html);
    }
}
