From 3408b13e44754d6f9d24fab2adb0ee026338b816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 17 Mar 2026 06:39:06 +0800 Subject: [PATCH] =?UTF-8?q?ui(site-subscriptions):=20ends=5Fat=20=E5=BF=AB?= =?UTF-8?q?=E6=8D=B7=E5=8C=BA=E9=97=B4=E9=93=BE=E6=8E=A5=E4=BF=9D=E7=95=99?= =?UTF-8?q?=E7=AD=9B=E9=80=89=E4=B8=8A=E4=B8=8B=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/site_subscriptions/index.blade.php | 10 ++-- ...AtRangeQuickLinksShouldKeepContextTest.php | 59 +++++++++++++++++++ 2 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 tests/Feature/AdminSiteSubscriptionIndexEndsAtRangeQuickLinksShouldKeepContextTest.php diff --git a/resources/views/admin/site_subscriptions/index.blade.php b/resources/views/admin/site_subscriptions/index.blade.php index c51bdbf..5378fde 100644 --- a/resources/views/admin/site_subscriptions/index.blade.php +++ b/resources/views/admin/site_subscriptions/index.blade.php @@ -279,10 +279,12 @@ $endsToday = now()->format('Y-m-d'); $ends7d = now()->addDays(7)->format('Y-m-d'); $ends30d = now()->addDays(30)->format('Y-m-d'); - $endsQuickTodayUrl = $buildQuickFilterUrl(['ends_from' => $endsToday, 'ends_to' => $endsToday, 'page' => null]); - $endsQuick7dUrl = $buildQuickFilterUrl(['ends_from' => $endsToday, 'ends_to' => $ends7d, 'page' => null]); - $endsQuick30dUrl = $buildQuickFilterUrl(['ends_from' => $endsToday, 'ends_to' => $ends30d, 'page' => null]); - $endsQuickClearUrl = $buildQuickFilterUrl(['ends_from' => null, 'ends_to' => null, 'page' => null]); + + // 到期区间快捷入口:应保留当前筛选上下文(status/expiry/merchant/plan/keyword/back),仅覆盖 ends_from/ends_to,并清空 page。 + $endsQuickTodayUrl = $safeFullUrlWithQuery(['ends_from' => $endsToday, 'ends_to' => $endsToday, 'page' => null]); + $endsQuick7dUrl = $safeFullUrlWithQuery(['ends_from' => $endsToday, 'ends_to' => $ends7d, 'page' => null]); + $endsQuick30dUrl = $safeFullUrlWithQuery(['ends_from' => $endsToday, 'ends_to' => $ends30d, 'page' => null]); + $endsQuickClearUrl = $safeFullUrlWithQuery(['ends_from' => null, 'ends_to' => null, 'page' => null]); @endphp 今天到期 diff --git a/tests/Feature/AdminSiteSubscriptionIndexEndsAtRangeQuickLinksShouldKeepContextTest.php b/tests/Feature/AdminSiteSubscriptionIndexEndsAtRangeQuickLinksShouldKeepContextTest.php new file mode 100644 index 0000000..08249c4 --- /dev/null +++ b/tests/Feature/AdminSiteSubscriptionIndexEndsAtRangeQuickLinksShouldKeepContextTest.php @@ -0,0 +1,59 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_ends_at_range_quick_links_should_keep_context_and_safe_back(): void + { + $this->loginAsPlatformAdmin(); + + $res = $this->get('/admin/site-subscriptions?merchant_id=2&plan_id=3&keyword=abc&status=pending&expiry=expired&back=%2Fadmin%2Fplatform-orders'); + $res->assertOk(); + + $html = (string) $res->getContent(); + + // 抓取“近7天到期”链接 + preg_match_all('/href="([^"]+)"/', $html, $m); + $hrefs = $m[1] ?? []; + + $links = array_values(array_filter($hrefs, fn ($u) => str_contains($u, '近7天到期') === false)); + // 上面这行没意义(文案不在 href),我们直接按 ends_from/ends_to+merchant_id 来筛 + $rangeLinks = array_values(array_filter($hrefs, fn ($u) => str_contains($u, '/admin/site-subscriptions') && str_contains($u, 'ends_from=') && str_contains($u, 'ends_to=') && str_contains($u, 'merchant_id=2') && str_contains($u, 'plan_id=3'))); + $this->assertGreaterThanOrEqual(1, count($rangeLinks)); + + $parts = parse_url($rangeLinks[0]); + parse_str($parts['query'] ?? '', $q); + + $this->assertSame('2', (string) ($q['merchant_id'] ?? '')); + $this->assertSame('3', (string) ($q['plan_id'] ?? '')); + $this->assertSame('abc', (string) ($q['keyword'] ?? '')); + $this->assertSame('pending', (string) ($q['status'] ?? '')); + $this->assertSame('expired', (string) ($q['expiry'] ?? '')); + $this->assertSame('/admin/platform-orders', (string) ($q['back'] ?? '')); + + // 应清空分页,避免停留在旧页码导致空结果错觉 + $this->assertArrayNotHasKey('page', $q); + + // ends_from/ends_to 必须存在(具体日期值不在本测试锁死) + $this->assertArrayHasKey('ends_from', $q); + $this->assertArrayHasKey('ends_to', $q); + $this->assertNotSame('', (string) ($q['ends_from'] ?? '')); + $this->assertNotSame('', (string) ($q['ends_to'] ?? '')); + } +}