freat:页面添加 测试用例

This commit is contained in:
zhangyu
2022-04-15 15:57:27 +08:00
parent 923b8679e8
commit 3de0416f66
8 changed files with 107 additions and 49 deletions

View File

@@ -1,17 +1,23 @@
import { dealLegendAlias } from '@/components/common/js/tools'
import { dealLegendAlias } from '@/components/common/js/example'
describe('别名替换函数', () => {
// 测试代码可读性最好
// 分组
const str = 'node_load1{module="node-exporter",endpoint_id="69",project="Common",datacenter="xin_xi_gang_DC",asset_id="11",endpoint="node-exporter-192.168.44.18",module_id="165",nz_agent_id="75",project_id="17",olap="node_exporter_nacos",asset="Bifang-CM-Server2",datacenter_id="4"} '
it('正常替换一个', () => {
expect(dealLegendAlias('{a:1,b:2}', '{{a}}')).toBe('1')
expect(dealLegendAlias(str, '{{module}}')).toBe('node-exporter')
})
it('正常替换多个个', () => {
expect(dealLegendAlias('{a:1,b:2}', '{{a}}{{b}}')).toBe('12')
expect(dealLegendAlias(str, '{{module}}{{endpoint_id}}')).toBe('node-exporter69')
})
it('匹配不到', () => {
expect(dealLegendAlias('{a:1,b:2}', '{{c}}')).toBe('')
expect(dealLegendAlias(str, '{{c}}')).toBe('')
})
it('没有legend', () => {
expect(dealLegendAlias('{a:1,b:2}', '')).toBe('{a:1,b:2}')
expect(dealLegendAlias(str, '')).toBe(str)
})
it('legend没有变量', () => {
expect(dealLegendAlias(str, 'c')).toBe('c')
})
})