feat(t241): improve freight admin views
This commit is contained in:
@@ -928,13 +928,16 @@ func TestFreightPagesEscapeSourceDataAndCreateSynchronousOrderSync(t *testing.T)
|
||||
service := &fakeFreightService{
|
||||
fakeService: &fakeService{},
|
||||
orders: []FreightOrder{{
|
||||
ID: testTaskID,
|
||||
ExternalStockID: "12",
|
||||
SourceCode: `<script>private</script>`,
|
||||
ShopName: "测试店铺",
|
||||
ItemCount: 2,
|
||||
Revision: 1,
|
||||
UpdatedAt: now,
|
||||
ID: testTaskID,
|
||||
ExternalStockID: "12",
|
||||
SourceCode: `<script>private</script>`,
|
||||
ShopName: "测试店铺",
|
||||
ItemCount: 2,
|
||||
Revision: 1,
|
||||
UpdatedAt: now,
|
||||
PreviewTitle: "脱敏商品标题",
|
||||
PreviewImageStatus: "READY",
|
||||
PreviewImageURL: "/api/v1/freight-items/preview/image",
|
||||
}},
|
||||
createResult: FreightSync{
|
||||
ID: testTaskID,
|
||||
@@ -947,7 +950,10 @@ func TestFreightPagesEscapeSourceDataAndCreateSynchronousOrderSync(t *testing.T)
|
||||
if list.Code != http.StatusOK ||
|
||||
strings.Contains(list.Body.String(), `<script>private</script>`) ||
|
||||
!strings.Contains(list.Body.String(), "<script>private") ||
|
||||
!strings.Contains(list.Body.String(), "2 项") {
|
||||
!strings.Contains(list.Body.String(), "共 2 项") ||
|
||||
!strings.Contains(list.Body.String(), `width="56" height="56"`) ||
|
||||
!strings.Contains(list.Body.String(), `loading="lazy"`) ||
|
||||
!strings.Contains(list.Body.String(), "脱敏商品标题") {
|
||||
t.Fatalf("freight list status/body = %d / %s", list.Code, list.Body)
|
||||
}
|
||||
assertSecurityHeaders(t, list)
|
||||
@@ -1208,6 +1214,7 @@ func TestFreightImportLogsUnknownFailureWithoutRawError(t *testing.T) {
|
||||
|
||||
func TestFreightDetailCreatesProcurementTaskWithCSRF(t *testing.T) {
|
||||
const itemID = "00000000-0000-4000-8000-000000000002"
|
||||
price := int64(12950)
|
||||
service := &fakeProcurementService{
|
||||
fakeFreightService: &fakeFreightService{
|
||||
fakeService: &fakeService{},
|
||||
@@ -1216,14 +1223,20 @@ func TestFreightDetailCreatesProcurementTaskWithCSRF(t *testing.T) {
|
||||
ID: testTaskID,
|
||||
ExternalStockID: "12",
|
||||
SourceCode: "SOURCE-12",
|
||||
ItemCount: 1,
|
||||
},
|
||||
Items: []FreightItemReview{{
|
||||
Item: FreightOrderItem{
|
||||
ID: itemID,
|
||||
ExternalItemID: "88",
|
||||
Title: "商品",
|
||||
SKU: "BLACK-L",
|
||||
Quantity: 2,
|
||||
ID: itemID,
|
||||
ExternalItemID: "88",
|
||||
Title: "商品",
|
||||
ProductSpec: "黑色,L",
|
||||
SKU: "黑色,L",
|
||||
Quantity: 2,
|
||||
OriginalUnitPriceMinor: &price,
|
||||
OriginalCurrency: "TWD",
|
||||
ImageStatus: "READY",
|
||||
ImageURL: "/api/v1/freight-items/" + itemID + "/image",
|
||||
},
|
||||
Request: &ProcurementRequest{
|
||||
ID: itemID,
|
||||
@@ -1250,7 +1263,12 @@ func TestFreightDetailCreatesProcurementTaskWithCSRF(t *testing.T) {
|
||||
)
|
||||
if detail.Code != http.StatusOK ||
|
||||
!strings.Contains(detail.Body.String(), "生成采购任务") ||
|
||||
!strings.Contains(detail.Body.String(), "可以生成任务") {
|
||||
!strings.Contains(detail.Body.String(), "可以生成任务") ||
|
||||
!strings.Contains(detail.Body.String(), "TWD 129.50") ||
|
||||
!strings.Contains(detail.Body.String(), `width="84" height="84"`) ||
|
||||
!strings.Contains(detail.Body.String(), `loading="lazy"`) ||
|
||||
strings.Contains(detail.Body.String(), "图片引用") ||
|
||||
strings.Count(detail.Body.String(), "黑色,L") != 1 {
|
||||
t.Fatalf("detail status/body = %d / %s", detail.Code, detail.Body)
|
||||
}
|
||||
cookie := csrfCookie(t, detail)
|
||||
@@ -1283,6 +1301,26 @@ func TestFreightDetailCreatesProcurementTaskWithCSRF(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFreightPresentationFormatsMoneyAndImageStates(t *testing.T) {
|
||||
value := int64(12905)
|
||||
if got := formatMinorCurrency(&value, "TWD"); got != "TWD 129.05" {
|
||||
t.Fatalf("formatMinorCurrency() = %q", got)
|
||||
}
|
||||
if got := formatMinorCurrency(nil, "TWD"); got != "未提供" {
|
||||
t.Fatalf("nil formatMinorCurrency() = %q", got)
|
||||
}
|
||||
for status, want := range map[string]string{
|
||||
"": "未提供图片",
|
||||
"PENDING": "图片待获取",
|
||||
"MISSING": "ERP 无图片",
|
||||
"FAILED": "图片获取失败",
|
||||
} {
|
||||
if got := freightImageStatusLabel(status); got != want {
|
||||
t.Fatalf("freightImageStatusLabel(%q) = %q", status, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type fakeService struct {
|
||||
listInput ListTasksInput
|
||||
listResult TaskList
|
||||
|
||||
Reference in New Issue
Block a user