From 7f1f5a688743e46be350b36bcf0e897f22528fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 17 Mar 2026 17:43:58 +0800 Subject: [PATCH] =?UTF-8?q?refactor(js):=20=E5=A4=8D=E5=88=B6=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5toast=E6=96=87=E6=A1=88=E6=94=B6=E6=95=9B=E4=B8=BAtoas?= =?UTF-8?q?tCopyFailed=E5=B9=B6=E6=9B=B4=E6=96=B0=E6=8A=A4=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/admin.js | 17 +++++++++++++-- ...pyFailuresShouldUseToastErrorFirstTest.php | 6 +++++- ...JsToastCopyFailedHelperShouldExistTest.php | 21 +++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 tests/Feature/AdminJsToastCopyFailedHelperShouldExistTest.php diff --git a/public/js/admin.js b/public/js/admin.js index 9ccaa19..89fec19 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -608,6 +608,19 @@ return toastSuccess(msg); } + function toastCopyFailed(label, detail) { + var l = String(label || '').trim(); + var d = String(detail || '').trim(); + var msg = '复制失败'; + if (l) { + msg += '(' + l + ')'; + } + if (d) { + msg += ':' + d; + } + return toastError(msg); + } + // 通用:按钮短暂反馈(已复制/复制失败)并自动恢复 // 说明:用于复制 run_id / 复制治理链接,避免两套口径漂移。 function tempButtonFeedback(btn, ok, origAttr) { @@ -655,7 +668,7 @@ toastCopied('run_id', runId); }).catch(function(){ markCopiedRunId(false); - if (toastError('复制失败,请手动复制 run_id:' + runId)) { + if (toastCopyFailed('run_id', '请手动复制:' + runId)) { return; } try { window.alert('复制失败,请手动复制 run_id:' + runId); } catch (e) {} @@ -696,7 +709,7 @@ toastCopied(label + '链接', ''); }).catch(function(){ markCopied(btn, false); - if (toastError('复制失败,请手动复制' + label + '链接')) { + if (toastCopyFailed(label + '链接', '请手动复制')) { return; } try { window.alert('复制失败,请手动复制' + label + '链接'); } catch (e) {} diff --git a/tests/Feature/AdminJsCopyFailuresShouldUseToastErrorFirstTest.php b/tests/Feature/AdminJsCopyFailuresShouldUseToastErrorFirstTest.php index 6a13389..7bd1a91 100644 --- a/tests/Feature/AdminJsCopyFailuresShouldUseToastErrorFirstTest.php +++ b/tests/Feature/AdminJsCopyFailuresShouldUseToastErrorFirstTest.php @@ -15,6 +15,10 @@ class AdminJsCopyFailuresShouldUseToastErrorFirstTest extends TestCase $this->assertIsString($js); // 复制失败时应优先 toastError(alert 作为降级) - $this->assertStringContainsString("toastError('复制失败", $js); + // 允许通过 wrapper(toastCopyFailed)间接调用 toastError。 + $this->assertTrue( + str_contains($js, "toastError('复制失败") || str_contains($js, 'toastCopyFailed('), + 'copy failures should use toastError (directly or via toastCopyFailed wrapper)' + ); } } diff --git a/tests/Feature/AdminJsToastCopyFailedHelperShouldExistTest.php b/tests/Feature/AdminJsToastCopyFailedHelperShouldExistTest.php new file mode 100644 index 0000000..fcd8a87 --- /dev/null +++ b/tests/Feature/AdminJsToastCopyFailedHelperShouldExistTest.php @@ -0,0 +1,21 @@ +assertIsString($js); + + $this->assertStringContainsString('function toastCopyFailed', $js); + $this->assertStringContainsString("msg = '复制失败'", $js); + $this->assertStringContainsString("return toastError(msg)", $js); + } +}