Skip to content

Commit 73a9b69

Browse files
committed
增加uml类图和测试用例
1 parent bd3543f commit 73a9b69

File tree

2 files changed

+153
-33
lines changed

2 files changed

+153
-33
lines changed

designer/uml.png

29 KB
Loading

test/script/dialog.spec.js

Lines changed: 153 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,149 @@
1-
import Plugin from '../../src'
21
import Vue from 'vue'
2+
import MyDialogPlugin from '../../src'
33

4-
Vue.use(Plugin)
4+
Vue.use(MyDialogPlugin)
55

6-
///////////////////////////////////////创建用于测试的列表控件
7-
let vueInstance = new Vue({template: `<div></div>`}).$mount()
86

9-
describe('Dialog相关', function () {
10-
this.timeout(6000)
11-
it('创建Dialog', async function () {
12-
await new Promise((resolve, reject)=>{
13-
vueInstance.$Dialog.open({
14-
component: {
7+
describe('测试创建MyDialog', function () {
8+
this.timeout(3000)
9+
10+
it('不设置myDialog属性创建', async function () {
11+
let vueInstance = new Vue({
12+
template: `<div></div>`,
13+
}).$mount()
14+
15+
assert.isNull(vueInstance.$MyDialog)
16+
});
17+
18+
it('不设置myDialog的key属性创建', async function () {
19+
let vueInstance = new Vue({
20+
template: `<div></div>`,
21+
myDialog: {},
22+
}).$mount()
23+
24+
assert.isNotNull(vueInstance.$MyDialog)
25+
assert.isString(vueInstance.$MyDialog.key)
26+
});
27+
28+
it('设置myDialog的key属性创建', async function () {
29+
let vueInstance = new Vue({
30+
template: `<div></div>`,
31+
myDialog: {key: 'test'},
32+
}).$mount()
33+
34+
assert.isNotNull(vueInstance.$MyDialog)
35+
assert.deepEqual(vueInstance.$MyDialog.key, 'test')
36+
});
37+
38+
it('测试getInstance()', async function () {
39+
let vueInstance1 = new Vue({
40+
template: `<div></div>`,
41+
myDialog: {key: 'test'},
42+
}).$mount()
43+
44+
assert.deepEqual(MyDialogPlugin.getInstance().key, 'test')
45+
46+
let vueInstance2 = new Vue({
47+
template: `<div></div>`,
48+
myDialog: {key: 'test2'},
49+
}).$mount()
50+
assert.deepEqual(MyDialogPlugin.getInstance().key, 'test2')
51+
});
52+
53+
it('测试getInstance(key)', async function () {
54+
let vueInstance1 = new Vue({
55+
template: `<div></div>`,
56+
myDialog: {key: 'test1'},
57+
}).$mount()
58+
59+
assert.deepEqual(MyDialogPlugin.getInstance('test1').key, 'test1')
60+
assert.equal(MyDialogPlugin.getInstance('test1'), vueInstance1.$MyDialog)
61+
62+
let vueInstance2 = new Vue({
63+
template: `<div></div>`,
64+
myDialog: {key: 'test2'},
65+
}).$mount()
66+
assert.deepEqual(MyDialogPlugin.getInstance('test2').key, 'test2')
67+
assert.equal(MyDialogPlugin.getInstance('test2'), vueInstance2.$MyDialog)
68+
});
69+
70+
it('测试默认配置', async function () {
71+
let vueInstance1 = new Vue({
72+
template: `<div></div>`,
73+
myDialog: {key: 'test1', title: 'test'},
74+
}).$mount()
75+
76+
assert.deepEqual(vueInstance1.$MyDialog.defaultOption.title, 'test')
77+
});
78+
});
79+
80+
81+
describe('测试MyDialogAPI', function () {
82+
83+
let vueInstance = new Vue({
84+
template: `<div></div>`,
85+
myDialog: {},
86+
}).$mount()
87+
88+
before(function(){
89+
if(vueInstance){
90+
vueInstance.$destroy()
91+
vueInstance = null
92+
}
93+
vueInstance = new Vue({
94+
template: `<div></div>`,
95+
myDialog: {},
96+
}).$mount()
97+
})
98+
99+
this.timeout(3000)
100+
101+
it('创建MyDialog', async function () {
102+
let mounted = false
103+
await new Promise((resolve)=>{
104+
vueInstance.$MyDialog.open({
105+
content: {
15106
template: '<span></span>',
16107
mounted(){
108+
mounted = true
109+
this.$myDialog.close()
110+
}
111+
},
112+
onClose(){
113+
if(mounted)
114+
resolve()
115+
}
116+
})
117+
})
118+
119+
});
120+
121+
it('测试默认配置', async function () {
122+
await new Promise((resolve)=>{
123+
vueInstance.$MyDialog.defaultOption.title = 'xxxx'
124+
vueInstance.$MyDialog.open({
125+
content: {
126+
template: '<span></span>',
127+
mounted(){
128+
this.$myDialog.close()
129+
}
130+
},
131+
onClose(){
132+
if(this.getTitle() == 'xxxx'){
17133
resolve()
18134
}
19135
}
20136
})
21137
})
22138
});
23139

24-
it('关闭Dialog和onClose', async function () {
25-
await new Promise((resolve, reject)=>{
26-
vueInstance.$Dialog.open({
27-
component: {
140+
it('关闭MyDialog和onClose', async function () {
141+
await new Promise((resolve)=>{
142+
vueInstance.$MyDialog.open({
143+
content: {
28144
template: '<span></span>',
29145
mounted(){
30-
this.$DialogInstance.close()
146+
this.$myDialog.close()
31147
}
32148
},
33149
onClose(){
@@ -38,18 +154,22 @@ describe('Dialog相关', function () {
38154
});
39155

40156
it('关闭onBeforeClose', async function () {
157+
let result = false
41158
await new Promise((resolve, reject)=>{
42-
vueInstance.$Dialog.open({
43-
component: {
159+
vueInstance.$MyDialog.open({
160+
content: {
44161
template: '<span></span>',
45162
mounted(){
46-
this.$DialogInstance.close(true)
163+
this.$myDialog.close(true)
47164
}
48165
},
49-
onBeforeClose(resulte){
50-
if(resulte)
166+
onBeforeClose(_result){
167+
result = _result
168+
},
169+
onClose(){
170+
if(result)
51171
resolve()
52-
}
172+
},
53173
})
54174
})
55175
});
@@ -60,17 +180,17 @@ describe('Dialog相关', function () {
60180
resolve()
61181
}, 1000)
62182

63-
vueInstance.$Dialog.open({
64-
component: {
183+
vueInstance.$MyDialog.open({
184+
content: {
65185
template: '<span></span>',
66186
mounted(){
67-
this.$DialogInstance.close()
187+
this.$myDialog.close()
68188
}
69189
},
70-
onBeforeClose(resulte){
190+
onBeforeClose(){
71191
return false
72192
},
73-
onClose(resulte){
193+
onClose(){
74194
//如果真的不关闭了,这里会先返回错误
75195
reject('beforeClose失效')
76196
},
@@ -80,13 +200,13 @@ describe('Dialog相关', function () {
80200

81201
it('关闭onBeforeShow', async function () {
82202
let title = await new Promise((resolve, reject)=>{
83-
vueInstance.$Dialog.open({
203+
vueInstance.$MyDialog.open({
84204
title: 'test',
85-
component: {
205+
content: {
86206
template: '<span></span>',
87207
},
88-
onBeforeShow(option){
89-
resolve(option.title)
208+
onBeforeShow(){
209+
resolve(this.getTitle())
90210
},
91211
})
92212
})
@@ -100,10 +220,10 @@ describe('Dialog相关', function () {
100220
resolve()
101221
}, 1000)
102222

103-
vueInstance.$Dialog.open({
104-
component: {
223+
vueInstance.$MyDialog.open({
224+
content: {
105225
template: '<span></span>',
106-
destroyed(){
226+
mounted(){
107227
reject('beforeShow失效')
108228
},
109229
},

0 commit comments

Comments
 (0)