@@ -254,6 +254,234 @@ test.serial("generateThemeDesignerResources: Library sap.ui.core", async (t) =>
254254 "workspace.write should be called with libraryLessResource" ) ;
255255} ) ;
256256
257+ test . serial ( "generateThemeDesignerResources: Library sap.ui.core with existing library .theming" , async ( t ) => {
258+ const { sinon, generateThemeDesignerResources, libraryLessGeneratorStub, fsInterfaceStub, ResourceStub} = t . context ;
259+
260+ const librarySourceLessResource = {
261+ getPath : sinon . stub ( ) . returns ( "/resources/sap/ui/core/themes/base/library.source.less" )
262+ } ;
263+
264+ const coreLibraryDotThemingResource = {
265+ getString : async ( ) => JSON . stringify ( {
266+ sEntity : "Library" ,
267+ sId : "sap/ui/core" ,
268+ aFiles : [
269+ "existing" , "entries"
270+ ]
271+ } , null , 2 ) ,
272+ setString : sinon . stub ( )
273+ } ;
274+
275+ const workspace = {
276+ byGlob : sinon . stub ( ) . callsFake ( async ( globPattern ) => {
277+ if ( globPattern === "/resources/sap/ui/core/themes/*/library.source.less" ) {
278+ return [ librarySourceLessResource ] ;
279+ } else {
280+ return [ ] ;
281+ }
282+ } ) ,
283+ byPath : sinon . stub ( ) . callsFake ( async ( virPath ) => {
284+ if ( virPath === "/resources/sap/ui/core/themes/base/.theming" ) {
285+ return { } ;
286+ } else if ( virPath === "/resources/sap/ui/core/.theming" ) {
287+ return coreLibraryDotThemingResource ;
288+ } else {
289+ return null ;
290+ }
291+ } ) ,
292+ write : sinon . stub ( )
293+ } ;
294+ const dependencies = { } ;
295+
296+ const libraryLessResource = { } ;
297+
298+ libraryLessGeneratorStub . resolves ( [ libraryLessResource ] ) ;
299+
300+ await generateThemeDesignerResources ( {
301+ workspace,
302+ dependencies,
303+ options : {
304+ projectName : "sap.ui.core" ,
305+ version : "1.2.3" ,
306+ namespace : "sap/ui/core"
307+ }
308+ } ) ;
309+
310+ t . is ( t . context . ReaderCollectionPrioritizedStub . callCount , 1 , "ReaderCollectionPrioritized should be created once" ) ;
311+ t . deepEqual ( t . context . ReaderCollectionPrioritizedStub . getCall ( 0 ) . args , [ {
312+ name : `generateThemeDesignerResources - prioritize workspace over dependencies: sap.ui.core` ,
313+ readers : [ workspace , dependencies ]
314+ } ] ) ;
315+ const combo = t . context . ReaderCollectionPrioritizedStub . getCall ( 0 ) . returnValue ;
316+
317+ t . is ( fsInterfaceStub . callCount , 1 , "fsInterface should be created once" ) ;
318+ t . deepEqual ( fsInterfaceStub . getCall ( 0 ) . args , [ combo ] , "fsInterface should be created for 'combo'" ) ;
319+ const fs = fsInterfaceStub . getCall ( 0 ) . returnValue ;
320+
321+ t . is ( libraryLessGeneratorStub . callCount , 1 ) ;
322+
323+ t . deepEqual ( libraryLessGeneratorStub . getCall ( 0 ) . args [ 0 ] , {
324+ resources : [ librarySourceLessResource ] ,
325+ fs,
326+ } , "libraryLessGenerator processor should be called with expected arguments" ) ;
327+
328+ t . is ( ResourceStub . callCount , 0 , "No new resource should be created" ) ;
329+
330+ t . is ( coreLibraryDotThemingResource . setString . callCount , 1 ) ;
331+ t . deepEqual ( coreLibraryDotThemingResource . setString . getCall ( 0 ) . args , [
332+ JSON . stringify ( {
333+ sEntity : "Library" ,
334+ sId : "sap/ui/core" ,
335+ aFiles : [
336+ "existing" , "entries"
337+ ] ,
338+ sVersion : "1.2.3" ,
339+ } , null , 2 )
340+ ] ) ;
341+
342+ t . is ( workspace . write . callCount , 2 ) ;
343+ t . is ( workspace . write . getCall ( 0 ) . args . length , 1 ,
344+ "workspace.write for coreLibraryDotThemingResource should be called with 1 argument" ) ;
345+ t . is ( workspace . write . getCall ( 0 ) . args [ 0 ] , coreLibraryDotThemingResource ,
346+ "workspace.write should be called with libraryDotTheming" ) ;
347+ t . is ( workspace . write . getCall ( 1 ) . args . length , 1 ,
348+ "workspace.write for libraryLessResource should be called with 1 argument" ) ;
349+ t . is ( workspace . write . getCall ( 1 ) . args [ 0 ] , libraryLessResource ,
350+ "workspace.write should be called with libraryLessResource" ) ;
351+ } ) ;
352+
353+ test . serial ( "generateThemeDesignerResources: Library sap.ui.core without themes, " +
354+ "with existing library .theming with version" , async ( t ) => {
355+ // NOTE: This tests the case when sap.ui.core has no themes, which is not a likely scenario.
356+ // But as the underlying functionality might be used in other scenarios in future, it is tested here.
357+
358+ const { sinon, generateThemeDesignerResources, libraryLessGeneratorStub, fsInterfaceStub, ResourceStub} = t . context ;
359+
360+ const coreLibraryDotThemingResource = {
361+ getString : async ( ) => JSON . stringify ( {
362+ sEntity : "Library" ,
363+ sId : "sap/ui/core" ,
364+ sVersion : "0.0.0" , // existing version should be ignored
365+ aFiles : [
366+ "existing" , "entries"
367+ ]
368+ } , null , 2 ) ,
369+ setString : sinon . stub ( )
370+ } ;
371+
372+ const workspace = {
373+ byGlob : sinon . stub ( ) . callsFake ( async ( globPattern ) => {
374+ return [ ] ;
375+ } ) ,
376+ byPath : sinon . stub ( ) . callsFake ( async ( virPath ) => {
377+ if ( virPath === "/resources/sap/ui/core/.theming" ) {
378+ return coreLibraryDotThemingResource ;
379+ } else {
380+ return null ;
381+ }
382+ } ) ,
383+ write : sinon . stub ( )
384+ } ;
385+ const dependencies = { } ;
386+
387+ const libraryLessResource = { } ;
388+
389+ libraryLessGeneratorStub . resolves ( [ libraryLessResource ] ) ;
390+
391+ await generateThemeDesignerResources ( {
392+ workspace,
393+ dependencies,
394+ options : {
395+ projectName : "sap.ui.core" ,
396+ version : "1.2.3" ,
397+ namespace : "sap/ui/core"
398+ }
399+ } ) ;
400+
401+ t . is ( t . context . ReaderCollectionPrioritizedStub . callCount , 0 , "ReaderCollectionPrioritized should not be created" ) ;
402+
403+ t . is ( fsInterfaceStub . callCount , 0 , "fsInterface should not be created" ) ;
404+
405+ t . is ( libraryLessGeneratorStub . callCount , 0 ) ;
406+
407+ t . is ( ResourceStub . callCount , 0 , "No new resource should be created" ) ;
408+
409+ t . is ( coreLibraryDotThemingResource . setString . callCount , 1 ) ;
410+ t . deepEqual ( coreLibraryDotThemingResource . setString . getCall ( 0 ) . args , [
411+ JSON . stringify ( {
412+ sEntity : "Library" ,
413+ sId : "sap/ui/core" ,
414+ sVersion : "1.2.3" ,
415+ aFiles : [
416+ "existing" , "entries"
417+ ] ,
418+ bIgnore : true
419+ } , null , 2 )
420+ ] ) ;
421+
422+ t . is ( workspace . write . callCount , 1 ) ;
423+ t . is ( workspace . write . getCall ( 0 ) . args . length , 1 ,
424+ "workspace.write for coreLibraryDotThemingResource should be called with 1 argument" ) ;
425+ t . is ( workspace . write . getCall ( 0 ) . args [ 0 ] , coreLibraryDotThemingResource ,
426+ "workspace.write should be called with libraryDotTheming" ) ;
427+ } ) ;
428+
429+ test . serial ( "generateThemeDesignerResources: Library sap.ui.core with existing invalid library .theming" , async ( t ) => {
430+ const { sinon, generateThemeDesignerResources, libraryLessGeneratorStub, fsInterfaceStub, ResourceStub} = t . context ;
431+
432+ const coreLibraryDotThemingResource = {
433+ getPath : ( ) => "/resources/sap/ui/core/.theming" ,
434+ getString : async ( ) => JSON . stringify ( {
435+ sEntity : "Library" ,
436+ sId : "sap/m"
437+ } , null , 2 ) ,
438+ setString : sinon . stub ( )
439+ } ;
440+
441+ const workspace = {
442+ byGlob : sinon . stub ( ) . callsFake ( async ( globPattern ) => {
443+ return [ ] ;
444+ } ) ,
445+ byPath : sinon . stub ( ) . callsFake ( async ( virPath ) => {
446+ if ( virPath === "/resources/sap/ui/core/.theming" ) {
447+ return coreLibraryDotThemingResource ;
448+ } else {
449+ return null ;
450+ }
451+ } ) ,
452+ write : sinon . stub ( )
453+ } ;
454+ const dependencies = { } ;
455+
456+ const libraryLessResource = { } ;
457+
458+ libraryLessGeneratorStub . resolves ( [ libraryLessResource ] ) ;
459+
460+ await t . throwsAsync ( generateThemeDesignerResources ( {
461+ workspace,
462+ dependencies,
463+ options : {
464+ projectName : "sap.ui.core" ,
465+ version : "1.2.3" ,
466+ namespace : "sap/ui/core"
467+ }
468+ } ) , {
469+ message : "Incorrect 'sId' value 'sap/m' in /resources/sap/ui/core/.theming: Expected 'sap/ui/core'"
470+ } ) ;
471+
472+ t . is ( t . context . ReaderCollectionPrioritizedStub . callCount , 0 , "ReaderCollectionPrioritized should not be created" ) ;
473+
474+ t . is ( fsInterfaceStub . callCount , 0 , "fsInterface should not be created" ) ;
475+
476+ t . is ( libraryLessGeneratorStub . callCount , 0 ) ;
477+
478+ t . is ( ResourceStub . callCount , 0 , "No new resource should be created" ) ;
479+
480+ t . is ( coreLibraryDotThemingResource . setString . callCount , 0 ) ;
481+
482+ t . is ( workspace . write . callCount , 0 ) ;
483+ } ) ;
484+
257485test . serial ( "generateThemeDesignerResources: Library sap.ui.documentation is skipped" , async ( t ) => {
258486 const { sinon, generateThemeDesignerResources, libraryLessGeneratorStub, fsInterfaceStub, ResourceStub} = t . context ;
259487
0 commit comments