Skip to content

Commit

Permalink
fix(misc): update component generators and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Sep 26, 2024
1 parent 38d2ffa commit b32fdc8
Show file tree
Hide file tree
Showing 24 changed files with 246 additions and 427 deletions.
78 changes: 26 additions & 52 deletions packages/angular/src/generators/component/component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ describe('component Generator', () => {

// ACT
await componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/src/lib/example',
path: 'libs/lib1/src/lib/example/example',
standalone: false,
});

Expand Down Expand Up @@ -79,8 +78,7 @@ describe('component Generator', () => {

// ACT
await componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/src/lib/example',
path: 'libs/lib1/src/lib/example/example',
skipTests: true,
standalone: false,
skipFormat: true,
Expand Down Expand Up @@ -115,8 +113,7 @@ describe('component Generator', () => {

// ACT
await componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/src/lib/example',
path: 'libs/lib1/src/lib/example/example',
inlineTemplate: true,
standalone: false,
skipFormat: true,
Expand Down Expand Up @@ -154,8 +151,7 @@ describe('component Generator', () => {

// ACT
await componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/src/lib/example',
path: 'libs/lib1/src/lib/example/example',
inlineStyle: true,
standalone: false,
skipFormat: true,
Expand Down Expand Up @@ -193,8 +189,7 @@ describe('component Generator', () => {

// ACT
await componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/src/lib/example',
path: 'libs/lib1/src/lib/example/example',
style: 'none',
standalone: false,
skipFormat: true,
Expand Down Expand Up @@ -240,8 +235,7 @@ describe('component Generator', () => {

// ACT
await componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/src/lib/example',
path: 'libs/lib1/src/lib/example/example',
export: true,
standalone: false,
skipFormat: true,
Expand Down Expand Up @@ -281,8 +275,7 @@ describe('component Generator', () => {

// ACT
await componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/src/lib/example',
path: 'libs/lib1/src/lib/example/example',
export: true,
skipFormat: true,
});
Expand Down Expand Up @@ -323,8 +316,7 @@ describe('component Generator', () => {

// ACT
await componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/src/lib/example',
path: 'libs/lib1/src/lib/example/example',
export: false,
standalone: false,
skipFormat: true,
Expand Down Expand Up @@ -366,8 +358,7 @@ describe('component Generator', () => {

// ACT
await componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/src/lib/example',
path: 'libs/lib1/src/lib/example/example',
export: false,
skipFormat: true,
});
Expand Down Expand Up @@ -408,8 +399,7 @@ describe('component Generator', () => {

// ACT
await componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/src/lib/example',
path: 'libs/lib1/src/lib/example/example',
skipImport: true,
standalone: false,
skipFormat: true,
Expand Down Expand Up @@ -450,8 +440,7 @@ describe('component Generator', () => {

// ACT
await componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/src/lib/example',
path: 'libs/lib1/src/lib/example/example',
export: true,
standalone: false,
skipFormat: true,
Expand Down Expand Up @@ -491,8 +480,7 @@ describe('component Generator', () => {

// ACT
await componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/src/lib/example',
path: 'libs/lib1/src/lib/example/example',
export: true,
standalone: false,
skipFormat: true,
Expand Down Expand Up @@ -539,8 +527,7 @@ describe('component Generator', () => {

// ACT
await componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/src/lib/example',
path: 'libs/lib1/src/lib/example/example',
module,
export: true,
standalone: false,
Expand Down Expand Up @@ -582,8 +569,7 @@ export class LibModule {}

// ACT
await componentGenerator(tree, {
name: 'example',
directory: 'libs/shared/ui/src/lib/example',
path: 'libs/shared/ui/src/lib/example/example',
export: true,
standalone: false,
skipFormat: true,
Expand Down Expand Up @@ -631,8 +617,7 @@ export class LibModule {}

// ACT
await componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/src/lib/example',
path: 'libs/lib1/src/lib/example/example',
module: 'not-exported',
export: true,
standalone: false,
Expand Down Expand Up @@ -669,8 +654,7 @@ export class LibModule {}
// ACT & ASSERT
await expect(
componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/src/lib/example',
path: 'libs/lib1/src/lib/example/example',
module: 'not-found',
standalone: false,
skipFormat: true,
Expand Down Expand Up @@ -712,8 +696,7 @@ export class LibModule {}
// ACT & ASSERT
await expect(
componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/src/lib/example',
path: 'libs/lib1/src/lib/example/example',
standalone: false,
skipFormat: true,
})
Expand All @@ -734,9 +717,8 @@ export class LibModule {}

it('should use the prefix', async () => {
await componentGenerator(tree, {
name: 'lib1/src/lib/example/example',
path: 'lib1/src/lib/example/example',
prefix: 'foo',
nameAndDirectoryFormat: 'as-provided',
});

const content = tree.read(
Expand All @@ -749,18 +731,16 @@ export class LibModule {}
it('should error when name starts with a digit', async () => {
await expect(
componentGenerator(tree, {
name: 'lib1/src/lib/1-one/1-one',
path: 'lib1/src/lib/1-one/1-one',
prefix: 'foo',
nameAndDirectoryFormat: 'as-provided',
})
).rejects.toThrow('The selector "foo-1-one" is invalid.');
});

it('should allow dash in selector before a number', async () => {
await componentGenerator(tree, {
name: 'lib1/src/lib/one-1/one-1',
path: 'lib1/src/lib/one-1/one-1',
prefix: 'foo',
nameAndDirectoryFormat: 'as-provided',
});

const content = tree.read(
Expand All @@ -772,9 +752,8 @@ export class LibModule {}

it('should allow dash in selector before a number and without a prefix', async () => {
await componentGenerator(tree, {
name: 'lib1/src/lib/example/example',
path: 'lib1/src/lib/example/example',
selector: 'one-1',
nameAndDirectoryFormat: 'as-provided',
});

const content = tree.read(
Expand All @@ -792,8 +771,7 @@ export class LibModule {}
} as AngularProjectConfiguration);

await componentGenerator(tree, {
name: 'lib1/src/lib/example/example',
nameAndDirectoryFormat: 'as-provided',
path: 'lib1/src/lib/example/example',
});

const content = tree.read(
Expand All @@ -811,8 +789,7 @@ export class LibModule {}
} as AngularProjectConfiguration);

await componentGenerator(tree, {
name: 'lib1/src/lib/example/example',
nameAndDirectoryFormat: 'as-provided',
path: 'lib1/src/lib/example/example',
});

const content = tree.read(
Expand Down Expand Up @@ -867,8 +844,7 @@ export class LibModule {}

// ACT
await componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/secondary/src/lib/example',
path: 'libs/lib1/secondary/src/lib/example/example',
export: true,
standalone: false,
skipFormat: true,
Expand Down Expand Up @@ -928,8 +904,7 @@ export class LibModule {}

// ACT
await componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/secondary/src/lib/example',
path: 'libs/lib1/secondary/src/lib/example',
export: true,
standalone: false,
skipFormat: true,
Expand Down Expand Up @@ -966,8 +941,7 @@ export class LibModule {}
tree.write('libs/lib1/src/index.ts', '');

await componentGenerator(tree, {
name: 'example',
directory: 'libs/lib1/src/lib/example',
path: 'libs/lib1/src/lib/example/example',
inlineStyle: true,
standalone: false,
skipFormat: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function normalizeOptions(
project: projectName,
} = await determineArtifactNameAndDirectoryOptions(tree, {
name: options.name,
path: options.directory,
path: options.path,
suffix: options.type ?? 'component',
});

Expand Down
6 changes: 2 additions & 4 deletions packages/angular/src/generators/component/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';

export interface Schema {
name: string;
directory?: string;
path: string;
name?: string;
nameAndDirectoryFormat?: NameAndDirectoryFormat;
displayBlock?: boolean;
inlineStyle?: boolean;
Expand Down
Loading

0 comments on commit b32fdc8

Please sign in to comment.