Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(angular): update remote entry component selector to use the provided prefix #10561

Merged
merged 1 commit into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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 {}"
`;
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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