| 123456789101112131415161718192021 |
- import { describe, expect, it } from 'vitest'
- import {
- formatTextDeviceValue,
- formatTextDisplayValue
- } from '@/components/mt-edit/utils/text-format'
- describe('文字组件格式化', () => {
- it('保留用户主动输入的换行', () => {
- expect(formatTextDisplayValue('第一行\n第二行')).toBe('第一行\n第二行')
- })
- it('支持前后缀和空值文字', () => {
- expect(formatTextDisplayValue('23.5', { prefix: '温度:', suffix: '℃' })).toBe('温度:23.5℃')
- expect(formatTextDisplayValue('', { emptyText: '暂无数据' })).toBe('暂无数据')
- })
- it('支持设备数值精度和单位显示', () => {
- expect(formatTextDeviceValue(23.456, '℃', { decimalPlaces: 2, showUnit: true })).toBe('23.46 ℃')
- expect(formatTextDeviceValue(23.456, '℃', { decimalPlaces: 1, showUnit: false })).toBe('23.5')
- })
- })
|