@@ -4,18 +4,27 @@ import { DOM } from 'aurelia-pal';
4
4
import { DialogConfiguration , Renderer } from '../../src/aurelia-dialog' ;
5
5
import { DefaultDialogSettings } from '../../src/dialog-settings' ;
6
6
import { DialogRenderer } from '../../src/dialog-renderer' ;
7
+ import UxDialog from '../../src/resources/ux-dialog' ;
7
8
8
- describe ( 'DialogConfiguration' , ( ) => {
9
+ fdescribe ( 'DialogConfiguration' , ( ) => {
9
10
const frameworkConfig : FrameworkConfiguration = {
10
11
container : new Container ( ) ,
11
12
globalResources : ( ) => { return ; } ,
12
13
transient : ( ) => { return ; }
13
14
} as any ;
14
15
let configuration : DialogConfiguration ;
15
- let applyConfig : ( ) => void ;
16
+ let applyConfig : ( ) => Promise < void > ;
16
17
const applySetterSpy = jasmine . createSpy ( 'applySetter' )
17
18
. and
18
- . callFake ( ( apply : ( ) => void ) => { applyConfig = apply ; } ) ;
19
+ . callFake ( ( apply : ( ) => Promise < void > ) => { applyConfig = apply ; } ) ;
20
+
21
+ async function whenConfigured ( configuration : ( ) => ( void | Promise < void > ) , done : DoneFn ) : Promise < void > {
22
+ try {
23
+ await configuration ( ) ;
24
+ } catch ( e ) {
25
+ done . fail ( e ) ;
26
+ }
27
+ }
19
28
20
29
beforeEach ( ( ) => {
21
30
frameworkConfig . container . unregister ( DefaultDialogSettings ) ;
@@ -32,101 +41,106 @@ describe('DialogConfiguration', () => {
32
41
} ) ;
33
42
34
43
describe ( 'even when ".useDefaults" is not called' , ( ) => {
35
- it ( 'a default Renderer should be registered' , ( ) => {
36
- let applyConfig : ( ) => void = null as any ;
44
+ it ( 'a default Renderer should be registered' , async done => {
45
+ let applyConfig : ( ) => void | Promise < void > = null as any ;
37
46
// tslint:disable-next-line:no-unused-expression
38
47
new DialogConfiguration ( frameworkConfig , apply => { applyConfig = apply ; } ) ;
39
48
spyOn ( frameworkConfig , 'transient' ) ;
40
- applyConfig ( ) ;
49
+ await whenConfigured ( applyConfig , done ) ;
41
50
expect ( frameworkConfig . transient ) . toHaveBeenCalledWith ( Renderer , DialogRenderer ) ;
51
+ done ( ) ;
42
52
} ) ;
43
53
44
- it ( 'the default css styles should be applied' , ( ) => {
45
- let applyConfig : ( ) => void = null as any ;
54
+ it ( 'the default css styles should be applied' , async done => {
55
+ let applyConfig : ( ) => void | Promise < void > = null as any ;
46
56
// tslint:disable-next-line:no-unused-expression
47
57
new DialogConfiguration ( frameworkConfig , apply => { applyConfig = apply ; } ) ;
48
58
spyOn ( DOM , 'injectStyles' ) ;
49
- applyConfig ( ) ;
59
+ await whenConfigured ( applyConfig , done ) ;
50
60
expect ( DOM . injectStyles ) . toHaveBeenCalledWith ( jasmine . any ( String ) ) ;
61
+ done ( ) ;
51
62
} ) ;
52
63
} ) ;
53
64
54
65
describe ( 'useRenderer' , ( ) => {
55
- it ( 'should register a renderer as a transient' , ( ) => {
66
+ it ( 'should register a renderer as a transient' , async done => {
56
67
const renderer = { } as any ;
57
68
spyOn ( frameworkConfig , 'transient' ) ;
58
69
configuration . useRenderer ( renderer ) ;
59
- applyConfig ( ) ;
70
+ await whenConfigured ( applyConfig , done ) ;
60
71
expect ( frameworkConfig . transient ) . toHaveBeenCalledWith ( Renderer , renderer ) ;
72
+ done ( ) ;
61
73
} ) ;
62
74
63
- it ( 'should export settings' , ( ) => {
75
+ it ( 'should export settings' , async done => {
64
76
const first = 'first' ;
65
77
const second = 'second' ;
66
78
configuration . useRenderer ( { } as any , { first, second } ) ;
67
- applyConfig ( ) ;
79
+ await whenConfigured ( applyConfig , done ) ;
68
80
expect ( configuration . settings [ first ] ) . toBe ( first ) ;
69
81
expect ( configuration . settings [ second ] ) . toBe ( second ) ;
82
+ done ( ) ;
70
83
} ) ;
71
84
} ) ;
72
85
73
86
describe ( 'useResource' , ( ) => {
74
- it ( 'should call globalResources' , ( ) => {
87
+ it ( 'should call globalResources' , async done => {
75
88
spyOn ( frameworkConfig , 'globalResources' ) ;
76
89
configuration . useResource ( 'ux-dialog' ) ;
77
- applyConfig ( ) ;
78
- expect ( frameworkConfig . globalResources ) . toHaveBeenCalled ( ) ;
90
+ await whenConfigured ( applyConfig , done ) ;
91
+ expect ( frameworkConfig . globalResources ) . toHaveBeenCalledWith ( jasmine . arrayContaining ( [ UxDialog ] ) ) ;
92
+ done ( ) ;
79
93
} ) ;
80
94
} ) ;
81
95
82
96
describe ( 'useDefaults' , ( ) => {
83
- it ( 'should call useRenderer with the default renderer' , ( ) => {
97
+ it ( 'should call useRenderer with the default renderer' , async done => {
84
98
spyOn ( configuration , 'useRenderer' ) . and . callThrough ( ) ;
85
99
spyOn ( configuration , 'useResource' ) . and . callThrough ( ) ;
86
-
87
100
configuration . useDefaults ( ) ;
88
- applyConfig ( ) ;
101
+ await whenConfigured ( applyConfig , done ) ;
89
102
expect ( configuration . useRenderer ) . toHaveBeenCalledWith ( DialogRenderer ) ;
90
103
expect ( configuration . useResource ) . toHaveBeenCalledWith ( 'ux-dialog' ) ;
91
104
expect ( configuration . useResource ) . toHaveBeenCalledWith ( 'ux-dialog-header' ) ;
92
105
expect ( configuration . useResource ) . toHaveBeenCalledWith ( 'ux-dialog-footer' ) ;
93
106
expect ( configuration . useResource ) . toHaveBeenCalledWith ( 'ux-dialog-body' ) ;
94
107
expect ( configuration . useResource ) . toHaveBeenCalledWith ( 'attach-focus' ) ;
108
+ done ( ) ;
95
109
} ) ;
96
110
97
- it ( 'should inject default style' , ( ) => {
111
+ it ( 'should inject default style' , async done => {
98
112
spyOn ( DOM , 'injectStyles' ) . and . callThrough ( ) ;
99
-
100
113
configuration . useDefaults ( ) ;
101
- applyConfig ( ) ;
114
+ await whenConfigured ( applyConfig , done ) ;
102
115
expect ( ( DOM . injectStyles as jasmine . Spy ) . calls . any ( ) ) . toEqual ( true ) ;
116
+ done ( ) ;
103
117
} ) ;
104
118
} ) ;
105
119
106
120
describe ( 'useCSS' , ( ) => {
107
121
describe ( 'should skip injecting' , ( ) => {
108
- it ( 'undefined css' , ( ) => {
122
+ it ( 'undefined css' , async done => {
109
123
spyOn ( DOM , 'injectStyles' ) . and . callThrough ( ) ;
110
-
111
124
configuration . useCSS ( undefined as any ) ;
112
- applyConfig ( ) ;
125
+ await whenConfigured ( applyConfig , done ) ;
113
126
expect ( ( DOM . injectStyles as jasmine . Spy ) . calls . any ( ) ) . toEqual ( false ) ;
127
+ done ( ) ;
114
128
} ) ;
115
129
116
- it ( 'null css' , ( ) => {
130
+ it ( 'null css' , async done => {
117
131
spyOn ( DOM , 'injectStyles' ) . and . callThrough ( ) ;
118
-
119
132
configuration . useCSS ( null as any ) ;
120
- applyConfig ( ) ;
133
+ await whenConfigured ( applyConfig , done ) ;
121
134
expect ( ( DOM . injectStyles as jasmine . Spy ) . calls . any ( ) ) . toEqual ( false ) ;
135
+ done ( ) ;
122
136
} ) ;
123
137
124
- it ( 'empty string' , ( ) => {
138
+ it ( 'empty string' , async done => {
125
139
spyOn ( DOM , 'injectStyles' ) . and . callThrough ( ) ;
126
-
127
140
configuration . useCSS ( '' ) ;
128
- applyConfig ( ) ;
141
+ await whenConfigured ( applyConfig , done ) ;
129
142
expect ( ( DOM . injectStyles as jasmine . Spy ) . calls . any ( ) ) . toEqual ( false ) ;
143
+ done ( ) ;
130
144
} ) ;
131
145
} ) ;
132
146
} ) ;
0 commit comments