<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class AdminDashboardMerchantRevenueRank7dLinkShouldIncludeDateRangeTest 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_dashboard_merchant_revenue_rank_7d_link_should_include_date_range(): void
    {
        $this->loginAsPlatformAdmin();

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

        $from = now()->subDays(6)->format('Y-m-d');
        $to = now()->format('Y-m-d');

        // 排行卡的站点链接应带上近7天日期范围 + back
        $res->assertSee('data-role="merchant-revenue-rank-7d"', false);
        $res->assertSee('created_from=' . $from, false);
        $res->assertSee('created_to=' . $to, false);
        $res->assertSee('back=%2Fadmin', false);
        $res->assertDontSee('&amp;back=', false);
    }
}
