CaiWuXiTong/tests/Feature/Business/OrderProfitPageTest.php
renshen 3bd2587c04 feat: 新增订单利润页面与明细查询 (#786)
新增订单利润页面、共享镜像查询、筛选聚合、明细展示、列设置与导出。

验证:20 项测试通过,249 个断言;真实页面代表订单 26092142570188 验收通过。
2026-10-30 15:24:09 +08:00

132 lines
5.7 KiB
PHP

<?php
namespace Tests\Feature\Business;
use Mockery;
use Modules\EcommerceFinance\Repositories\OrderProfitRepository;
use Tests\Feature\FeatureTestCase;
class OrderProfitPageTest extends FeatureTestCase
{
public function test_order_profit_page_loads_recent_rows_without_filters(): void
{
$repository = Mockery::mock(OrderProfitRepository::class);
$repository->shouldReceive('status')->once()->andReturn([
'ready' => true,
'initial_completed_at' => '2026-10-01 00:00:00',
'last_succeeded_at' => '2026-10-30 10:00:00',
'last_error_code' => null,
]);
$repository->shouldReceive('shopNames')->once()->andReturn([]);
$repository->shouldReceive('paginate')->once()
->with(
Mockery::on(static fn (array $filters): bool => $filters['from'] === now()->subDays(6)->toDateString()
&& $filters['to'] === now()->toDateString()),
1,
25,
)
->andReturn([
'has_more' => false,
'rows' => [[
'shop_name' => '最近订单店铺',
'online_order_no' => 'RECENT-ORDER-1',
'internal_order_no' => '9001',
'cost_amount' => 12.0,
'refund_amount' => 0.0,
'platform_subsidy' => 0.0,
'product_quantity' => 1.0,
'product_amount' => 20.0,
'items' => [],
]],
]);
$this->app->instance(OrderProfitRepository::class, $repository);
$this->loginAs()->get(route('business.pages.show', [
'section' => 'order-profit',
'page' => 'order-profit-list',
]))
->assertOk()
->assertSeeText('RECENT-ORDER-1')
->assertSeeText('最近订单店铺')
->assertSeeText('12.00');
}
public function test_order_profit_page_renders_aggregated_order_and_source_details(): void
{
$repository = Mockery::mock(OrderProfitRepository::class);
$repository->shouldReceive('status')->once()->andReturn([
'ready' => true,
'initial_completed_at' => '2026-10-01 00:00:00',
'last_succeeded_at' => '2026-10-30 10:00:00',
'last_error_code' => null,
]);
$repository->shouldReceive('shopNames')->once()->andReturn(['唯品会MP-卓禾家具特卖旗舰店']);
$repository->shouldReceive('paginate')->once()->andReturn([
'has_more' => false,
'rows' => [[
'shop_name' => '唯品会MP-卓禾家具特卖旗舰店',
'online_order_no' => '26092142570188',
'internal_order_no' => '9470588',
'order_time' => '2026/9/21 9:40:36',
'cost_amount' => 75.0,
'refund_amount' => 20.0,
'platform_subsidy' => 0.0,
'product_quantity' => 1.0,
'product_amount' => 259.0,
'refund_type' => '仅退款',
'classification_order' => '否',
'source_row_count' => 2,
'matched_package_fee' => null,
'matched_freight_fee' => null,
'matched_bill_fee' => null,
'items' => [[
'after_sales_no' => '743208893',
'product_code' => 'BJ018706N68V01',
'style_code' => 'BJ0187',
'shop_product_code' => 'SKU-1E73E04C8008B3AF',
'product_name' => '款式一 60/40/53 胡桃色',
'color_spec' => '胡桃色',
'product_quantity' => 0,
'product_amount' => 0,
'product_cost' => 0,
'refund_type' => '仅退款',
'post_refund_amount' => 20,
'post_refund_cost' => 0,
'post_platform_subsidy' => 0,
'combine_type' => '非组合',
'shipping_warehouse' => '简尚-崔桥工厂仓',
'express_no' => '76001654919378',
'express_company' => '新北中通',
'order_tags' => '发货后售后,店铺-唯品',
]],
]],
]);
$this->app->instance(OrderProfitRepository::class, $repository);
$this->loginAs()->get(route('business.pages.show', [
'section' => 'order-profit',
'page' => 'order-profit-list',
'order_no' => '26092142570188',
]))
->assertOk()
->assertSeeText('订单利润')
->assertSeeText('唯品会MP-卓禾家具特卖旗舰店')
->assertSeeText('26092142570188')
->assertSeeText('9470588')
->assertSeeText('75.00')
->assertSeeText('20.00')
->assertSeeText('仅退款')
->assertSeeText('包材费、快递费、账单费用属于聚水潭页面自动匹配结果')
->assertSeeText('743208893')
->assertSeeTextInOrder(['内部单号', '明细', '订单时间'])
->assertSee('data-finance-fixed="true"', false)
->assertSee('data-order-profit-autofit-fixed', false)
->assertSee('data-order-profit-fixed-key="detail"', false)
->assertSee('style="left: 28rem; width: 4.75rem; min-width: 4.75rem; max-width: 4.75rem;"', false)
->assertSee('data-order-profit-detail', false)
->assertSee('data-finance-table-name="订单利润"', false)
->assertSee('is-column-hidden', false)
->assertSee('/workspace/order-profit', false);
}
}