|
|
@@ -0,0 +1,70 @@
|
|
|
+import assert from 'node:assert/strict'
|
|
|
+import { describe, it } from 'node:test'
|
|
|
+import {
|
|
|
+ MP_PRODUCT_STATUS_FILTERS,
|
|
|
+ buildProductListQuery,
|
|
|
+ buildProductCard,
|
|
|
+ productStatusLabel,
|
|
|
+ productStatusTagType
|
|
|
+} from './mp-crm-product-card'
|
|
|
+
|
|
|
+describe('MP_PRODUCT_STATUS_FILTERS', () => {
|
|
|
+ it('defaults on first and includes all/off', () => {
|
|
|
+ assert.equal(MP_PRODUCT_STATUS_FILTERS[0].value, 'on')
|
|
|
+ assert.deepEqual(
|
|
|
+ MP_PRODUCT_STATUS_FILTERS.map((x) => x.value),
|
|
|
+ ['on', 'all', 'off']
|
|
|
+ )
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+describe('buildProductListQuery', () => {
|
|
|
+ it('defaults statusIn on and passes keyword/page', () => {
|
|
|
+ assert.deepEqual(
|
|
|
+ buildProductListQuery({ page: 1, pageSize: 20, statusFilter: 'on', keyword: ' 酸 ' }),
|
|
|
+ { page: 1, pageSize: 20, statusIn: 'on', keyword: '酸' }
|
|
|
+ )
|
|
|
+ })
|
|
|
+ it('omits statusIn when filter is all', () => {
|
|
|
+ const q = buildProductListQuery({ page: 2, pageSize: 10, statusFilter: 'all', keyword: '' })
|
|
|
+ assert.equal(q.page, 2)
|
|
|
+ assert.equal(q.statusIn, undefined)
|
|
|
+ assert.equal('keyword' in q, false)
|
|
|
+ })
|
|
|
+ it('sets statusIn off', () => {
|
|
|
+ assert.equal(
|
|
|
+ buildProductListQuery({ page: 1, pageSize: 20, statusFilter: 'off', keyword: '' }).statusIn,
|
|
|
+ 'off'
|
|
|
+ )
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+describe('buildProductCard', () => {
|
|
|
+ it('maps fields and tags', () => {
|
|
|
+ const card = buildProductCard({
|
|
|
+ id: 'p1',
|
|
|
+ productNo: 'SX001',
|
|
|
+ productName: '硫酸',
|
|
|
+ categoryPath: '化工 / 酸类',
|
|
|
+ model: '98%',
|
|
|
+ status: 'on',
|
|
|
+ isToxic: 1,
|
|
|
+ isExplosive: 0
|
|
|
+ })
|
|
|
+ assert.equal(card.id, 'p1')
|
|
|
+ assert.equal(card.productNo, 'SX001')
|
|
|
+ assert.equal(card.statusLabel, '上架')
|
|
|
+ assert.equal(card.statusTagType, 'success')
|
|
|
+ assert.equal(card.showToxic, true)
|
|
|
+ assert.equal(card.showExplosive, false)
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+describe('productStatusTagType', () => {
|
|
|
+ it('maps on→success off→info', () => {
|
|
|
+ assert.equal(productStatusTagType('on'), 'success')
|
|
|
+ assert.equal(productStatusTagType('off'), 'info')
|
|
|
+ assert.equal(productStatusLabel('on'), '上架')
|
|
|
+ assert.equal(productStatusLabel('off'), '下架')
|
|
|
+ })
|
|
|
+})
|