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

remove not necessary ActivatedRoute usages #24881

Merged
merged 4 commits into from
Jan 17, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
<%_
const tsKeyId = this.generateTestEntityId(user.primaryKey.type);
_%>
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';
import { TestBed } from '@angular/core/testing';
import { provideRouter, withComponentInputBinding } from '@angular/router';
import { RouterTestingHarness, RouterTestingModule } from '@angular/router/testing';
import { of } from 'rxjs';

import { Authority } from 'app/config/authority.constants';
Expand All @@ -29,39 +30,46 @@ import { User } from '../user-management.model';
import UserManagementDetailComponent from './user-management-detail.component';

describe('User Management Detail Component', () => {
let comp: UserManagementDetailComponent;
let fixture: ComponentFixture<UserManagementDetailComponent>;

beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [UserManagementDetailComponent],
providers: [
{
provide: ActivatedRoute,
useValue: {
data: of({ user: new User(<%- tsKeyId %>, 'user', 'first', 'last', '[email protected]', true, 'en', [Authority.USER], 'admin') }),
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [UserManagementDetailComponent, RouterTestingModule.withRoutes([], { bindToComponentInputs: true })],
providers: [
provideRouter(
[
{
path: '**',
component: UserManagementDetailComponent,
resolve: {
user: () => of({
id: <%- tsKeyId %>,
login: 'user',
firstName: 'first',
lastName: 'last',
email: '[email protected]',
activated: true,
langKey: 'en',
authorities: [Authority.USER],
createdBy: 'admin',
}),
},
},
},
],
})
.overrideTemplate(UserManagementDetailComponent, '')
.compileComponents();
],
withComponentInputBinding(),
),
],
})
);

beforeEach(() => {
fixture = TestBed.createComponent(UserManagementDetailComponent);
comp = fixture.componentInstance;
.overrideTemplate(UserManagementDetailComponent, '')
.compileComponents();
});

describe('OnInit', () => {
it('Should call load all on init', () => {
describe('Construct', () => {
it('Should call load all on construct', async () => {
// WHEN
comp.ngOnInit();
const harness = await RouterTestingHarness.create();
const instance = await harness.navigateByUrl('/', UserManagementDetailComponent);

// THEN
expect(comp.user).toEqual(
expect(instance.user).toEqual(
expect.objectContaining({
id: <%- tsKeyId %>,
login: 'user',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
import { Component, inject, OnInit } from '@angular/core';
import { ActivatedRoute, RouterModule } from '@angular/router';
import { Component, Input } from '@angular/core';
import { RouterModule } from '@angular/router';
import SharedModule from 'app/shared/shared.module';

import { User } from '../user-management.model';
Expand All @@ -28,14 +28,6 @@ import { User } from '../user-management.model';
templateUrl: './user-management-detail.component.html',
imports: [RouterModule, SharedModule],
})
export default class UserManagementDetailComponent implements OnInit {
user: User | null = null;

private route = inject(ActivatedRoute);

ngOnInit(): void {
this.route.data.subscribe(({ user }) => {
this.user = user;
});
}
export default class UserManagementDetailComponent {
@Input() user: User | null = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
import { Component, inject, Input } from '@angular/core';
import { ActivatedRoute, RouterModule } from '@angular/router';
import { Component, <% if (anyFieldIsBlobDerived) { %>inject, <% } %>Input } from '@angular/core';
import { RouterModule } from '@angular/router';

import SharedModule from 'app/shared/shared.module';
import { DurationPipe, FormatMediumDatetimePipe, FormatMediumDatePipe } from 'app/shared/date';
Expand All @@ -38,7 +38,6 @@ export class <%= entityAngularName %>DetailComponent {
<%_ if (anyFieldIsBlobDerived) { _%>
protected dataUtils = inject(DataUtils);
<%_ } _%>
protected activatedRoute = inject(ActivatedRoute);

<%_ if (anyFieldIsBlobDerived) { _%>
byteSize(base64String: string): string {
Expand Down
Loading