67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package quote_test
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"chat-agent-system/internal/quote"
|
|
"github.com/xuri/excelize/v2"
|
|
)
|
|
|
|
func TestCDOQuoteGeneration(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
outXlsx := filepath.Join(tmpDir, "CDO报价核算-V01.xlsx")
|
|
|
|
in := quote.Input{
|
|
CustomerName: "水木测试医疗",
|
|
ProductName: "腹腔微创手术导航系统",
|
|
Author: "商务小队测试",
|
|
Hours: map[string]float64{
|
|
"结构工程师": 320,
|
|
"硬件工程师": 320,
|
|
"软件工程师": 480,
|
|
"项目经理": 160,
|
|
},
|
|
}
|
|
|
|
summary, err := quote.CalculateAndFill(in, "templates/xlsx/cdo_quote.xlsx", outXlsx)
|
|
if err != nil {
|
|
t.Fatalf("quote calculation failed: %v", err)
|
|
}
|
|
|
|
if _, err := os.Stat(outXlsx); err != nil {
|
|
t.Fatalf("expected output xlsx to exist: %v", err)
|
|
}
|
|
|
|
if summary.TotalPrice <= 0 {
|
|
t.Errorf("expected positive total price, got %f", summary.TotalPrice)
|
|
}
|
|
if len(summary.Notes) != 7 {
|
|
t.Errorf("expected 7 statutory notes, got %d", len(summary.Notes))
|
|
}
|
|
|
|
xf, err := excelize.OpenFile(outXlsx)
|
|
if err != nil {
|
|
t.Fatalf("failed to reopen output xlsx: %v", err)
|
|
}
|
|
defer xf.Close()
|
|
|
|
sheet := "报价模型"
|
|
assertCell := func(cell, want string) {
|
|
got, err := xf.GetCellValue(sheet, cell)
|
|
if err != nil {
|
|
t.Fatalf("failed to read cell %s: %v", cell, err)
|
|
}
|
|
if got != want {
|
|
t.Errorf("cell %s: expected %q, got %q", cell, want, got)
|
|
}
|
|
}
|
|
|
|
assertCell("A7", "报价代码")
|
|
assertCell("A8", "ID2")
|
|
assertCell("B8", "产品规划")
|
|
assertCell("A18", "总计")
|
|
assertCell("B18", "全阶段综合报价")
|
|
}
|