helpers.test.js 1.43 KB
/**
 * 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.url(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();
});