helpers.test.js
1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* library helpers 类单元测试
* @author jeff.jiang<jeff.jiang@yoho.cn>
* @date 2016/05/17
*/
'use strict';
const test = require('ava');
const helpers = require('../../library/helpers');
test('qiniu image url handle', t => {
let url = 'http://img11.static.yhbimg.com/yhb-img01/2016/04/18/03/016d50b20cfdec5a91c614b68546bc9d72.jpg?imageView2/{mode}/w/{width}/h/{height}';
let expected = 'http://img11.static.yhbimg.com/yhb-img01/2016/04/18/03/016d50b20cfdec5a91c614b68546bc9d72.jpg?imageView2/2/w/400/h/300';
t.is(helpers.image(url, 400, 300), expected);
});
test('uri format', t => {
let uri = '/test';
let qs = { name: 'yoho' };
let mod = 'list';
let expected = '//list.m.yohobuy.com/test?name=yoho';
t.is(helpers.urlFormat(uri, qs, mod), expected);
});
test('upper char to lowercase', t => {
let str = 'ABc';
let expected = 'abc';
t.is(helpers.lowerCase(str), expected);
});
test('lower char to uppercase', t => {
let str = 'abc!';
let expected = 'ABC!';
t.is(helpers.upperCase(str), expected);
});
test('date format test', (t) => {
let seconds = 60 * 60 * 3 + 2;
let str = helpers.dateFormat('HH:mm:ss', seconds, 'ss');
let expected = '03:00:02';
t.is(str, expected);
});
test('date diff format test', (t) => {
let seconds = 60 * 60 * 24 * (1.3) + 2;
let str = helpers.dateDiffFormat('{d}天{h}小时', seconds, 's');
console.log(str);
t.pass();
});