@@ -46,7 +46,7 @@ const overrides = {
46
46
overrideBaz : 'baz' ,
47
47
} ;
48
48
49
- const defaults = {
49
+ const defaults : Record < string , any > = {
50
50
foo : {
51
51
name : 'foo' ,
52
52
value : 'bar' ,
@@ -97,6 +97,21 @@ describe('uiSettings', () => {
97
97
) ;
98
98
} ) ;
99
99
} ) ;
100
+
101
+ it ( 'fails if configured default was not previously defined' , async ( ) => {
102
+ const coreContext = mockCoreContext . create ( ) ;
103
+ coreContext . configService . atPath . mockReturnValueOnce (
104
+ new BehaviorSubject ( {
105
+ defaults : {
106
+ foo : 'configured' ,
107
+ } ,
108
+ } )
109
+ ) ;
110
+ const customizedService = new UiSettingsService ( coreContext ) ;
111
+ await expect ( customizedService . setup ( setupDeps ) ) . rejects . toMatchInlineSnapshot (
112
+ `[Error: [ui settings defaults [foo]: expected key to be have been registered]`
113
+ ) ;
114
+ } ) ;
100
115
} ) ;
101
116
102
117
describe ( '#start' , ( ) => {
@@ -168,6 +183,31 @@ describe('uiSettings', () => {
168
183
expect ( MockUiSettingsClientConstructor . mock . calls [ 0 ] [ 0 ] . defaults ) . toEqual ( defaults ) ;
169
184
expect ( MockUiSettingsClientConstructor . mock . calls [ 0 ] [ 0 ] . defaults ) . not . toBe ( defaults ) ;
170
185
} ) ;
186
+
187
+ it ( 'passes configured defaults to UiSettingsClient' , async ( ) => {
188
+ const defaultsClone : Record < string , any > = { } ;
189
+ Object . keys ( defaults ) . forEach ( ( key : string ) => {
190
+ defaultsClone [ key ] = { ...defaults [ key ] } ;
191
+ } ) ;
192
+
193
+ getCoreSettingsMock . mockReturnValue ( defaultsClone ) ;
194
+ const coreContext = mockCoreContext . create ( ) ;
195
+ coreContext . configService . atPath . mockReturnValueOnce (
196
+ new BehaviorSubject ( {
197
+ defaults : {
198
+ foo : 'configured' ,
199
+ } ,
200
+ } )
201
+ ) ;
202
+ const customizedService = new UiSettingsService ( coreContext ) ;
203
+ await customizedService . setup ( setupDeps ) ;
204
+ const start = await customizedService . start ( ) ;
205
+ start . asScopedToClient ( savedObjectsClient ) ;
206
+ expect ( MockUiSettingsClientConstructor ) . toBeCalledTimes ( 1 ) ;
207
+ expect ( MockUiSettingsClientConstructor . mock . calls [ 0 ] [ 0 ] . defaults ?. foo ?. value ) . toEqual (
208
+ 'configured'
209
+ ) ;
210
+ } ) ;
171
211
} ) ;
172
212
} ) ;
173
213
} ) ;
0 commit comments