jmalcloud-view/tests/unit/utils/formatTime.spec.js
jmal 8d34f727bc 网盘web界面:
一、已完成:
			1.完成文件列表的展示、预览、删除、下载(多文件、多目录打包下载)
			2.文件、文件夹的上传,大文件、多文件上传、断点续传(在另一台电脑的浏览器可以继续)
			二、待完成:
			* 移动复制文件和文件夹(可拖动)
			* 文件和文件夹的分享,可设置连接时效
			* 文件的收藏和打标签(方便筛选)
			* 适配手机界面
2020-02-09 16:02:02 +08:00

31 lines
1.0 KiB
JavaScript

import { formatTime } from '@/utils/index.js'
describe('Utils:formatTime', () => {
const d = new Date('2018-07-13 17:54:01') // "2018-07-13 17:54:01"
const retrofit = 5 * 1000
it('ten digits timestamp', () => {
expect(formatTime((d / 1000).toFixed(0))).toBe('7月13日17时54分')
})
it('test now', () => {
expect(formatTime(+new Date() - 1)).toBe('刚刚')
})
it('less two minute', () => {
expect(formatTime(+new Date() - 60 * 2 * 1000 + retrofit)).toBe('2分钟前')
})
it('less two hour', () => {
expect(formatTime(+new Date() - 60 * 60 * 2 * 1000 + retrofit)).toBe('2小时前')
})
it('less one day', () => {
expect(formatTime(+new Date() - 60 * 60 * 24 * 1 * 1000)).toBe('1天前')
})
it('more than one day', () => {
expect(formatTime(d)).toBe('7月13日17时54分')
})
it('format', () => {
expect(formatTime(d, '{y}-{m}-{d} {h}:{i}')).toBe('2018-07-13 17:54')
expect(formatTime(d, '{y}-{m}-{d}')).toBe('2018-07-13')
expect(formatTime(d, '{y}/{m}/{d} {h}-{i}')).toBe('2018/07/13 17-54')
})
})