|  | 
|  | 1 | +/** | 
|  | 2 | + * @license | 
|  | 3 | + * Copyright Google LLC All Rights Reserved. | 
|  | 4 | + * | 
|  | 5 | + * Use of this source code is governed by an MIT-style license that can be | 
|  | 6 | + * found in the LICENSE file at https://angular.dev/license | 
|  | 7 | + */ | 
|  | 8 | + | 
|  | 9 | +import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; | 
|  | 10 | +import { Schema as WorkspaceOptions } from '../workspace/schema'; | 
|  | 11 | +import { Schema as ConfigOptions, Tool as ConfigTool } from './schema'; | 
|  | 12 | + | 
|  | 13 | +describe('Ai Config Schematic', () => { | 
|  | 14 | +  const schematicRunner = new SchematicTestRunner( | 
|  | 15 | +    '@schematics/angular', | 
|  | 16 | +    require.resolve('../collection.json'), | 
|  | 17 | +  ); | 
|  | 18 | + | 
|  | 19 | +  const workspaceOptions: WorkspaceOptions = { | 
|  | 20 | +    name: 'workspace', | 
|  | 21 | +    newProjectRoot: 'projects', | 
|  | 22 | +    version: '15.0.0', | 
|  | 23 | +  }; | 
|  | 24 | + | 
|  | 25 | +  let workspaceTree: UnitTestTree; | 
|  | 26 | +  function runConfigSchematic(tool: ConfigTool[]): Promise<UnitTestTree> { | 
|  | 27 | +    return schematicRunner.runSchematic<ConfigOptions>('ai-config', { tool }, workspaceTree); | 
|  | 28 | +  } | 
|  | 29 | + | 
|  | 30 | +  beforeEach(async () => { | 
|  | 31 | +    workspaceTree = await schematicRunner.runSchematic('workspace', workspaceOptions); | 
|  | 32 | +  }); | 
|  | 33 | + | 
|  | 34 | +  it('should create a GEMINI.MD file', async () => { | 
|  | 35 | +    const tree = await runConfigSchematic([ConfigTool.Gemini]); | 
|  | 36 | +    expect(tree.exists('.gemini/GEMINI.md')).toBeTruthy(); | 
|  | 37 | +  }); | 
|  | 38 | + | 
|  | 39 | +  it('should create a copilot-instructions.md file', async () => { | 
|  | 40 | +    const tree = await runConfigSchematic([ConfigTool.Copilot]); | 
|  | 41 | +    expect(tree.exists('.github/copilot-instructions.md')).toBeTruthy(); | 
|  | 42 | +  }); | 
|  | 43 | + | 
|  | 44 | +  it('should create a cursor file', async () => { | 
|  | 45 | +    const tree = await runConfigSchematic([ConfigTool.Cursor]); | 
|  | 46 | +    expect(tree.exists('.cursor/rules/cursor.mdc')).toBeTruthy(); | 
|  | 47 | +  }); | 
|  | 48 | + | 
|  | 49 | +  it('should create a windsurf file', async () => { | 
|  | 50 | +    const tree = await runConfigSchematic([ConfigTool.Windsurf]); | 
|  | 51 | +    expect(tree.exists('.windsurf/rules/guidelines.md')).toBeTruthy(); | 
|  | 52 | +  }); | 
|  | 53 | + | 
|  | 54 | +  it('should create a claude file', async () => { | 
|  | 55 | +    const tree = await runConfigSchematic([ConfigTool.Claude]); | 
|  | 56 | +    expect(tree.exists('.claude/CLAUDE.md')).toBeTruthy(); | 
|  | 57 | +  }); | 
|  | 58 | + | 
|  | 59 | +  it('should create a jetbrains file', async () => { | 
|  | 60 | +    const tree = await runConfigSchematic([ConfigTool.Jetbrains]); | 
|  | 61 | +    expect(tree.exists('.junie/guidelines.md')).toBeTruthy(); | 
|  | 62 | +  }); | 
|  | 63 | + | 
|  | 64 | +  it('should create multiple files when multiple tools are selected', async () => { | 
|  | 65 | +    const tree = await runConfigSchematic([ | 
|  | 66 | +      ConfigTool.Gemini, | 
|  | 67 | +      ConfigTool.Copilot, | 
|  | 68 | +      ConfigTool.Cursor, | 
|  | 69 | +    ]); | 
|  | 70 | +    expect(tree.exists('.gemini/GEMINI.md')).toBeTruthy(); | 
|  | 71 | +    expect(tree.exists('.github/copilot-instructions.md')).toBeTruthy(); | 
|  | 72 | +    expect(tree.exists('.cursor/rules/cursor.mdc')).toBeTruthy(); | 
|  | 73 | +  }); | 
|  | 74 | + | 
|  | 75 | +  it('should error is None is associated with other values', () => { | 
|  | 76 | +    return expectAsync(runConfigSchematic([ConfigTool.None, ConfigTool.Cursor])).toBeRejected(); | 
|  | 77 | +  }); | 
|  | 78 | + | 
|  | 79 | +  it('should not create any files if None is selected', async () => { | 
|  | 80 | +    const filesCount = workspaceTree.files.length; | 
|  | 81 | +    const tree = await runConfigSchematic([ConfigTool.None]); | 
|  | 82 | +    expect(tree.files.length).toBe(filesCount); | 
|  | 83 | +  }); | 
|  | 84 | +}); | 
0 commit comments