@@ -40,6 +40,25 @@ const simpleContentType = {
4040 ]
4141}
4242
43+ const contentTypeWithUndefined = {
44+ sys : {
45+ id : 'bar'
46+ } ,
47+ name : 'Bar' ,
48+ description : undefined ,
49+ displayField : undefined ,
50+ fields : [
51+ {
52+ id : 'title' ,
53+ name : 'Title' ,
54+ type : 'Symbol' ,
55+ required : undefined ,
56+ localized : undefined ,
57+ disabled : false
58+ }
59+ ]
60+ }
61+
4362const editorInterface = {
4463 controls : [
4564 {
@@ -53,6 +72,38 @@ const editorInterface = {
5372 ]
5473}
5574
75+ const editorInterfaceWithUndefined = {
76+ controls : [
77+ {
78+ fieldId : 'title' ,
79+ widgetId : 'singleLine' ,
80+ widgetNamespace : 'builtin' ,
81+ settings : {
82+ helpText : undefined ,
83+ placeholder : 'Enter title' ,
84+ showLinkEntityAction : undefined
85+ }
86+ }
87+ ]
88+ }
89+
90+ const editorInterfaceWithMissingProperties = {
91+ controls : [
92+ {
93+ fieldId : 'title' ,
94+ widgetId : 'singleLine' ,
95+ widgetNamespace : 'builtin' ,
96+ settings : {
97+ helpText : 'Valid title'
98+ }
99+ } ,
100+ {
101+ fieldId : 'description'
102+ // Missing widgetId and widgetNamespace
103+ }
104+ ]
105+ }
106+
56107const EditorInterfaceNotFoundErrorMock = function ( ) {
57108 this . name = 'NotFound'
58109}
@@ -173,6 +224,79 @@ test('it creates the editor interface', async () => {
173224 )
174225} )
175226
227+ test ( 'it handles undefined values in content type' , async ( ) => {
228+ const programStub = b . blockStatement ( [ createContentType ( contentTypeWithUndefined ) ] )
229+
230+ const expected = `module.exports = function(migration) {
231+ const bar = migration.createContentType("bar").name("Bar");
232+ };`
233+
234+ expect ( recast . prettyPrint ( wrapMigrationWithBase ( programStub ) ) . code ) . toBe (
235+ expected
236+ )
237+ } )
238+
239+ test ( 'it handles undefined values in field properties' , async ( ) => {
240+ const programStub = b . blockStatement ( [
241+ b . expressionStatement (
242+ createField ( contentTypeWithUndefined . sys . id , contentTypeWithUndefined . fields [ 0 ] )
243+ )
244+ ] )
245+
246+ const expected = `module.exports = function(migration) {
247+ bar.createField("title").name("Title").type("Symbol").disabled(false);
248+ };`
249+
250+ expect ( recast . prettyPrint ( wrapMigrationWithBase ( programStub ) ) . code ) . toBe (
251+ expected
252+ )
253+ } )
254+
255+ test ( 'it handles undefined values in editor interface settings' , async ( ) => {
256+ const programStub = b . blockStatement ( [
257+ b . expressionStatement (
258+ changeFieldControl (
259+ 'bar' ,
260+ editorInterfaceWithUndefined . controls [ 0 ] . fieldId ,
261+ editorInterfaceWithUndefined . controls [ 0 ] . widgetNamespace ,
262+ editorInterfaceWithUndefined . controls [ 0 ] . widgetId ,
263+ editorInterfaceWithUndefined . controls [ 0 ] . settings
264+ )
265+ )
266+ ] )
267+
268+ const expected = `module.exports = function(migration) {
269+ bar.changeFieldControl("title", "builtin", "singleLine", {
270+ placeholder: "Enter title"
271+ });
272+ };`
273+
274+ expect ( recast . prettyPrint ( wrapMigrationWithBase ( programStub ) ) . code ) . toBe (
275+ expected
276+ )
277+ } )
278+
279+ test ( 'it skips changeFieldControl when required parameters are undefined' , async ( ) => {
280+ const validControl = changeFieldControl (
281+ 'bar' ,
282+ editorInterfaceWithMissingProperties . controls [ 0 ] . fieldId ,
283+ editorInterfaceWithMissingProperties . controls [ 0 ] . widgetNamespace ,
284+ editorInterfaceWithMissingProperties . controls [ 0 ] . widgetId ,
285+ editorInterfaceWithMissingProperties . controls [ 0 ] . settings
286+ )
287+
288+ const invalidControl = changeFieldControl (
289+ 'bar' ,
290+ editorInterfaceWithMissingProperties . controls [ 1 ] . fieldId ,
291+ editorInterfaceWithMissingProperties . controls [ 1 ] . widgetNamespace ,
292+ editorInterfaceWithMissingProperties . controls [ 1 ] . widgetId ,
293+ editorInterfaceWithMissingProperties . controls [ 1 ] . settings
294+ )
295+
296+ expect ( validControl ) . not . toBeNull ( )
297+ expect ( invalidControl ) . toBeNull ( )
298+ } )
299+
176300test ( 'it creates the full migration script' , async ( ) => {
177301 const expected = `module.exports = function (migration) {
178302 const foo = migration
0 commit comments