jufubao-admin-library 1.0.0-beta1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/encodings.xml +6 -0
- package/.idea/misc.xml +14 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/xd-admin-buss-library.iml +12 -0
- package/package.json +1 -1
- package/tests/unit/components/Breadcrumb.spec.js +98 -0
- package/tests/unit/components/Hamburger.spec.js +18 -0
- package/tests/unit/components/SvgIcon.spec.js +22 -0
- package/tests/unit/utils/formatTime.spec.js +30 -0
- package/tests/unit/utils/param2Obj.spec.js +14 -0
- package/tests/unit/utils/parseTime.spec.js +35 -0
- package/tests/unit/utils/validate.spec.js +17 -0
package/.idea/misc.xml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ComposerSettings">
|
|
4
|
+
<pharPath>/usr/local/bin/composer</pharPath>
|
|
5
|
+
<phpPath>/usr/local/bin/php</phpPath>
|
|
6
|
+
</component>
|
|
7
|
+
<component name="PhpDebugGeneral" xdebug_debug_port="7757" />
|
|
8
|
+
<component name="PhpUnit">
|
|
9
|
+
<phpunit_settings>
|
|
10
|
+
<PhpUnitSettings load_method="PHPUNIT_PHAR" custom_loader_path="" phpunit_phar_path="/usr/local/bin/phpunit" />
|
|
11
|
+
</phpunit_settings>
|
|
12
|
+
</component>
|
|
13
|
+
<component name="PhpWorkspaceProjectConfiguration" backward_compatibility_performed="true" interpreter_name="PHP 5.6.13 local" />
|
|
14
|
+
</project>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/xd-admin-buss-library.iml" filepath="$PROJECT_DIR$/.idea/xd-admin-buss-library.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
package/.idea/vcs.xml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$">
|
|
5
|
+
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
6
|
+
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
7
|
+
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
|
+
</content>
|
|
9
|
+
<orderEntry type="inheritedJdk" />
|
|
10
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
11
|
+
</component>
|
|
12
|
+
</module>
|
package/package.json
CHANGED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { mount, createLocalVue } from '@vue/test-utils'
|
|
2
|
+
import VueRouter from 'vue-router'
|
|
3
|
+
import ElementUI from 'element-ui'
|
|
4
|
+
import Breadcrumb from '@/components/Breadcrumb/index.vue'
|
|
5
|
+
|
|
6
|
+
const localVue = createLocalVue()
|
|
7
|
+
localVue.use(VueRouter)
|
|
8
|
+
localVue.use(ElementUI)
|
|
9
|
+
|
|
10
|
+
const routes = [
|
|
11
|
+
{
|
|
12
|
+
path: '/',
|
|
13
|
+
name: 'home',
|
|
14
|
+
children: [{
|
|
15
|
+
path: 'dashboard',
|
|
16
|
+
name: 'dashboard'
|
|
17
|
+
}]
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
path: '/menu',
|
|
21
|
+
name: 'menu',
|
|
22
|
+
children: [{
|
|
23
|
+
path: 'menu1',
|
|
24
|
+
name: 'menu1',
|
|
25
|
+
meta: { title: 'menu1' },
|
|
26
|
+
children: [{
|
|
27
|
+
path: 'menu1-1',
|
|
28
|
+
name: 'menu1-1',
|
|
29
|
+
meta: { title: 'menu1-1' }
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
path: 'menu1-2',
|
|
33
|
+
name: 'menu1-2',
|
|
34
|
+
redirect: 'noredirect',
|
|
35
|
+
meta: { title: 'menu1-2' },
|
|
36
|
+
children: [{
|
|
37
|
+
path: 'menu1-2-1',
|
|
38
|
+
name: 'menu1-2-1',
|
|
39
|
+
meta: { title: 'menu1-2-1' }
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
path: 'menu1-2-2',
|
|
43
|
+
name: 'menu1-2-2'
|
|
44
|
+
}]
|
|
45
|
+
}]
|
|
46
|
+
}]
|
|
47
|
+
}]
|
|
48
|
+
|
|
49
|
+
const router = new VueRouter({
|
|
50
|
+
routes
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
describe('Breadcrumb.vue', () => {
|
|
54
|
+
const wrapper = mount(Breadcrumb, {
|
|
55
|
+
localVue,
|
|
56
|
+
router
|
|
57
|
+
})
|
|
58
|
+
it('dashboard', () => {
|
|
59
|
+
router.push('/dashboard')
|
|
60
|
+
const len = wrapper.findAll('.el-breadcrumb__inner').length
|
|
61
|
+
expect(len).toBe(1)
|
|
62
|
+
})
|
|
63
|
+
it('normal route', () => {
|
|
64
|
+
router.push('/menu/menu1')
|
|
65
|
+
const len = wrapper.findAll('.el-breadcrumb__inner').length
|
|
66
|
+
expect(len).toBe(2)
|
|
67
|
+
})
|
|
68
|
+
it('nested route', () => {
|
|
69
|
+
router.push('/menu/menu1/menu1-2/menu1-2-1')
|
|
70
|
+
const len = wrapper.findAll('.el-breadcrumb__inner').length
|
|
71
|
+
expect(len).toBe(4)
|
|
72
|
+
})
|
|
73
|
+
it('no meta.title', () => {
|
|
74
|
+
router.push('/menu/menu1/menu1-2/menu1-2-2')
|
|
75
|
+
const len = wrapper.findAll('.el-breadcrumb__inner').length
|
|
76
|
+
expect(len).toBe(3)
|
|
77
|
+
})
|
|
78
|
+
// it('click link', () => {
|
|
79
|
+
// router.push('/menu/menu1/menu1-2/menu1-2-2')
|
|
80
|
+
// const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner')
|
|
81
|
+
// const second = breadcrumbArray.at(1)
|
|
82
|
+
// console.log(breadcrumbArray)
|
|
83
|
+
// const href = second.find('a').attributes().href
|
|
84
|
+
// expect(href).toBe('#/menu/menu1')
|
|
85
|
+
// })
|
|
86
|
+
// it('noRedirect', () => {
|
|
87
|
+
// router.push('/menu/menu1/menu1-2/menu1-2-1')
|
|
88
|
+
// const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner')
|
|
89
|
+
// const redirectBreadcrumb = breadcrumbArray.at(2)
|
|
90
|
+
// expect(redirectBreadcrumb.contains('a')).toBe(false)
|
|
91
|
+
// })
|
|
92
|
+
it('last breadcrumb', () => {
|
|
93
|
+
router.push('/menu/menu1/menu1-2/menu1-2-1')
|
|
94
|
+
const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner')
|
|
95
|
+
const redirectBreadcrumb = breadcrumbArray.at(3)
|
|
96
|
+
expect(redirectBreadcrumb.contains('a')).toBe(false)
|
|
97
|
+
})
|
|
98
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { shallowMount } from '@vue/test-utils'
|
|
2
|
+
import Hamburger from '@/components/Hamburger/index.vue'
|
|
3
|
+
describe('Hamburger.vue', () => {
|
|
4
|
+
it('toggle click', () => {
|
|
5
|
+
const wrapper = shallowMount(Hamburger)
|
|
6
|
+
const mockFn = jest.fn()
|
|
7
|
+
wrapper.vm.$on('toggleClick', mockFn)
|
|
8
|
+
wrapper.find('.hamburger').trigger('click')
|
|
9
|
+
expect(mockFn).toBeCalled()
|
|
10
|
+
})
|
|
11
|
+
it('prop isActive', () => {
|
|
12
|
+
const wrapper = shallowMount(Hamburger)
|
|
13
|
+
wrapper.setProps({ isActive: true })
|
|
14
|
+
expect(wrapper.contains('.is-active')).toBe(true)
|
|
15
|
+
wrapper.setProps({ isActive: false })
|
|
16
|
+
expect(wrapper.contains('.is-active')).toBe(false)
|
|
17
|
+
})
|
|
18
|
+
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { shallowMount } from '@vue/test-utils'
|
|
2
|
+
import SvgIcon from '@/components/SvgIcon/index.vue'
|
|
3
|
+
describe('SvgIcon.vue', () => {
|
|
4
|
+
it('iconClass', () => {
|
|
5
|
+
const wrapper = shallowMount(SvgIcon, {
|
|
6
|
+
propsData: {
|
|
7
|
+
iconClass: 'test'
|
|
8
|
+
}
|
|
9
|
+
})
|
|
10
|
+
expect(wrapper.find('use').attributes().href).toBe('#icon-test')
|
|
11
|
+
})
|
|
12
|
+
it('className', () => {
|
|
13
|
+
const wrapper = shallowMount(SvgIcon, {
|
|
14
|
+
propsData: {
|
|
15
|
+
iconClass: 'test'
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
expect(wrapper.classes().length).toBe(1)
|
|
19
|
+
wrapper.setProps({ className: 'test' })
|
|
20
|
+
expect(wrapper.classes().includes('test')).toBe(true)
|
|
21
|
+
})
|
|
22
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { formatTime } from '@/utils/index.js'
|
|
2
|
+
|
|
3
|
+
describe('Utils:formatTime', () => {
|
|
4
|
+
const d = new Date('2018-07-13 17:54:01') // "2018-07-13 17:54:01"
|
|
5
|
+
const retrofit = 5 * 1000
|
|
6
|
+
|
|
7
|
+
it('ten digits timestamp', () => {
|
|
8
|
+
expect(formatTime((d / 1000).toFixed(0))).toBe('7月13日17时54分')
|
|
9
|
+
})
|
|
10
|
+
it('test now', () => {
|
|
11
|
+
expect(formatTime(+new Date() - 1)).toBe('刚刚')
|
|
12
|
+
})
|
|
13
|
+
it('less two minute', () => {
|
|
14
|
+
expect(formatTime(+new Date() - 60 * 2 * 1000 + retrofit)).toBe('2分钟前')
|
|
15
|
+
})
|
|
16
|
+
it('less two hour', () => {
|
|
17
|
+
expect(formatTime(+new Date() - 60 * 60 * 2 * 1000 + retrofit)).toBe('2小时前')
|
|
18
|
+
})
|
|
19
|
+
it('less one day', () => {
|
|
20
|
+
expect(formatTime(+new Date() - 60 * 60 * 24 * 1 * 1000)).toBe('1天前')
|
|
21
|
+
})
|
|
22
|
+
it('more than one day', () => {
|
|
23
|
+
expect(formatTime(d)).toBe('7月13日17时54分')
|
|
24
|
+
})
|
|
25
|
+
it('format', () => {
|
|
26
|
+
expect(formatTime(d, '{y}-{m}-{d} {h}:{i}')).toBe('2018-07-13 17:54')
|
|
27
|
+
expect(formatTime(d, '{y}-{m}-{d}')).toBe('2018-07-13')
|
|
28
|
+
expect(formatTime(d, '{y}/{m}/{d} {h}-{i}')).toBe('2018/07/13 17-54')
|
|
29
|
+
})
|
|
30
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { param2Obj } from '@/utils/index.js'
|
|
2
|
+
describe('Utils:param2Obj', () => {
|
|
3
|
+
const url = 'https://github.com/PanJiaChen/vue-element-admin?name=bill&age=29&sex=1&field=dGVzdA==&key=%E6%B5%8B%E8%AF%95'
|
|
4
|
+
|
|
5
|
+
it('param2Obj test', () => {
|
|
6
|
+
expect(param2Obj(url)).toEqual({
|
|
7
|
+
name: 'bill',
|
|
8
|
+
age: '29',
|
|
9
|
+
sex: '1',
|
|
10
|
+
field: window.btoa('test'),
|
|
11
|
+
key: '测试'
|
|
12
|
+
})
|
|
13
|
+
})
|
|
14
|
+
})
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { parseTime } from '@/utils/index.js'
|
|
2
|
+
|
|
3
|
+
describe('Utils:parseTime', () => {
|
|
4
|
+
const d = new Date('2018-07-13 17:54:01') // "2018-07-13 17:54:01"
|
|
5
|
+
it('timestamp', () => {
|
|
6
|
+
expect(parseTime(d)).toBe('2018-07-13 17:54:01')
|
|
7
|
+
})
|
|
8
|
+
it('timestamp string', () => {
|
|
9
|
+
expect(parseTime((d + ''))).toBe('2018-07-13 17:54:01')
|
|
10
|
+
})
|
|
11
|
+
it('ten digits timestamp', () => {
|
|
12
|
+
expect(parseTime((d / 1000).toFixed(0))).toBe('2018-07-13 17:54:01')
|
|
13
|
+
})
|
|
14
|
+
it('new Date', () => {
|
|
15
|
+
expect(parseTime(new Date(d))).toBe('2018-07-13 17:54:01')
|
|
16
|
+
})
|
|
17
|
+
it('format', () => {
|
|
18
|
+
expect(parseTime(d, '{y}-{m}-{d} {h}:{i}')).toBe('2018-07-13 17:54')
|
|
19
|
+
expect(parseTime(d, '{y}-{m}-{d}')).toBe('2018-07-13')
|
|
20
|
+
expect(parseTime(d, '{y}/{m}/{d} {h}-{i}')).toBe('2018/07/13 17-54')
|
|
21
|
+
})
|
|
22
|
+
it('get the day of the week', () => {
|
|
23
|
+
expect(parseTime(d, '{a}')).toBe('五') // 星期五
|
|
24
|
+
})
|
|
25
|
+
it('get the day of the week', () => {
|
|
26
|
+
expect(parseTime(+d + 1000 * 60 * 60 * 24 * 2, '{a}')).toBe('日') // 星期日
|
|
27
|
+
})
|
|
28
|
+
it('empty argument', () => {
|
|
29
|
+
expect(parseTime()).toBeNull()
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('null', () => {
|
|
33
|
+
expect(parseTime(null)).toBeNull()
|
|
34
|
+
})
|
|
35
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { validUsername, isExternal } from '@/utils/validate.js'
|
|
2
|
+
|
|
3
|
+
describe('Utils:validate', () => {
|
|
4
|
+
it('validUsername', () => {
|
|
5
|
+
expect(validUsername('admin')).toBe(true)
|
|
6
|
+
expect(validUsername('editor')).toBe(true)
|
|
7
|
+
expect(validUsername('xxxx')).toBe(false)
|
|
8
|
+
})
|
|
9
|
+
it('isExternal', () => {
|
|
10
|
+
expect(isExternal('https://github.com/PanJiaChen/vue-element-admin')).toBe(true)
|
|
11
|
+
expect(isExternal('http://github.com/PanJiaChen/vue-element-admin')).toBe(true)
|
|
12
|
+
expect(isExternal('github.com/PanJiaChen/vue-element-admin')).toBe(false)
|
|
13
|
+
expect(isExternal('/dashboard')).toBe(false)
|
|
14
|
+
expect(isExternal('./dashboard')).toBe(false)
|
|
15
|
+
expect(isExternal('dashboard')).toBe(false)
|
|
16
|
+
})
|
|
17
|
+
})
|