实现用户角色权限区域管理模块
This commit is contained in:
		
							
								
								
									
										30
									
								
								ssyx-admin/tests/unit/utils/formatTime.spec.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								ssyx-admin/tests/unit/utils/formatTime.spec.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
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')
 | 
			
		||||
  })
 | 
			
		||||
})
 | 
			
		||||
							
								
								
									
										15
									
								
								ssyx-admin/tests/unit/utils/param2Obj.spec.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								ssyx-admin/tests/unit/utils/param2Obj.spec.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
import {param2Obj} from '@/utils/index.js'
 | 
			
		||||
 | 
			
		||||
describe('Utils:param2Obj', () => {
 | 
			
		||||
  const url = 'https://github.com/PanJiaChen/vue-element-admin?name=bill&age=29&sex=1&field=dGVzdA==&key=%E6%B5%8B%E8%AF%95'
 | 
			
		||||
 | 
			
		||||
  it('param2Obj test', () => {
 | 
			
		||||
    expect(param2Obj(url)).toEqual({
 | 
			
		||||
      name: 'bill',
 | 
			
		||||
      age: '29',
 | 
			
		||||
      sex: '1',
 | 
			
		||||
      field: window.btoa('test'),
 | 
			
		||||
      key: '测试'
 | 
			
		||||
    })
 | 
			
		||||
  })
 | 
			
		||||
})
 | 
			
		||||
							
								
								
									
										35
									
								
								ssyx-admin/tests/unit/utils/parseTime.spec.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								ssyx-admin/tests/unit/utils/parseTime.spec.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
import {parseTime} from '@/utils/index.js'
 | 
			
		||||
 | 
			
		||||
describe('Utils:parseTime', () => {
 | 
			
		||||
  const d = new Date('2018-07-13 17:54:01') // "2018-07-13 17:54:01"
 | 
			
		||||
  it('timestamp', () => {
 | 
			
		||||
    expect(parseTime(d)).toBe('2018-07-13 17:54:01')
 | 
			
		||||
  })
 | 
			
		||||
  it('timestamp string', () => {
 | 
			
		||||
    expect(parseTime((d + ''))).toBe('2018-07-13 17:54:01')
 | 
			
		||||
  })
 | 
			
		||||
  it('ten digits timestamp', () => {
 | 
			
		||||
    expect(parseTime((d / 1000).toFixed(0))).toBe('2018-07-13 17:54:01')
 | 
			
		||||
  })
 | 
			
		||||
  it('new Date', () => {
 | 
			
		||||
    expect(parseTime(new Date(d))).toBe('2018-07-13 17:54:01')
 | 
			
		||||
  })
 | 
			
		||||
  it('format', () => {
 | 
			
		||||
    expect(parseTime(d, '{y}-{m}-{d} {h}:{i}')).toBe('2018-07-13 17:54')
 | 
			
		||||
    expect(parseTime(d, '{y}-{m}-{d}')).toBe('2018-07-13')
 | 
			
		||||
    expect(parseTime(d, '{y}/{m}/{d} {h}-{i}')).toBe('2018/07/13 17-54')
 | 
			
		||||
  })
 | 
			
		||||
  it('get the day of the week', () => {
 | 
			
		||||
    expect(parseTime(d, '{a}')).toBe('五') // 星期五
 | 
			
		||||
  })
 | 
			
		||||
  it('get the day of the week', () => {
 | 
			
		||||
    expect(parseTime(+d + 1000 * 60 * 60 * 24 * 2, '{a}')).toBe('日') // 星期日
 | 
			
		||||
  })
 | 
			
		||||
  it('empty argument', () => {
 | 
			
		||||
    expect(parseTime()).toBeNull()
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  it('null', () => {
 | 
			
		||||
    expect(parseTime(null)).toBeNull()
 | 
			
		||||
  })
 | 
			
		||||
})
 | 
			
		||||
							
								
								
									
										17
									
								
								ssyx-admin/tests/unit/utils/validate.spec.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								ssyx-admin/tests/unit/utils/validate.spec.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
import {validUsername, isExternal} from '@/utils/validate.js'
 | 
			
		||||
 | 
			
		||||
describe('Utils:validate', () => {
 | 
			
		||||
  it('validUsername', () => {
 | 
			
		||||
    expect(validUsername('admin')).toBe(true)
 | 
			
		||||
    expect(validUsername('editor')).toBe(true)
 | 
			
		||||
    expect(validUsername('xxxx')).toBe(false)
 | 
			
		||||
  })
 | 
			
		||||
  it('isExternal', () => {
 | 
			
		||||
    expect(isExternal('https://github.com/PanJiaChen/vue-element-admin')).toBe(true)
 | 
			
		||||
    expect(isExternal('http://github.com/PanJiaChen/vue-element-admin')).toBe(true)
 | 
			
		||||
    expect(isExternal('github.com/PanJiaChen/vue-element-admin')).toBe(false)
 | 
			
		||||
    expect(isExternal('/dashboard')).toBe(false)
 | 
			
		||||
    expect(isExternal('./dashboard')).toBe(false)
 | 
			
		||||
    expect(isExternal('dashboard')).toBe(false)
 | 
			
		||||
  })
 | 
			
		||||
})
 | 
			
		||||
		Reference in New Issue
	
	Block a user