Skip to content

Commit 43507fd

Browse files
committed
fix(routing): Fix dasherize logic in getRooute and fix tests
1 parent e0c16ca commit 43507fd

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const routes = [
8282
},
8383
{
8484
name: 'ChangePasswordFormComponent',
85-
path: 'change-password'
85+
path: 'change-password/:recoveryCode'
8686
}
8787
];
8888

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -241,28 +241,27 @@ describe('layout', () => {
241241

242242
expect(tree.files).toContain('/src/app/app.routes.ts');
243243
const routesContent = tree.readContent('/src/app/app.routes.ts');
244-
244+
245245
expect(routesContent)
246246
.toContain(`import { AuthGuardService } from './shared/services';`);
247-
expect(routesContent)
248-
.toContain(`import { LoginFormComponent } from './shared/components';`);
249-
expect(routesContent)
250-
.toContain(`import { ResetPasswordFormComponent } from './shared/components';`);
251-
expect(routesContent)
252-
.toContain(`import { CreateAccountFormComponent } from './shared/components';`);
253-
expect(routesContent)
254-
.toContain(`import { ChangePasswordFormComponent } from './shared/components';`);
247+
const loginFormComponentMatch = routesContent.match(/\bLoginFormComponent\b/g);
248+
const resetPasswordFormComponentMatch = routesContent.match(/\bResetPasswordFormComponent\b/g);
249+
const createAccountFormComponentMatch = routesContent.match(/\bCreateAccountFormComponent\b/g);
250+
const changePasswordFormComponentMatch = routesContent.match(/\bChangePasswordFormComponent\b/g);
251+
expect(loginFormComponentMatch?.length).toBe(2);
252+
expect(resetPasswordFormComponentMatch?.length).toBe(2);
253+
expect(createAccountFormComponentMatch?.length).toBe(2);
254+
expect(changePasswordFormComponentMatch?.length).toBe(2);
255255

256256
expect(routesContent)
257-
.toContain(`{\n path: 'login-form',\n component: LoginFormComponent,\n canActivate: [ AuthGuardService ]\n },`);
257+
.toContain(`path: 'login-form'`);
258258
expect(routesContent)
259-
.toContain(`{\n path: 'reset-password',\n component: ResetPasswordFormComponent,\n canActivate: [ AuthGuardService ]\n },`);
259+
.toContain(`path: 'reset-password'`);
260260
expect(routesContent)
261-
.toContain(`{\n path: 'create-account',\n component: CreateAccountFormComponent,\n canActivate: [ AuthGuardService ]\n },`);
261+
.toContain(`path: 'create-account'`);
262262
expect(routesContent)
263-
.toContain(`{\n path: 'change-password',\n component: ChangePasswordFormComponent,\n canActivate: [ AuthGuardService ]\n },`);
264-
});
265-
263+
.toContain(`path: 'change-password/:recoveryCode'`);
264+
});
266265
it('should use selected layout', async () => {
267266
const runner = new SchematicTestRunner('schematics', collectionPath);
268267
options.layout = 'side-nav-inner-toolbar';

packages/devextreme-schematics/src/utility/routing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function hasComponentInRoutes(routes: Node, name: string) {
2222

2323
export function getRoute(name: string, componentName?: string) {
2424
return ` {
25-
path: '${strings.dasherize(name)}',
25+
path: '${componentName ? name : strings.dasherize(name)}',
2626
component: ${componentName || getRouteComponentName(name)},
2727
canActivate: [ AuthGuardService ]
2828
}`;

0 commit comments

Comments
 (0)