@@ -127,6 +127,92 @@ describe('NgAlainSchematic: application', () => {
127127 } ) ;
128128 } ) ;
129129
130+ describe ( '#tailwindcss' , ( ) => {
131+ describe ( 'with false' , ( ) => {
132+ beforeEach ( async ( ) => ( { tree } = await createAlainApp ( ) ) ) ;
133+ it ( `should not add tailwind related files` , ( ) => {
134+ expect ( tree . exists ( '.postcssrc.json' ) ) . toBe ( false ) ;
135+ expect ( tree . exists ( `/projects/${ APPNAME } /src/tailwind.css` ) ) . toBe ( false ) ;
136+ const angularJson = JSON . parse ( tree . readContent ( 'angular.json' ) ) ;
137+ const styles = angularJson . projects [ APPNAME ] . architect . build . options . styles ;
138+ expect ( styles . some ( ( s : string ) => s . includes ( 'tailwind.css' ) ) ) . toBe ( false ) ;
139+ const packageJson = JSON . parse ( tree . readContent ( 'package.json' ) ) ;
140+ expect ( packageJson . devDependencies [ 'tailwindcss' ] ) . toBeUndefined ( ) ;
141+ } ) ;
142+ } ) ;
143+ describe ( 'with true' , ( ) => {
144+ beforeEach ( async ( ) => {
145+ const baseRunner = createNgRunner ( ) ;
146+ const workspaceTree = await baseRunner . runSchematic ( 'workspace' , {
147+ name : 'workspace' ,
148+ newProjectRoot : 'projects' ,
149+ version : '6.0.0'
150+ } ) ;
151+ const appTree = await baseRunner . runSchematic (
152+ 'application' ,
153+ {
154+ name : APPNAME ,
155+ inlineStyle : false ,
156+ inlineTemplate : false ,
157+ routing : false ,
158+ style : 'css' ,
159+ skipTests : false ,
160+ skipPackageJson : false
161+ } ,
162+ workspaceTree
163+ ) ;
164+ const alainRunner = createAlainRunner ( ) ;
165+ tree = await alainRunner . runSchematic (
166+ 'ng-add' ,
167+ {
168+ skipPackageJson : false ,
169+ tailwindcss : true
170+ } ,
171+ appTree
172+ ) ;
173+ } ) ;
174+
175+ it ( `should add tailwindcss as devDependencies` , ( ) => {
176+ const packageJson = JSON . parse ( tree . readContent ( 'package.json' ) ) ;
177+ expect ( packageJson . devDependencies [ 'tailwindcss' ] ) . toBeDefined ( ) ;
178+ expect ( packageJson . devDependencies [ '@tailwindcss/postcss' ] ) . toBeDefined ( ) ;
179+ expect ( packageJson . devDependencies [ 'postcss' ] ) . toBeDefined ( ) ;
180+ } ) ;
181+
182+ it ( `should generate .postcssrc.json` , ( ) => {
183+ expect ( tree . exists ( '.postcssrc.json' ) ) . toBe ( true ) ;
184+ const postcssrc = JSON . parse ( tree . readContent ( '.postcssrc.json' ) ) ;
185+ expect ( postcssrc . plugins [ '@tailwindcss/postcss' ] ) . toEqual ( { } ) ;
186+ } ) ;
187+
188+ it ( `should generate src/tailwind.css` , ( ) => {
189+ expect ( tree . exists ( `/projects/${ APPNAME } /src/tailwind.css` ) ) . toBe ( true ) ;
190+ const content = tree . readContent ( `/projects/${ APPNAME } /src/tailwind.css` ) ;
191+ expect ( content ) . toContain ( `@layer theme, base, ng-alain, utilities;` ) ;
192+ expect ( content ) . toContain ( `@import 'tailwindcss'` ) ;
193+ } ) ;
194+
195+ it ( `should handle styles.less gracefully when file does not exist (no crash)` , ( ) => {
196+ // removeOrginalFiles deletes styles.less before addTailwindcss
197+ // In test env (--style css), styles.less never existed
198+ // The function should handle missing styles.less gracefully
199+ expect ( tree . exists ( `/projects/${ APPNAME } /src/styles.less` ) ) . toBe ( false ) ;
200+ } ) ;
201+
202+ it ( `should add src/tailwind.css to angular.json styles` , ( ) => {
203+ const angularJson = JSON . parse ( tree . readContent ( 'angular.json' ) ) ;
204+ const styles = angularJson . projects [ APPNAME ] . architect . build . options . styles ;
205+ expect ( styles . some ( ( s : string ) => s . includes ( 'tailwind.css' ) ) ) . toBe ( true ) ;
206+ } ) ;
207+
208+ it ( `should update .vscode/extensions.json with tailwindcss recommendation` , ( ) => {
209+ expect ( tree . exists ( '.vscode/extensions.json' ) ) . toBe ( true ) ;
210+ const ext = JSON . parse ( tree . readContent ( '.vscode/extensions.json' ) ) ;
211+ expect ( ext . recommendations ) . toContain ( 'bradlc.vscode-tailwindcss' ) ;
212+ } ) ;
213+ } ) ;
214+ } ) ;
215+
130216 describe ( '#multiple-projects' , ( ) => {
131217 let runner : SchematicTestRunner ;
132218 let tree : UnitTestTree ;
0 commit comments