CaiWuXiTong/tests/Feature/Business/WarningPageTest.php
苏木 79e72382d6 feat: 新增售后退货退款预警子页 (#744)
feat: 新增售后退货退款预警子页 (#744)
Co-authored-by: 苏木 <594326199@qq.com>
Co-committed-by: 苏木 <594326199@qq.com>
2026-10-28 17:13:55 +08:00

119 lines
3.8 KiB
PHP

<?php
namespace Tests\Feature\Business;
use App\Models\Auth\Permission;
use App\Models\Auth\Role;
use App\Models\Auth\User;
use App\Utilities\BusinessNavigation;
use App\Utilities\SidebarPermissions;
use Tests\Feature\FeatureTestCase;
class WarningPageTest extends FeatureTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->user->attachPermission(
Permission::where('name', 'read-admin-panel')->firstOrFail()
);
}
public function test_warning_page_contains_after_sales_return_refund_child(): void
{
$warnings = collect(BusinessNavigation::all())
->firstWhere('slug', 'other')['pages'];
$warnings = collect($warnings)->firstWhere('slug', 'warnings');
$this->assertSame(
['warning-overview', 'after-sales-return-refund'],
array_column($warnings['children'], 'slug'),
);
$this->assertSame(
['预警总览', '售后退货退款'],
array_column($warnings['children'], 'title'),
);
}
public function test_warning_children_render_and_are_linked_from_the_sidebar(): void
{
$this->loginAs();
$overviewUrl = route('business.pages.show', [
'section' => 'other',
'page' => 'warning-overview',
]);
$afterSalesRefundUrl = route('business.pages.show', [
'section' => 'other',
'page' => 'after-sales-return-refund',
]);
$this->get(route('business.pages.show', [
'section' => 'other',
'page' => 'warnings',
]))
->assertRedirect($overviewUrl);
$this->get($overviewUrl)
->assertOk()
->assertSeeText('预警总览')
->assertSeeText('售后退货退款')
->assertSeeText('风险等级')
->assertSee($afterSalesRefundUrl, false);
$this->get($afterSalesRefundUrl)
->assertOk()
->assertSeeText('售后退货退款')
->assertSeeText('售后退货退款预警规则待接入')
->assertSeeText('退货、退款及售后差异')
->assertSeeText('接入后在这里查看售后退货退款预警');
}
public function test_existing_warning_page_permission_keeps_both_child_entries(): void
{
$regular = $this->regularAccount();
$subject = 'user_' . $regular->id;
setting()->set('system.sidebar_permissions', [
'configured' => [$subject],
'subjects' => [$subject => ['other/warnings']],
]);
$other = collect(SidebarPermissions::navigationFor($regular))
->firstWhere('slug', 'other');
$warnings = collect($other['pages'])->firstWhere('slug', 'warnings');
$this->assertSame(
['warning-overview', 'after-sales-return-refund'],
array_column($warnings['children'], 'slug'),
);
$this->loginAs($regular)
->get(route('business.pages.show', [
'section' => 'other',
'page' => 'after-sales-return-refund',
]))
->assertOk()
->assertSeeText('售后退货退款预警规则待接入');
}
private function regularAccount(): User
{
$name = 'fixture-warning-page-' . User::count();
$user = User::create([
'name' => $name,
'email' => $name . '@example.test',
'password' => 'fixture-unused-password',
'enabled' => true,
'locale' => 'zh-CN',
'landing_page' => 'dashboard',
]);
$user->roles()->attach(Role::where('name', 'user')->firstOrFail()->id);
$user->permissions()->attach(Permission::where('name', 'read-admin-panel')->firstOrFail()->id);
$user->companies()->attach($this->company->id);
return $user;
}
}