@@ -146,6 +146,114 @@ describe('ContentElementTypeRegistry', () => {
146146 } ) ;
147147 } ) ;
148148
149+ describe ( '#getDefaultsInputsMapping' , ( ) => {
150+ it ( 'returns empty object for type without defaultsInputs' , ( ) => {
151+ const registry = new ContentElementTypeRegistry ( { features : new Features ( ) } ) ;
152+ registry . register ( 'textBlock' , { } ) ;
153+
154+ const mapping = registry . getDefaultsInputsMapping ( 'textBlock' ) ;
155+
156+ expect ( mapping ) . toEqual ( { } ) ;
157+ } ) ;
158+
159+ it ( 'returns mapping from metadata keys to property names' , ( ) => {
160+ const registry = new ContentElementTypeRegistry ( { features : new Features ( ) } ) ;
161+ registry . register ( 'inlineImage' , {
162+ defaultsInputs ( ) {
163+ this . input ( 'enableFullscreen' ) ;
164+ this . input ( 'autoplay' ) ;
165+ }
166+ } ) ;
167+
168+ const mapping = registry . getDefaultsInputsMapping ( 'inlineImage' ) ;
169+
170+ expect ( mapping ) . toEqual ( {
171+ 'default-inlineImage-enableFullscreen' : 'enableFullscreen' ,
172+ 'default-inlineImage-autoplay' : 'autoplay'
173+ } ) ;
174+ } ) ;
175+ } ) ;
176+
177+ describe ( '#createDefaultsInputContext' , ( ) => {
178+ it ( 'prefixes property names passed to input' , ( ) => {
179+ const registry = new ContentElementTypeRegistry ( { features : new Features ( ) } ) ;
180+ const tabView = {
181+ input : jest . fn ( ) ,
182+ view : jest . fn ( )
183+ } ;
184+
185+ const context = registry . createDefaultsInputContext ( tabView , 'inlineImage' ) ;
186+ context . input ( 'enableFullscreen' , 'CheckBoxInputView' , { some : 'option' } ) ;
187+
188+ expect ( tabView . input ) . toHaveBeenCalledWith (
189+ 'default-inlineImage-enableFullscreen' ,
190+ 'CheckBoxInputView' ,
191+ expect . objectContaining ( { some : 'option' } )
192+ ) ;
193+ } ) ;
194+
195+ it ( 'adds attributeTranslationKeyPrefixes with fallback to normal attributes' , ( ) => {
196+ const registry = new ContentElementTypeRegistry ( { features : new Features ( ) } ) ;
197+ const tabView = {
198+ input : jest . fn ( ) ,
199+ view : jest . fn ( )
200+ } ;
201+
202+ const context = registry . createDefaultsInputContext ( tabView , 'inlineImage' ) ;
203+ context . input ( 'enableFullscreen' , 'CheckBoxInputView' ) ;
204+
205+ expect ( tabView . input ) . toHaveBeenCalledWith (
206+ expect . anything ( ) ,
207+ expect . anything ( ) ,
208+ expect . objectContaining ( {
209+ attributeTranslationKeyPrefixes : [
210+ 'pageflow_scrolled.editor.content_elements.inlineImage.defaults.attributes' ,
211+ 'pageflow_scrolled.editor.content_elements.inlineImage.attributes'
212+ ] ,
213+ attributeTranslationPropertyName : 'enableFullscreen'
214+ } )
215+ ) ;
216+ } ) ;
217+
218+ it ( 'preserves existing attributeTranslationKeyPrefixes' , ( ) => {
219+ const registry = new ContentElementTypeRegistry ( { features : new Features ( ) } ) ;
220+ const tabView = {
221+ input : jest . fn ( ) ,
222+ view : jest . fn ( )
223+ } ;
224+
225+ const context = registry . createDefaultsInputContext ( tabView , 'inlineImage' ) ;
226+ context . input ( 'enableFullscreen' , 'CheckBoxInputView' , {
227+ attributeTranslationKeyPrefixes : [ 'custom.prefix' ]
228+ } ) ;
229+
230+ expect ( tabView . input ) . toHaveBeenCalledWith (
231+ expect . anything ( ) ,
232+ expect . anything ( ) ,
233+ expect . objectContaining ( {
234+ attributeTranslationKeyPrefixes : [
235+ 'pageflow_scrolled.editor.content_elements.inlineImage.defaults.attributes' ,
236+ 'pageflow_scrolled.editor.content_elements.inlineImage.attributes' ,
237+ 'custom.prefix'
238+ ]
239+ } )
240+ ) ;
241+ } ) ;
242+
243+ it ( 'passes through view calls' , ( ) => {
244+ const registry = new ContentElementTypeRegistry ( { features : new Features ( ) } ) ;
245+ const tabView = {
246+ input : jest . fn ( ) ,
247+ view : jest . fn ( )
248+ } ;
249+
250+ const context = registry . createDefaultsInputContext ( tabView , 'inlineImage' ) ;
251+ context . view ( 'SomeView' , { some : 'option' } ) ;
252+
253+ expect ( tabView . view ) . toHaveBeenCalledWith ( 'SomeView' , { some : 'option' } ) ;
254+ } ) ;
255+ } ) ;
256+
149257 describe ( '#toArray' , ( ) => {
150258 it ( 'returns array of with options passed to register' , ( ) => {
151259 const registry = new ContentElementTypeRegistry ( { features : new Features ( ) } ) ;
0 commit comments