@@ -52,6 +52,131 @@ describe('ng add', () => {
5252 ) ;
5353 } ) ;
5454 } ) ;
55+
56+ describe ( 'Folder Detection' , ( ) => {
57+ it ( 'should use public/i18n for Angular 18+ projects with public folder' , async ( ) => {
58+ const options : SchemaOptions = { project : 'bar' } as SchemaOptions ;
59+ const initialTree = await createWorkspace ( schematicRunner ) ;
60+
61+ // Create public folder to simulate Angular 18+
62+ initialTree . create ( '/public/favicon.ico' , '' ) ;
63+
64+ const tree = await schematicRunner . runSchematic (
65+ 'ng-add' ,
66+ options ,
67+ initialTree ,
68+ ) ;
69+
70+ expect ( tree . files ) . toContain ( '/public/i18n/en.json' ) ;
71+ expect ( tree . files ) . toContain ( '/public/i18n/es.json' ) ;
72+
73+ // Check that loader uses correct URL path
74+ const loaderContent = readFile ( tree , 'app/transloco-loader.ts' ) ;
75+ expect ( loaderContent ) . toContain ( '/i18n/${lang}.json' ) ;
76+ expect ( loaderContent ) . not . toContain ( '/assets/i18n/' ) ;
77+ } ) ;
78+
79+ it ( 'should use src/assets/i18n for projects with assets folder' , async ( ) => {
80+ const options : SchemaOptions = { project : 'bar' } as SchemaOptions ;
81+ const initialTree = await createWorkspace ( schematicRunner ) ;
82+
83+ // Create assets folder to simulate traditional Angular structure
84+ initialTree . create ( '/projects/bar/src/assets/icons/icon.png' , '' ) ;
85+
86+ const tree = await schematicRunner . runSchematic (
87+ 'ng-add' ,
88+ options ,
89+ initialTree ,
90+ ) ;
91+
92+ expect ( tree . files ) . toContain ( '/projects/bar/src/assets/i18n/en.json' ) ;
93+ expect ( tree . files ) . toContain ( '/projects/bar/src/assets/i18n/es.json' ) ;
94+
95+ // Check that loader uses correct URL path
96+ const loaderContent = readFile ( tree , 'app/transloco-loader.ts' ) ;
97+ expect ( loaderContent ) . toContain ( '/assets/i18n/${lang}.json' ) ;
98+ } ) ;
99+
100+ it ( 'should respect custom path when specified' , async ( ) => {
101+ const options : SchemaOptions = {
102+ project : 'bar' ,
103+ path : 'custom/translations/' ,
104+ } as SchemaOptions ;
105+
106+ const tree = await schematicRunner . runSchematic (
107+ 'ng-add' ,
108+ options ,
109+ await createWorkspace ( schematicRunner ) ,
110+ ) ;
111+
112+ expect ( tree . files ) . toContain (
113+ '/projects/bar/src/custom/translations/en.json' ,
114+ ) ;
115+ expect ( tree . files ) . toContain (
116+ '/projects/bar/src/custom/translations/es.json' ,
117+ ) ;
118+
119+ // Check that loader uses correct URL path
120+ const loaderContent = readFile ( tree , 'app/transloco-loader.ts' ) ;
121+ expect ( loaderContent ) . toContain ( '/custom/translations/${lang}.json' ) ;
122+ } ) ;
123+
124+ it ( 'should fallback to package.json version detection when folders are ambiguous' , async ( ) => {
125+ const options : SchemaOptions = { project : 'bar' } as SchemaOptions ;
126+ const initialTree = await createWorkspace ( schematicRunner ) ;
127+
128+ // Simulate Angular 18+ by updating package.json
129+ const packageJson = JSON . parse (
130+ initialTree . read ( '/package.json' ) ! . toString ( ) ,
131+ ) ;
132+ packageJson . dependencies [ '@angular/core' ] = '^18.0.0' ;
133+ initialTree . overwrite (
134+ '/package.json' ,
135+ JSON . stringify ( packageJson , null , 2 ) ,
136+ ) ;
137+
138+ const tree = await schematicRunner . runSchematic (
139+ 'ng-add' ,
140+ options ,
141+ initialTree ,
142+ ) ;
143+
144+ expect ( tree . files ) . toContain ( '/public/i18n/en.json' ) ;
145+ expect ( tree . files ) . toContain ( '/public/i18n/es.json' ) ;
146+
147+ // Check that loader uses correct URL path for Angular 18+
148+ const loaderContent = readFile ( tree , 'app/transloco-loader.ts' ) ;
149+ expect ( loaderContent ) . toContain ( '/i18n/${lang}.json' ) ;
150+ } ) ;
151+
152+ it ( 'should fallback to assets for Angular <18 when package.json indicates older version' , async ( ) => {
153+ const options : SchemaOptions = { project : 'bar' } as SchemaOptions ;
154+ const initialTree = await createWorkspace ( schematicRunner ) ;
155+
156+ // Simulate Angular 17 by updating package.json
157+ const packageJson = JSON . parse (
158+ initialTree . read ( '/package.json' ) ! . toString ( ) ,
159+ ) ;
160+ packageJson . dependencies [ '@angular/core' ] = '^17.0.0' ;
161+ initialTree . overwrite (
162+ '/package.json' ,
163+ JSON . stringify ( packageJson , null , 2 ) ,
164+ ) ;
165+
166+ const tree = await schematicRunner . runSchematic (
167+ 'ng-add' ,
168+ options ,
169+ initialTree ,
170+ ) ;
171+
172+ expect ( tree . files ) . toContain ( '/projects/bar/src/assets/i18n/en.json' ) ;
173+ expect ( tree . files ) . toContain ( '/projects/bar/src/assets/i18n/es.json' ) ;
174+
175+ // Check that loader uses correct URL path for Angular <18
176+ const loaderContent = readFile ( tree , 'app/transloco-loader.ts' ) ;
177+ expect ( loaderContent ) . toContain ( '/assets/i18n/${lang}.json' ) ;
178+ } ) ;
179+ } ) ;
55180} ) ;
56181
57182function readFile ( host : UnitTestTree , path : string ) {
0 commit comments