Skip to content

Commit 6739d06

Browse files
fix add-view for Angular (#934)
1 parent 9d1ccdc commit 6739d06

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

packages/devextreme-schematics/src/add-layout/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,16 @@ function updateAppModule(host: Tree, sourcePath: string) {
208208

209209
function getComponentName(host: Tree, sourcePath: string) {
210210
let name = '';
211-
const index = 1;
211+
let index = 0;
212212

213213
if (!host.exists(sourcePath + 'app.component.ts')) {
214214
name = 'app';
215215
}
216216

217217
while (!name) {
218+
index++;
218219
const componentName = `app${index}`;
220+
219221
if (!host.exists(`${sourcePath}${componentName}.component.ts`)) {
220222
name = componentName;
221223
}

packages/devextreme-schematics/src/add-view/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ async function addContentToTS(options: any) {
151151
const content = `import { Component } from '@angular/core';
152152
153153
@Component({
154-
selector: 'app-new-page',
155-
templateUrl: './new-page.component.html',
156-
styleUrl: './new-page.component.css',
154+
selector: 'app-${name}',
155+
templateUrl: './${name}.component.html',
156+
styleUrl: './${name}.component.css',
157157
standalone: false
158158
})
159-
export class NewPageComponent {
159+
export class ${strings.classify(basename(normalize(name)))}Component {
160160
161161
}
162162
`;

packages/devextreme-schematics/src/add-view/index_spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
22
import { Schema as WorkspaceOptions } from '@schematics/angular/workspace/schema';
3+
import { strings, basename, normalize } from '@angular-devkit/core';
34
import * as path from 'path';
45

56
const collectionPath = path.join(__dirname, '../collection.json');
@@ -45,6 +46,7 @@ describe('view', () => {
4546

4647
it('should create new view', async () => {
4748
const runner = new SchematicTestRunner('schematics', collectionPath);
49+
const componentName = componentOptions.name;
4850
let tree = await runner.runSchematic('add-layout', { layout: 'side-nav-outer-toolbar' }, appTree);
4951
tree = await runner.runSchematic('add-view', componentOptions, appTree);
5052

@@ -55,7 +57,11 @@ describe('view', () => {
5557
const contentTS = tree.readContent('/src/app/pages/test/test.component.ts');
5658

5759
expect(contentHTML).toMatch(/<h2>Test<\/h2>/);
60+
expect(contentTS).toContain(`selector: 'app-${componentName}'`);
61+
expect(contentTS).toContain(`templateUrl: './${componentName}.component.html'`);
62+
expect(contentTS).toContain(`styleUrl: './${componentName}.component.css'`);
5863
expect(contentTS).toContain('standalone: false');
64+
expect(contentTS).toContain(`export class ${strings.classify(basename(normalize(componentName)))}Component`);
5965
});
6066

6167
it('should add view to default routing module', async () => {

0 commit comments

Comments
 (0)