user->attachPermission( Permission::where('name', 'read-admin-panel')->firstOrFail() ); } public function test_negative_alerts_is_a_payables_section_with_two_children(): void { $navigation = collect(BusinessNavigation::all())->keyBy('slug'); $alertSection = $navigation->get('negative-alerts'); $this->assertNotNull($alertSection); $this->assertSame('负数预警', $alertSection['title']); $this->assertSame( ['supplier-negative-alert', 'courier-negative-alert'], array_column($alertSection['pages'], 'slug'), ); $this->assertNotContains( 'supplier-negative-alert', array_column($navigation->get('supplier-reconciliation')['pages'], 'slug'), ); $grouped = ShowInAdmin::groupPayables(BusinessNavigation::all()); $payables = collect($grouped)->firstWhere('slug', 'payable-items'); $this->assertSame('negative-alerts', $payables['sections'][0]['slug']); } public function test_supplier_and_courier_negative_alert_pages_render_as_tabs(): void { $this->saveSupplierPayable('negative:1', '负余额供应商', '-128.50', '2026-09', [ 'company' => '测试供应商有限公司', 'negative_reason' => '历史多付款', ]); $this->saveSupplierPayable('positive:1', '正余额供应商', '88.00', '2026-09'); $this->loginAs() ->get(route('business.pages.show', [ 'section' => 'negative-alerts', 'page' => 'supplier-negative-alert', ])) ->assertOk() ->assertSeeText('供应商负数预警') ->assertSeeText('快递负数预警') ->assertSeeText('供应商余额小于 0 的终版数据') ->assertSeeText('负余额供应商') ->assertSeeText('-128.50') ->assertSeeText('历史多付款') ->assertDontSeeText('正余额供应商'); $this->loginAs() ->get(route('business.pages.show', [ 'section' => 'negative-alerts', 'page' => 'courier-negative-alert', ])) ->assertOk() ->assertSeeText('供应商负数预警') ->assertSeeText('快递负数预警') ->assertSeeText('快递负数判定口径待确认') ->assertSeeText('待接入'); } public function test_supplier_negative_alert_filters_by_month_and_supplier(): void { $this->saveSupplierPayable('negative:sep', '九月负余额供应商', '-99.00', '2026-09'); $this->saveSupplierPayable('negative:aug', '八月负余额供应商', '-66.00', '2026-08'); $this->loginAs() ->get(route('business.pages.show', [ 'section' => 'negative-alerts', 'page' => 'supplier-negative-alert', 'month' => '2026-08', 'supplier' => '八月负余额', ])) ->assertOk() ->assertSeeText('八月负余额供应商') ->assertSeeText('-66.00') ->assertDontSeeText('九月负余额供应商'); } public function test_supplier_negative_alert_route_no_longer_renders_under_supplier_reconciliation(): void { $this->withExceptionHandling() ->loginAs() ->get(route('business.pages.show', [ 'section' => 'supplier-reconciliation', 'page' => 'supplier-negative-alert', ])) ->assertRedirect(); } private function saveSupplierPayable( string $key, string $supplier, string $supplierBalance, string $month, array $extra = [], ): void { app(SupplierPayableOverrideStore::class)->save( PayablesFinalActions::DATASET_PREFIX . 'supplier:supplier-payables-report', $key, $extra + [ 'summary_month' => $month, 'supplier' => $supplier, 'supplier_balance' => $supplierBalance, ], (int) $this->company->id, (int) $this->user->id, ); } }