CaiWuXiTong/tests/Feature/Business/ManagementExpensesPageTest.php
yueyang 094be29e4f fix: 管理费用按打款月份筛选并补充映射 (#814)
按打款时间筛选,并补充两个货代与种菜科目映射。
2026-11-02 13:10:47 +08:00

130 lines
6.1 KiB
PHP

<?php
namespace Tests\Feature\Business;
use App\Models\Auth\Permission;
use Illuminate\Pagination\LengthAwarePaginator;
use Mockery;
use Modules\EcommerceFinance\View\ManagementExpensesPageData;
use Tests\Feature\FeatureTestCase;
class ManagementExpensesPageTest extends FeatureTestCase
{
public function test_page_renders_second_level_summary_and_detail_template(): void
{
$this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail());
$service = Mockery::mock(ManagementExpensesPageData::class);
$service->shouldReceive('page')->once()->andReturn([
'view' => 'business.pages.financial-operations.management-expenses',
'pageTitle' => '管理费用',
'rows' => new LengthAwarePaginator([
[
'business_id' => '202610301323000477793',
'originator_department' => '财务中心',
'purpose' => '测试用途',
'expense_category' => '管理费用',
'second_level' => '办公费',
'third_level' => '办公费用品',
'amount' => 100.0,
'fee_ratio' => '不进费比',
'allocation' => '分摊',
],
], 1, 50, 1),
'filters' => [
'paid_month' => '2026-10', 'expense_category' => '',
'second_level' => '', 'third_level' => '', 'fee_ratio' => '',
'allocation' => '', 'business_id' => '', 'originator_department' => '',
'originator_name' => '', 'keyword' => '',
],
'summary' => [
'amount_total' => 100.0, 'in_fee_ratio_amount' => 0.0,
'non_fee_ratio_amount' => 100.0, 'unmapped_amount' => 0.0,
'row_count' => 1, 'approval_count' => 1,
],
'secondLevelSummary' => [[
'expense_category' => '管理费用', 'second_level' => '办公费',
'in_fee_ratio_amount' => 0.0, 'non_fee_ratio_amount' => 100.0,
'unmapped_amount' => 0.0, 'amount_total' => 100.0,
'row_count' => 1, 'approval_count' => 1,
]],
'thirdLevelSummary' => [[
'expense_category' => '管理费用', 'second_level' => '办公费',
'third_level' => '办公费用品', 'in_fee_ratio_amount' => 0.0,
'non_fee_ratio_amount' => 100.0, 'unmapped_amount' => 0.0,
'amount_total' => 100.0, 'row_count' => 1, 'approval_count' => 1,
]],
'options' => [
'categories' => ['管理费用'], 'second_levels' => ['办公费'],
'third_levels' => ['办公费用品'], 'allocations' => ['分摊'],
'fee_ratios' => ManagementExpensesPageData::FEE_RATIO_OPTIONS,
],
'monthOptions' => ['2026-11' => '2026年11月', '2026-10' => '2026年10月'],
'perPageOptions' => ManagementExpensesPageData::PER_PAGE_OPTIONS,
'detailColumns' => ManagementExpensesPageData::DETAIL_COLUMNS,
'detailsUrl' => route(
'business.financial-operations.management-expenses.details',
['company_id' => company_id() ?: 1],
),
'error' => null,
]);
$this->app->instance(ManagementExpensesPageData::class, $service);
$this->loginAs()->get(route('business.pages.show', [
'section' => 'financial-operations',
'page' => 'management-expenses',
]))->assertOk()
->assertSee('管理费用')
->assertSee('二级汇总')
->assertSee('OA 已打款审批明细模板')
->assertSee('不涉及付款或出纳未打款的审批不计入汇总')
->assertSee('打款月份')
->assertSee('name="paid_month"', false)
->assertSee('2026年10月')
->assertSee('进费比')
->assertSee('不进费比')
->assertSee('是否分摊')
->assertSee('办公费用品')
->assertSee('202610301323000477793')
->assertSee('data-me-open-group', false)
->assertSee('detailsLoadedKey', false)
->assertSee('dialogBody.scrollTop = 0', false)
->assertDontSee('OA 已付款明细模板')
->assertDontSee('审批单 / 明细行')
->assertDontSee('<th class="num">审批单</th>', false)
->assertDontSee('<th class="num">明细行</th>', false);
}
public function test_details_endpoint_returns_template_rows(): void
{
$this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail());
$service = Mockery::mock(ManagementExpensesPageData::class);
$service->shouldReceive('details')->once()->andReturn([
'rows' => [[
'business_id' => '202610301323000477793',
'originator_department' => '财务中心',
'purpose' => '测试用途',
'expense_category' => '管理费用',
'second_level' => '办公费',
'third_level' => '办公费用品',
'amount' => 100.0,
'fee_ratio' => '不进费比',
'allocation' => '分摊',
]],
'pagination' => ['current_page' => 1, 'last_page' => 1, 'per_page' => 50, 'total' => 1],
'summary' => [
'amount_total' => 100.0, 'in_fee_ratio_amount' => 0.0,
'non_fee_ratio_amount' => 100.0, 'unmapped_amount' => 0.0,
'row_count' => 1, 'approval_count' => 1,
],
]);
$this->app->instance(ManagementExpensesPageData::class, $service);
$this->loginAs()->getJson(route('business.financial-operations.management-expenses.details'))
->assertOk()
->assertJsonPath('success', true)
->assertJsonPath('rows.0.business_id', '202610301323000477793')
->assertJsonPath('rows.0.fee_ratio', '不进费比')
->assertJsonPath('pagination.total', 1);
}
}