|
|
@@ -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), /<script/)
|
|
|
+ assert.equal(opts.theme, undefined)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('escapes html in danger message body', () => {
|
|
|
+ const opts = buildProductConfirmOptions({
|
|
|
+ kind: 'danger',
|
|
|
+ title: '删除产品',
|
|
|
+ message: 'a <b>x</b> & "y"'
|
|
|
+ })
|
|
|
+ assert.match(String(opts.message), /a <b>x<\/b> & "y"/)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('allows override confirmButtonText', () => {
|
|
|
+ const opts = buildProductConfirmOptions({
|
|
|
+ kind: 'default',
|
|
|
+ title: '上架产品',
|
|
|
+ message: '确认上架该产品?',
|
|
|
+ confirmButtonText: '立即上架'
|
|
|
+ })
|
|
|
+ assert.equal(opts.confirmButtonText, '立即上架')
|
|
|
+ })
|
|
|
+})
|