187 lines
6.4 KiB
PHP
187 lines
6.4 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_period_balances_and_keep_counts(): 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)
|
|
->assertSee('data-ledger-bank-category-sort="balance"', false)
|
|
->assertSee('(leftValue - rightValue)', false)
|
|
->assertSee('data-bank-category-balance="', false)
|
|
->assertSeeInOrder([
|
|
'招商银行',
|
|
'1',
|
|
'0',
|
|
'1',
|
|
'0.11',
|
|
'1',
|
|
'0',
|
|
'工商银行',
|
|
'1',
|
|
'1',
|
|
'2',
|
|
'0.55',
|
|
'1',
|
|
'1',
|
|
]);
|
|
}
|
|
|
|
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));
|
|
}
|
|
}
|