393 lines
15 KiB
PHP
393 lines
15 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Business;
|
|
|
|
use App\Models\Auth\Permission;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
class FinanceLedgerBankCategoryDialogTest extends FeatureTestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
Carbon::setTestNow('2026-10-18 12:00:00');
|
|
|
|
$this->user->attachPermission(
|
|
Permission::where('name', 'read-admin-panel')->firstOrFail(),
|
|
);
|
|
|
|
$connection = DB::connection('business_mirror');
|
|
$connection->table('fin_accounts')->insert([
|
|
[
|
|
'company_name' => '弹窗测试公司',
|
|
'account_short' => '弹窗招商招行',
|
|
'account_should_keep' => '是',
|
|
'current_balance' => 1100,
|
|
'daily_available' => 1100,
|
|
],
|
|
[
|
|
'company_name' => '弹窗测试公司',
|
|
'account_short' => '弹窗工商1工行',
|
|
'account_should_keep' => '否',
|
|
'current_balance' => 2200,
|
|
'daily_available' => 2200,
|
|
],
|
|
[
|
|
'company_name' => '弹窗测试公司',
|
|
'account_short' => '弹窗工商2工行',
|
|
'account_should_keep' => '是',
|
|
'current_balance' => 3300,
|
|
'daily_available' => 3300,
|
|
],
|
|
]);
|
|
$connection->table('fin_daily_flows')->insert([
|
|
[
|
|
'flow_date' => '2026-10-17',
|
|
'company_name' => '弹窗测试公司',
|
|
'account_short' => '弹窗招商招行',
|
|
'opening_balance' => 1100,
|
|
'inflow' => 0,
|
|
'outflow' => 0,
|
|
'closing_balance' => 1100,
|
|
],
|
|
[
|
|
'flow_date' => '2026-10-17',
|
|
'company_name' => '弹窗测试公司',
|
|
'account_short' => '弹窗工商1工行',
|
|
'opening_balance' => 2200,
|
|
'inflow' => 0,
|
|
'outflow' => 0,
|
|
'closing_balance' => 2200,
|
|
],
|
|
[
|
|
'flow_date' => '2026-10-17',
|
|
'company_name' => '弹窗测试公司',
|
|
'account_short' => '弹窗工商2工行',
|
|
'opening_balance' => 3300,
|
|
'inflow' => 0,
|
|
'outflow' => 0,
|
|
'closing_balance' => 3300,
|
|
],
|
|
]);
|
|
$connection->table('fin_flow_summary_account_sources')->insert([
|
|
[
|
|
'account_short' => '弹窗招商招行',
|
|
'data_source' => '银企直连',
|
|
'updated_by' => '测试',
|
|
],
|
|
[
|
|
'account_short' => '弹窗工商1工行',
|
|
'data_source' => '手动',
|
|
'updated_by' => '测试',
|
|
],
|
|
[
|
|
'account_short' => '弹窗工商2工行',
|
|
'data_source' => '银企直连',
|
|
'updated_by' => '测试',
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function test_account_count_opens_bank_category_dialog_with_counts_and_keep_status(): void
|
|
{
|
|
$response = $this->loginAs()->get($this->pageUrl([
|
|
'flows_from' => '2026-10-01',
|
|
'flows_to' => '2026-10-31',
|
|
]));
|
|
|
|
$response->assertOk()
|
|
->assertSee('data-ledger-bank-category-trigger', false)
|
|
->assertSee('银行分类数量')
|
|
->assertSee('table-layout:fixed', false)
|
|
->assertSee('text-align:center; white-space:nowrap', false)
|
|
->assertSee('border-right:1px solid #e8e3da', false)
|
|
->assertSee('<colgroup>', false)
|
|
->assertDontSee('data-ledger-bank-category-sort="balance"', false)
|
|
->assertDontSee('(leftValue - rightValue)', false)
|
|
->assertDontSee('data-bank-category-balance="', false)
|
|
->assertSeeInOrder([
|
|
'招商银行',
|
|
'1',
|
|
'0',
|
|
'1',
|
|
'1',
|
|
'0',
|
|
'工商银行',
|
|
'1',
|
|
'1',
|
|
'2',
|
|
'1',
|
|
'1',
|
|
]);
|
|
|
|
$html = $response->getContent();
|
|
$this->assertMatchesRegularExpression(
|
|
'/<table class="ledger-bank-category-table">.*?<thead>\s*<tr>(?:\s*<th scope="col">[^<]+<\/th>){6}\s*<\/tr>\s*<\/thead>/s',
|
|
$html,
|
|
);
|
|
}
|
|
|
|
public function test_bank_category_dialog_recognizes_extended_aliases_numeric_suffixes_and_override(): void
|
|
{
|
|
DB::connection('business_mirror')->table('fin_accounts')->insert([
|
|
[
|
|
'company_name' => '银行分类规则测试公司',
|
|
'account_short' => '广州一淘平安',
|
|
],
|
|
[
|
|
'company_name' => '银行分类规则测试公司',
|
|
'account_short' => '杭州环客',
|
|
],
|
|
[
|
|
'company_name' => '银行分类规则测试公司',
|
|
'account_short' => '艾之淘交行',
|
|
],
|
|
[
|
|
'company_name' => '银行分类规则测试公司',
|
|
'account_short' => '星惠光大',
|
|
],
|
|
[
|
|
'company_name' => '银行分类规则测试公司',
|
|
'account_short' => '欧伯娜中行0884',
|
|
],
|
|
[
|
|
'company_name' => '银行分类规则测试公司',
|
|
'account_short' => '胡亮超华夏2',
|
|
],
|
|
[
|
|
'company_name' => '银行分类规则测试公司',
|
|
'account_short' => '秋之丰家居支付宝2',
|
|
],
|
|
]);
|
|
|
|
$html = $this->loginAs()->get($this->pageUrl([
|
|
'flows_company' => '银行分类规则测试公司',
|
|
'flows_from' => '2026-10-01',
|
|
'flows_to' => '2026-10-31',
|
|
]))->assertOk()->getContent();
|
|
|
|
$this->assertSame(
|
|
1,
|
|
preg_match('/<table class="ledger-bank-category-table">(.*?)<\/table>/s', $html, $table),
|
|
);
|
|
$this->assertStringNotContainsString('<td>未填写</td>', $table[1]);
|
|
foreach ([
|
|
'平安银行' => 2,
|
|
'交通银行' => 1,
|
|
'光大银行' => 1,
|
|
'中国银行' => 1,
|
|
'华夏银行' => 1,
|
|
'支付宝' => 1,
|
|
] as $bank => $count) {
|
|
$this->assertMatchesRegularExpression(
|
|
'/<tr>\s*<td>' . preg_quote($bank, '/') . '<\/td>'
|
|
. '\s*<td>0<\/td>\s*<td>0<\/td>\s*<td>' . $count . '<\/td>'
|
|
. '\s*<td>0<\/td>\s*<td>0<\/td>\s*<\/tr>/',
|
|
$table[1],
|
|
);
|
|
}
|
|
}
|
|
|
|
public function test_fund_overview_opens_combined_period_and_current_balance_dialog(): void
|
|
{
|
|
$response = $this->loginAs()->get($this->pageUrl([
|
|
'flows_from' => '2026-10-01',
|
|
'flows_to' => '2026-10-31',
|
|
]));
|
|
|
|
$html = $response->assertOk()->getContent();
|
|
$checks = [
|
|
'trigger' => 'data-ledger-balance-distribution-trigger',
|
|
'dialog control' => 'aria-controls="ledger-balance-distribution-dialog"',
|
|
'dialog title' => '资金概览',
|
|
'period title' => '<h4>本期资金</h4>',
|
|
'current title' => '<h4>当前余额</h4>',
|
|
'chart title' => '余额条形图',
|
|
'detail title' => '银行分布明细',
|
|
'bank detail column' => '<th scope="col">所属银行</th>',
|
|
'total row label' => '<tfoot><tr><td>总金额</td>',
|
|
'icbc chart bar' => 'data-ledger-current-balance-chart-bar="工商银行"',
|
|
'cmb chart bar' => 'data-ledger-current-balance-chart-bar="招商银行"',
|
|
'trigger handler' => 'balanceDistributionTrigger?.addEventListener(\'click\', openBalanceDistributionDialog)',
|
|
];
|
|
foreach ($checks as $label => $needle) {
|
|
$this->assertTrue(str_contains($html, $needle), $label . ' is missing');
|
|
}
|
|
|
|
$this->assertTrue(
|
|
strpos($html, $checks['icbc chart bar']) < strpos($html, $checks['cmb chart bar']),
|
|
'chart bars are not ordered by balance descending',
|
|
);
|
|
$this->assertMatchesRegularExpression(
|
|
'/<table class="ledger-balance-detail-table">.*?<thead><tr>(?:<th scope="col">[^<]+<\/th>){4}<\/tr><\/thead>/s',
|
|
$html,
|
|
);
|
|
$this->assertDoesNotMatchRegularExpression(
|
|
'/<table class="ledger-balance-detail-table">.*?<th scope="col">账户数<\/th>/s',
|
|
$html,
|
|
);
|
|
}
|
|
|
|
public function test_summary_uses_compact_fund_overview_and_two_independent_progress_tabs(): void
|
|
{
|
|
$connection = DB::connection('business_mirror');
|
|
$connection->table('fin_accounts')->insert([
|
|
'company_name' => '弹窗测试公司',
|
|
'account_short' => '弹窗建设建行',
|
|
'account_should_keep' => '否',
|
|
'current_balance' => 4400.50,
|
|
'daily_available' => 4000,
|
|
'blocked_amount' => 400.50,
|
|
]);
|
|
$connection->table('fin_daily_flows')->insert([
|
|
'flow_date' => '2026-10-17',
|
|
'company_name' => '弹窗测试公司',
|
|
'account_short' => '弹窗建设建行',
|
|
'opening_balance' => 4400.50,
|
|
'inflow' => 0,
|
|
'outflow' => 0,
|
|
'closing_balance' => 4400.50,
|
|
]);
|
|
$connection->table('fin_account_keep_todos')->insert([
|
|
[
|
|
'account_short' => '弹窗工商1工行',
|
|
'current_progress' => 'completed',
|
|
'updated_by' => '测试',
|
|
],
|
|
[
|
|
'account_short' => '弹窗建设建行',
|
|
'current_progress' => 'in_progress',
|
|
'updated_by' => '测试',
|
|
],
|
|
]);
|
|
$connection->table('fin_account_statuses')->insert([
|
|
[
|
|
'account_short' => '弹窗工商1工行',
|
|
'status' => 'online_banking_abnormal',
|
|
'updated_by' => '测试',
|
|
],
|
|
[
|
|
'account_short' => '弹窗建设建行',
|
|
'status' => 'limited',
|
|
'updated_by' => '测试',
|
|
],
|
|
]);
|
|
$connection->table('fin_account_todos')->insert([
|
|
[
|
|
'account_short' => '弹窗工商1工行',
|
|
'completion_status' => 'in_progress',
|
|
'updated_by' => '测试',
|
|
],
|
|
[
|
|
'account_short' => '弹窗建设建行',
|
|
'completion_status' => 'completed',
|
|
'updated_by' => '测试',
|
|
],
|
|
]);
|
|
|
|
$html = $this->loginAs()->get($this->pageUrl([
|
|
'flows_company' => '弹窗测试公司',
|
|
'flows_from' => '2026-10-01',
|
|
'flows_to' => '2026-10-31',
|
|
]))->assertOk()->getContent();
|
|
|
|
foreach ([
|
|
'data-ledger-flow-overview',
|
|
'资金概览(万元)',
|
|
'当前余额',
|
|
'待办处理进度',
|
|
'data-ledger-progress-tab="unretained"',
|
|
'data-ledger-progress-tab="unavailable"',
|
|
'data-ledger-progress-panel="unretained"',
|
|
'data-ledger-progress-panel="unavailable"',
|
|
"activateProgressTab(tab.dataset.ledgerProgressTab)",
|
|
'data-ledger-current-total="11000.5"',
|
|
'data-ledger-current-available="10600"',
|
|
'data-ledger-current-blocked="400.5"',
|
|
'data-ledger-unavailable-progress',
|
|
'data-unavailable-total="2"',
|
|
'data-unavailable-completed="1"',
|
|
'data-unavailable-in-progress="1"',
|
|
'data-unavailable-incomplete="0"',
|
|
'data-unavailable-not-started="0"',
|
|
'已跟进 2 / 2',
|
|
'不保留账户',
|
|
'data-unretained-total="2"',
|
|
'data-unretained-completed="1"',
|
|
'data-unretained-in-progress="1"',
|
|
'data-unretained-not-started="0"',
|
|
'已完成 1 / 2',
|
|
'进行中 <b>1</b>',
|
|
'待开始 <b>0</b>',
|
|
'可用 <b>1.06</b>',
|
|
'不可用 <b>0.04</b>',
|
|
'data-ledger-current-balance-chart-bar="工商银行"',
|
|
'data-ledger-current-balance-chart-bar="建设银行"',
|
|
] as $needle) {
|
|
$this->assertStringContainsString($needle, $html);
|
|
}
|
|
$this->assertStringNotContainsString('待处理明细', $html);
|
|
}
|
|
|
|
public function test_bank_view_uses_data_source_and_summary_adds_keep_column(): void
|
|
{
|
|
$this->loginAs()->get($this->pageUrl([
|
|
'flows_view' => 'bank',
|
|
'flows_from' => '2026-10-01',
|
|
'flows_to' => '2026-10-31',
|
|
]))
|
|
->assertOk()
|
|
->assertSee('是否保留')
|
|
->assertSee('数据来源')
|
|
->assertDontSee('是否银企直连')
|
|
->assertSee('<option value="银企直连"', false);
|
|
|
|
$this->loginAs()->get($this->pageUrl([
|
|
'flows_view' => 'summary',
|
|
'flows_from' => '2026-10-01',
|
|
'flows_to' => '2026-10-31',
|
|
]))
|
|
->assertOk()
|
|
->assertSee('是否保留')
|
|
->assertSee('数据来源')
|
|
->assertSee('<option value="手动"', false)
|
|
->assertSee('<option value="银企直连"', false);
|
|
}
|
|
|
|
public function test_flow_summary_source_rejects_other_values(): void
|
|
{
|
|
$this->expectException(ValidationException::class);
|
|
|
|
$this->loginAs()->postJson(route('business.financial-ledger.flows.summary.source.update'), [
|
|
'account_short' => '弹窗工商1工行',
|
|
'value' => '其他来源',
|
|
]);
|
|
}
|
|
|
|
public function test_flow_summary_source_accepts_direct_connection(): void
|
|
{
|
|
$this->loginAs()->postJson(route('business.financial-ledger.flows.summary.source.update'), [
|
|
'account_short' => '弹窗工商1工行',
|
|
'value' => '银企直连',
|
|
])->assertOk()
|
|
->assertJsonPath('value.data_source', '银企直连');
|
|
|
|
$this->assertDatabaseHas('fin_flow_summary_account_sources', [
|
|
'account_short' => '弹窗工商1工行',
|
|
'data_source' => '银企直连',
|
|
], 'business_mirror');
|
|
}
|
|
|
|
private function pageUrl(array $parameters = []): string
|
|
{
|
|
return route('business.pages.show', array_merge([
|
|
'company_id' => $this->company->id,
|
|
'section' => 'financial-operations',
|
|
'page' => 'ledger',
|
|
], $parameters));
|
|
}
|
|
}
|