1
- import Plugin from '../../src'
2
1
import Vue from 'vue'
2
+ import MyDialogPlugin from '../../src'
3
3
4
- Vue . use ( Plugin )
4
+ Vue . use ( MyDialogPlugin )
5
5
6
- ///////////////////////////////////////创建用于测试的列表控件
7
- let vueInstance = new Vue ( { template : `<div></div>` } ) . $mount ( )
8
6
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 : {
15
106
template : '<span></span>' ,
16
107
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' ) {
17
133
resolve ( )
18
134
}
19
135
}
20
136
} )
21
137
} )
22
138
} ) ;
23
139
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 : {
28
144
template : '<span></span>' ,
29
145
mounted ( ) {
30
- this . $DialogInstance . close ( )
146
+ this . $myDialog . close ( )
31
147
}
32
148
} ,
33
149
onClose ( ) {
@@ -38,18 +154,22 @@ describe('Dialog相关', function () {
38
154
} ) ;
39
155
40
156
it ( '关闭onBeforeClose' , async function ( ) {
157
+ let result = false
41
158
await new Promise ( ( resolve , reject ) => {
42
- vueInstance . $Dialog . open ( {
43
- component : {
159
+ vueInstance . $MyDialog . open ( {
160
+ content : {
44
161
template : '<span></span>' ,
45
162
mounted ( ) {
46
- this . $DialogInstance . close ( true )
163
+ this . $myDialog . close ( true )
47
164
}
48
165
} ,
49
- onBeforeClose ( resulte ) {
50
- if ( resulte )
166
+ onBeforeClose ( _result ) {
167
+ result = _result
168
+ } ,
169
+ onClose ( ) {
170
+ if ( result )
51
171
resolve ( )
52
- }
172
+ } ,
53
173
} )
54
174
} )
55
175
} ) ;
@@ -60,17 +180,17 @@ describe('Dialog相关', function () {
60
180
resolve ( )
61
181
} , 1000 )
62
182
63
- vueInstance . $Dialog . open ( {
64
- component : {
183
+ vueInstance . $MyDialog . open ( {
184
+ content : {
65
185
template : '<span></span>' ,
66
186
mounted ( ) {
67
- this . $DialogInstance . close ( )
187
+ this . $myDialog . close ( )
68
188
}
69
189
} ,
70
- onBeforeClose ( resulte ) {
190
+ onBeforeClose ( ) {
71
191
return false
72
192
} ,
73
- onClose ( resulte ) {
193
+ onClose ( ) {
74
194
//如果真的不关闭了,这里会先返回错误
75
195
reject ( 'beforeClose失效' )
76
196
} ,
@@ -80,13 +200,13 @@ describe('Dialog相关', function () {
80
200
81
201
it ( '关闭onBeforeShow' , async function ( ) {
82
202
let title = await new Promise ( ( resolve , reject ) => {
83
- vueInstance . $Dialog . open ( {
203
+ vueInstance . $MyDialog . open ( {
84
204
title : 'test' ,
85
- component : {
205
+ content : {
86
206
template : '<span></span>' ,
87
207
} ,
88
- onBeforeShow ( option ) {
89
- resolve ( option . title )
208
+ onBeforeShow ( ) {
209
+ resolve ( this . getTitle ( ) )
90
210
} ,
91
211
} )
92
212
} )
@@ -100,10 +220,10 @@ describe('Dialog相关', function () {
100
220
resolve ( )
101
221
} , 1000 )
102
222
103
- vueInstance . $Dialog . open ( {
104
- component : {
223
+ vueInstance . $MyDialog . open ( {
224
+ content : {
105
225
template : '<span></span>' ,
106
- destroyed ( ) {
226
+ mounted ( ) {
107
227
reject ( 'beforeShow失效' )
108
228
} ,
109
229
} ,
0 commit comments