Skip to content

Commit

Permalink
Merge pull request AmadeusITGroup#606 from AmadeusITGroup/feat/improv…
Browse files Browse the repository at this point in the history
…e-schematics-feedback

feat: improve schematic ux by proposing to run schematic when the main failed for a known reason
  • Loading branch information
matthieu-crouzet authored Aug 1, 2023
2 parents cb01218 + 97195b3 commit bbb0096
Show file tree
Hide file tree
Showing 20 changed files with 1,276 additions and 932 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Tree } from '@angular-devkit/schematics';
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'node:path';
import * as fs from 'node:fs';
import { firstValueFrom } from 'rxjs';
import { ngAddAnalytics } from './index';

const collectionPath = path.join(__dirname, '..', '..', 'collection.json');
const o3rComponentPath = '/src/components/test/test.component.ts';
Expand Down Expand Up @@ -86,19 +88,37 @@ export class NgComponent {}
}, tree)).rejects.toThrow();
});

it('should throw if no Otter component', async () => {
it('should throw if inexisting path', async () => {
const runner = new SchematicTestRunner('schematics', collectionPath);

await expect(runner.runSchematic('analytics-to-component', {
path: ngComponentPath
path: 'inexisting-path.component.ts'
}, initialTree)).rejects.toThrow();
});

it('should throw if inexisting path', async () => {
const runner = new SchematicTestRunner('schematics', collectionPath);
describe('Angular component', () => {
it('should throw if no Otter component', async () => {
const runner = new SchematicTestRunner('schematics', collectionPath);

await expect(runner.runSchematic('analytics-to-component', {
path: 'inexisting-path.component.ts'
}, initialTree)).rejects.toThrow();
await expect(firstValueFrom(runner.callRule(ngAddAnalytics({
path: ngComponentPath,
skipLinter: false,
activateDummy: false
}), initialTree, { interactive: false }))).rejects.toThrow();
});

it('should call convert-component if no Otter component', async () => {
const runner = new SchematicTestRunner('schematics', collectionPath);
const o3rCorePackageJson = require.resolve('@o3r/core/package.json');
runner.registerCollection('@o3r/core', path.resolve(path.dirname(o3rCorePackageJson), require(o3rCorePackageJson).schematics));
const spy = jest.spyOn(runner.engine, 'createSchematic');

const tree = await runner.runSchematic('analytics-to-component', {
path: ngComponentPath
}, initialTree);

expect(spy).toHaveBeenCalledWith('convert-component', expect.anything(), expect.anything());
expect(tree.exists(ngComponentPath.replace(/component\.ts$/, 'analytics.ts'))).toBeTruthy();
});
});
});
Loading

0 comments on commit bbb0096

Please sign in to comment.