Skip to content

Commit

Permalink
fix(angular): update remote entry component selector to use the provi…
Browse files Browse the repository at this point in the history
…ded prefix (#10561)
  • Loading branch information
leosvelperez committed Jun 2, 2022
1 parent 7ce487e commit edea01a
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 6 deletions.
Expand Up @@ -108,3 +108,43 @@ exports[`Init MFE should create webpack and mfe configs correctly 4`] = `
},
}"
`;

exports[`Init MFE should generate the remote entry component correctly when prefix is not provided 1`] = `
"import { Component } from '@angular/core';
@Component({
selector: 'remote1-entry',
template: \`nx-welcome></nx-welcome>\`
})
export class RemoteEntryComponent {}
"
`;
exports[`Init MFE should generate the remote entry module and component correctly 1`] = `
"import { Component } from '@angular/core';
@Component({
selector: 'my-org-remote1-entry',
template: \`<my-org-nx-welcome></my-org-nx-welcome>\`
})
export class RemoteEntryComponent {}
"
`;
exports[`Init MFE should generate the remote entry module and component correctly 2`] = `
"import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RemoteEntryComponent } from './entry.component';
import { NxWelcomeComponent } from './nx-welcome.component';
@NgModule({
declarations: [RemoteEntryComponent, NxWelcomeComponent],
imports: [
CommonModule,
],
providers: [],
exports: [RemoteEntryComponent],
})
export class RemoteEntryModule {}"
`;
@@ -1,7 +1,9 @@
import { Component } from '@angular/core';

@Component({
@Component({<% if (prefix) { %>
selector: '<%= prefix %>-<%= appName %>-entry',
template: `<<%= prefix %>-nx-welcome></<%= prefix %>-nx-welcome>`<% } else { %>
selector: '<%= appName %>-entry',
template: `<<%= prefix %>-nx-welcome></<%= prefix %>-nx-welcome>`
template: `nx-welcome></nx-welcome>`<% } %>
})
export class RemoteEntryComponent {}
@@ -1,15 +1,15 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
<% if(routing) { %>import { RouterModule } from '@angular/router';<% } %>
import { CommonModule } from '@angular/common';<% if(routing) { %>
import { RouterModule } from '@angular/router';<% } %>

import { RemoteEntryComponent } from './entry.component';
import { NxWelcomeComponent } from './nx-welcome.component';

@NgModule({
declarations: [RemoteEntryComponent, NxWelcomeComponent],
imports: [
CommonModule,
<% if(routing) { %>RouterModule.forChild([
CommonModule,<% if(routing) { %>
RouterModule.forChild([
{
path: '',
component: RemoteEntryComponent,
Expand Down
27 changes: 27 additions & 0 deletions packages/angular/src/generators/setup-mfe/setup-mfe.spec.ts
Expand Up @@ -131,6 +131,33 @@ describe('Init MFE', () => {
}
);

it('should generate the remote entry module and component correctly', async () => {
// ACT
await setupMfe(tree, {
appName: 'remote1',
mfeType: 'remote',
prefix: 'my-org',
});

// ASSERT
expect(
tree.read('apps/remote1/src/app/remote-entry/entry.component.ts', 'utf-8')
).toMatchSnapshot();
expect(
tree.read('apps/remote1/src/app/remote-entry/entry.module.ts', 'utf-8')
).toMatchSnapshot();
});

it('should generate the remote entry component correctly when prefix is not provided', async () => {
// ACT
await setupMfe(tree, { appName: 'remote1', mfeType: 'remote' });

// ASSERT
expect(
tree.read('apps/remote1/src/app/remote-entry/entry.component.ts', 'utf-8')
).toMatchSnapshot();
});

it('should add the remote config to the host when --remotes flag supplied', async () => {
// ACT
await setupMfe(tree, {
Expand Down

0 comments on commit edea01a

Please sign in to comment.