<?php

namespace Tests\Feature;

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

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

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

        // 套餐占比表格里，点击套餐名应跳到平台订单列表并带 back 回到仪表盘
        // 并且应携带同口径的近7天范围（与排行卡一致），避免用户从“近7天占比”跳过去却看到全量。
        $res->assertSee('href="/admin/platform-orders?plan_id=1&created_from=', false);
        $res->assertSee('&created_to=', false);
        $res->assertSee('&back=%2Fadmin"', false);

        // 不应出现 &amp;back=，避免回跳断链
        $res->assertDontSee('&amp;back=', false);
    }
}
