feat: 重建 Bell GoAdmin 产品骨架 (#62)

This commit is contained in:
QiuSW
2026-08-27 18:20:40 +08:00
parent b37c350096
commit f5a3dd796b
715 changed files with 75278 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
module.exports = {
env: {
jest: true
}
}
@@ -0,0 +1,16 @@
import { shallowMount } from '@vue/test-utils'
import Hamburger from '@/components/Hamburger/index.vue'
describe('Hamburger.vue', () => {
it('toggle click', async() => {
const wrapper = shallowMount(Hamburger)
await wrapper.find('.hamburger').trigger('click')
expect(wrapper.emitted('toggleClick')).toBeTruthy()
})
it('prop isActive', async() => {
const wrapper = shallowMount(Hamburger)
await wrapper.setProps({ isActive: true })
expect(wrapper.find('.is-active').exists()).toBe(true)
await wrapper.setProps({ isActive: false })
expect(wrapper.find('.is-active').exists()).toBe(false)
})
})
@@ -0,0 +1,22 @@
import { shallowMount } from '@vue/test-utils'
import SvgIcon from '@/components/SvgIcon/index.vue'
describe('SvgIcon.vue', () => {
it('iconClass', () => {
const wrapper = shallowMount(SvgIcon, {
props: {
iconClass: 'test'
}
})
expect(wrapper.find('use').attributes().href).toBe('#icon-test')
})
it('className', async() => {
const wrapper = shallowMount(SvgIcon, {
props: {
iconClass: 'test'
}
})
expect(wrapper.classes().length).toBe(1)
await wrapper.setProps({ className: 'test' })
expect(wrapper.classes().includes('test')).toBe(true)
})
})
@@ -0,0 +1,36 @@
import { mount } from '@vue/test-utils'
import permisaction from '@/directive/permission/permisaction'
jest.mock('@/store', () => ({
getters: {
permisaction: ['admin:sysUser:add', 'admin:sysUser:edit']
}
}))
// 指令通过 el.parentNode.removeChild(el) 移除元素,因此被测元素必须有父节点
const factory = value =>
mount(
{
template: '<div><button v-permisaction="value">操作</button></div>',
data: () => ({ value })
},
{
global: { directives: { permisaction } }
}
)
describe('v-permisaction', () => {
it('拥有权限时保留元素', () => {
const wrapper = factory(['admin:sysUser:add'])
expect(wrapper.find('button').exists()).toBe(true)
})
it('缺少权限时移除元素', () => {
const wrapper = factory(['admin:sysUser:delete'])
expect(wrapper.find('button').exists()).toBe(false)
})
it('权限值为空数组时抛出错误', () => {
expect(() => factory([])).toThrow('请设置操作权限标签值')
})
})
@@ -0,0 +1,36 @@
import { mount } from '@vue/test-utils'
import permission from '@/directive/permission/permission'
jest.mock('@/store', () => ({
getters: {
roles: ['editor']
}
}))
// 指令通过 el.parentNode.removeChild(el) 移除元素,因此被测元素必须有父节点
const factory = value =>
mount(
{
template: '<div><section v-permission="value">内容</section></div>',
data: () => ({ value })
},
{
global: { directives: { permission } }
}
)
describe('v-permission', () => {
it('角色匹配时保留元素', () => {
const wrapper = factory(['editor'])
expect(wrapper.find('section').exists()).toBe(true)
})
it('角色不匹配时移除元素', () => {
const wrapper = factory(['admin'])
expect(wrapper.find('section').exists()).toBe(false)
})
it('角色值为空数组时抛出错误', () => {
expect(() => factory([])).toThrow('need roles!')
})
})
@@ -0,0 +1,29 @@
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')
})
})
@@ -0,0 +1,27 @@
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('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()
})
})
+28
View File
@@ -0,0 +1,28 @@
import { validUsername, validURL, validLowerCase, validUpperCase, validAlphabets } 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('validURL', () => {
expect(validURL('https://github.com/PanJiaChen/vue-element-admin')).toBe(true)
expect(validURL('http://github.com/PanJiaChen/vue-element-admin')).toBe(true)
expect(validURL('github.com/PanJiaChen/vue-element-admin')).toBe(false)
})
it('validLowerCase', () => {
expect(validLowerCase('abc')).toBe(true)
expect(validLowerCase('Abc')).toBe(false)
expect(validLowerCase('123abc')).toBe(false)
})
it('validUpperCase', () => {
expect(validUpperCase('ABC')).toBe(true)
expect(validUpperCase('Abc')).toBe(false)
expect(validUpperCase('123ABC')).toBe(false)
})
it('validAlphabets', () => {
expect(validAlphabets('ABC')).toBe(true)
expect(validAlphabets('Abc')).toBe(true)
expect(validAlphabets('123aBC')).toBe(false)
})
})