Skip to content

Commit

Permalink
fix(Schematics): Don't add state import if not provided (#697)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonroberts authored and MikeRyanDev committed Jan 7, 2018
1 parent dffb539 commit e5c2aed
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
14 changes: 14 additions & 0 deletions modules/schematics/src/container/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,18 @@ describe('Container Schematic', () => {
/import { FooComponent } from '.\/foo\/foo.component/
);
});

it('should respect the state option if not provided', () => {
const options = { ...defaultOptions, state: undefined };
const tree = schematicRunner.runSchematic('container', options, appTree);
const content = getFileContent(tree, '/src/app/foo/foo.component.ts');
expect(content).not.toMatch(/import \* as fromStore/);
});

it('should import the state path if provided', () => {
const options = { ...defaultOptions, state: 'reducers' };
const tree = schematicRunner.runSchematic('container', options, appTree);
const content = getFileContent(tree, '/src/app/foo/foo.component.ts');
expect(content).toMatch(/import \* as fromStore from '..\/reducers';/);
});
});
9 changes: 7 additions & 2 deletions modules/schematics/src/container/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,18 @@ export default function(options: ContainerOptions): Rule {
options.path = options.path ? normalize(options.path) : options.path;
options.module = findModuleFromOptions(host, options);

const statePath = `/${options.sourceDir}/${options.path}/${options.state}`;
const componentPath =
`/${options.sourceDir}/${options.path}/` +
(options.flat ? '' : stringUtils.dasherize(options.name) + '/') +
stringUtils.dasherize(options.name) +
'.component';
options.state = buildRelativePath(componentPath, statePath);

if (options.state) {
const statePath = `/${options.sourceDir}/${options.path}/${
options.state
}`;
options.state = buildRelativePath(componentPath, statePath);
}

const templateSource = apply(url('./files'), [
options.spec ? noop() : filter(path => !path.endsWith('__spec.ts')),
Expand Down

0 comments on commit e5c2aed

Please sign in to comment.