chore(admin-dashboard): failed same-reason links use config max len

This commit is contained in:
萝卜
2026-03-16 17:15:53 +08:00
parent cef5783612
commit ce7f957d70
3 changed files with 91 additions and 4 deletions

View File

@@ -346,7 +346,8 @@
: '-';
// 运营提效:失败原因较短时,提供“一键进入同原因集合”链接(避免复制粘贴)。
$FAILED_REASON_KEYWORD_MAX_LEN = 80;
// 与平台订单列表页的阈值保持一致(避免仪表盘能点、列表页却不支持/反之)。
$FAILED_REASON_KEYWORD_MAX_LEN = (int) config('saasshop.platform_orders.sync_error_keyword_link_max_len', 200);
$syncReasonUrl = '';
if ($syncErrMsg !== '' && mb_strlen($syncErrMsg) <= $FAILED_REASON_KEYWORD_MAX_LEN) {
$syncReasonUrl = \App\Support\BackUrl::withBack('/admin/platform-orders?' . \Illuminate\Support\Arr::query([

View File

@@ -0,0 +1,79 @@
<?php
namespace Tests\Feature;
use App\Models\Admin;
use App\Models\Merchant;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminDashboardRecentPlatformOrdersFailedHintsSameReasonLinkShouldUseConfigMaxLenTest 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_failed_hints_same_reason_link_should_use_config_max_len(): void
{
config()->set('saasshop.platform_orders.sync_error_keyword_link_max_len', 5);
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$platformAdminId = (int) Admin::query()->where('email', 'platform.admin@demo.local')->value('id');
// len=5应生成“同原因集合”链接
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => null,
'site_subscription_id' => null,
'created_by_admin_id' => $platformAdminId ?: null,
'order_no' => 'PO_DASH_SYNC_REASON_LEN5',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'paid',
'payable_amount' => 10,
'paid_amount' => 10,
'placed_at' => now(),
'meta' => [
'subscription_activation_error' => ['message' => '12345'],
],
]);
// len=6应显示“原因过长”不生成“同原因集合”链接
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => null,
'site_subscription_id' => null,
'created_by_admin_id' => $platformAdminId ?: null,
'order_no' => 'PO_DASH_SYNC_REASON_LEN6',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'paid',
'payable_amount' => 10,
'paid_amount' => 10,
'placed_at' => now(),
'meta' => [
'subscription_activation_error' => ['message' => '123456'],
],
]);
$res = $this->get('/admin');
$res->assertOk();
$res->assertSee('PO_DASH_SYNC_REASON_LEN5');
$res->assertSee('同原因集合', false);
$res->assertSee('PO_DASH_SYNC_REASON_LEN6');
$res->assertSee('原因过长', false);
}
}

View File

@@ -41,7 +41,8 @@ class AdminDashboardRecentPlatformOrdersFailedHintsShouldShowReasonTooLongHintWh
'published_at' => now(),
]);
$longReason = str_repeat('A', 120);
// 使用超出 config 阈值的长度(默认 200确保命中“原因过长”分支。
$longReason = str_repeat('A', 220);
PlatformOrder::query()->create([
'merchant_id' => $merchantId,
@@ -85,7 +86,13 @@ class AdminDashboardRecentPlatformOrdersFailedHintsShouldShowReasonTooLongHintWh
// 原因过长时不生成同原因集合链接,但应提示“原因过长”避免运营以为缺入口。
$res->assertSee('原因过长', false);
// 不应出现同原因集合链接
$res->assertDontSee('同原因集合', false);
// 不应出现同原因集合链接(限定在失败提示块 scope 内,避免页面其它区域出现同名文案造成误判)
// 说明:页面上其他位置可能也会出现“同原因集合”,因此这里锁定到 recent-order-sync-failed-hint 这段。
$content = (string) $res->getContent();
$startPos = strpos($content, 'data-role="recent-order-sync-failed-hint"');
$this->assertNotFalse($startPos);
$snippet = substr($content, $startPos, 800);
$this->assertStringContainsString('原因过长', $snippet);
$this->assertStringNotContainsString('同原因集合', $snippet);
}
}