diff --git a/web-admin/src/utils/mp-crm-product-confirm.test.ts b/web-admin/src/utils/mp-crm-product-confirm.test.ts new file mode 100644 index 000000000..5a2298ec3 --- /dev/null +++ b/web-admin/src/utils/mp-crm-product-confirm.test.ts @@ -0,0 +1,56 @@ +import assert from 'node:assert/strict' +import { describe, it } from 'node:test' +import { buildProductConfirmOptions } from './mp-crm-product-confirm' + +describe('buildProductConfirmOptions', () => { + it('builds scheme A for non-delete confirms', () => { + const opts = buildProductConfirmOptions({ + kind: 'default', + title: '下架产品', + message: '确认下架该产品?' + }) + assert.equal(opts.title, '下架产品') + assert.equal(opts.message, '确认下架该产品?') + assert.equal(opts.allowHtml, false) + assert.equal(opts.className, 'mp-product-dialog') + assert.equal(opts.confirmButtonText, '确认') + assert.equal(opts.confirmButtonColor, '#0a9f6d') + assert.equal(opts.theme, undefined) + }) + + it('builds scheme B for delete confirms with warn html', () => { + const opts = buildProductConfirmOptions({ + kind: 'danger', + title: '删除产品', + message: '确认删除该产品?删除后不可恢复。' + }) + assert.equal(opts.title, '删除产品') + assert.equal(opts.allowHtml, true) + assert.equal(opts.className, 'mp-product-dialog mp-product-dialog--danger') + assert.equal(opts.confirmButtonText, '确认删除') + assert.equal(opts.confirmButtonColor, '#dc2626') + assert.match(String(opts.message), /mp-product-dialog__warn/) + assert.match(String(opts.message), /确认删除该产品?删除后不可恢复。/) + assert.doesNotMatch(String(opts.message), /