'Full Administrator', 'guard_name' => 'admin']);
$admin = User::factory()->create();
$admin->assignRole('Full Administrator');
$quote = WebDesignQuote::create([
'quote_number' => 'BG-WEB-202610-0001',
'status' => 'draft',
'customer_name' => 'Nguyễn Văn A',
'website_name' => 'shop.vn',
'website_category' => 'Thương mại điện tử',
'platform' => 'wordpress_elementor',
'items' => [
['name' => 'Thiết kế UI', 'description' => '
', 'quantity' => 1, 'unit_price' => 8000000],
['name' => '=HYPERLINK("x")', 'description' => null, 'quantity' => 2, 'unit_price' => 1000000],
],
'subtotal' => 10000000,
'discount' => 500000,
'vat_percent' => 8,
'total' => 10260000,
'currency' => 'VND',
]);
$response = $this->actingAs($admin, 'admin')
->get("/api/v1/administrator/web-design-quotes/{$quote->id}/xlsx")
->assertOk();
$book = IOFactory::load($response->baseResponse->getFile()->getPathname());
$sheet = $book->getActiveSheet();
$cells = collect($sheet->toArray(null, true, false, true));
$this->assertSame(1, $book->getSheetCount());
$this->assertCount(1, $sheet->getDrawingCollection());
$this->assertSame('BÁO GIÁ THIẾT KẾ WEBSITE SHOP.VN', $sheet->getCell('A6')->getValue());
$itemRow = $cells->search(fn (array $row) => $row['B'] === 'Thiết kế UI');
$this->assertSame("- Trang chủ\n- Sản phẩm", $sheet->getCell("C{$itemRow}")->getValue());
$this->assertSame('=HYPERLINK("x")', $sheet->getCell('B' . ($itemRow + 1))->getCalculatedValue());
$totalRow = $cells->search(fn (array $row) => $row['A'] === 'Tổng giá trị báo giá');
$this->assertEquals($quote->total, $sheet->getCell("F{$totalRow}")->getCalculatedValue());
}
}