2019-04-30 11:11:25 +08:00
|
|
|
import {
|
|
|
|
prettyBytes,
|
|
|
|
escapeHtml,
|
2019-05-05 11:58:05 +08:00
|
|
|
formatDuration,
|
|
|
|
resolveVariableAndFilter
|
2019-04-30 11:11:25 +08:00
|
|
|
} from '../../src/utils/tpl-builtin';
|
|
|
|
|
|
|
|
test('tpl-builtin:prettyBytes', () => {
|
|
|
|
expect(prettyBytes(1024)).toEqual('1.02 kB');
|
|
|
|
expect(prettyBytes(1024000)).toEqual('1.02 MB');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test('tpl-builtin:escapeHtml', () => {
|
|
|
|
expect(escapeHtml('<div id="1">Hello&world</div>')).toEqual('<div id="1">Hello&world</div>');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('tpl-builtin:formatDuration', () => {
|
|
|
|
expect(formatDuration(1)).toEqual('1秒');
|
|
|
|
expect(formatDuration(61)).toEqual('1分1秒');
|
|
|
|
expect(formatDuration(233233)).toEqual('3天17时47分13秒');
|
2019-05-05 11:58:05 +08:00
|
|
|
})
|
2019-04-30 11:11:25 +08:00
|
|
|
|
2019-05-05 11:58:05 +08:00
|
|
|
test('tpl-bultin:resolveVariableAndFilter', () => {
|
|
|
|
const data = {
|
|
|
|
a: 1,
|
|
|
|
b: '2',
|
|
|
|
c: {
|
|
|
|
'1': 'first',
|
|
|
|
'2': 'second'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(resolveVariableAndFilter('${a}', data, '| raw')).toEqual(1);
|
|
|
|
expect(resolveVariableAndFilter('${b}', data, '| raw')).toEqual('2');
|
|
|
|
expect(resolveVariableAndFilter('${c.${a}}', data, '| raw')).toEqual('first');
|
|
|
|
expect(resolveVariableAndFilter('${c.${b}}', data, '| raw')).toEqual('second');
|
|
|
|
});
|