diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 366bfae..7e8b69e 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -1,7 +1,7 @@ import { BrowserModule } from '@angular/platform-browser'; import { NgModule, APP_INITIALIZER, inject } from '@angular/core'; import { FormsModule } from '@angular/forms'; -import { HttpClientModule, provideHttpClient } from '@angular/common/http'; +import { provideHttpClient } from '@angular/common/http'; import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { AppRoutingModule } from './app.routes'; import { NgxPaginationModule } from 'ngx-pagination'; @@ -57,7 +57,6 @@ export function initConfig(configService: ConfigService) { BrowserAnimationsModule, BrowserModule, FormsModule, - HttpClientModule, ProjectsModule, // <-- module import order matters - https://angular.io/guide/router#module-import-order-matters EnforcementActionsModule, AppRoutingModule, diff --git a/frontend/src/app/projects/project-detail/compliance/compliance-tab-content.component.spec.ts b/frontend/src/app/projects/project-detail/compliance/compliance-tab-content.component.spec.ts index 3af338d..884c323 100644 --- a/frontend/src/app/projects/project-detail/compliance/compliance-tab-content.component.spec.ts +++ b/frontend/src/app/projects/project-detail/compliance/compliance-tab-content.component.spec.ts @@ -1,5 +1,4 @@ import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing'; -import { RouterTestingModule } from '@angular/router/testing'; import { ObjectFilterPipe } from '@pipes/object-filter.pipe'; import { OperatorFilterPipe } from '@pipes/operator-filter.pipe'; import { ProjectStatusFilterPipe } from '@pipes/project-status-filter.pipe'; @@ -11,34 +10,30 @@ import { ConfigService } from '@services/config.service'; import { ComplianceTabContentComponent } from '@projects/project-detail/compliance//compliance-tab-content.component'; import { OrderByPipe } from '@pipes/filters/order-by.pipe'; -import { HttpClientModule } from '@angular/common/http'; -import { Subscription } from 'rxjs'; +import { of } from 'rxjs'; import { ContentService } from '@app/services/content-service'; import { Apollo } from 'apollo-angular'; describe('ComplianceTabContentComponent', () => { let component: ComplianceTabContentComponent; let fixture: ComponentFixture; + let configService: ConfigService; let ActivatedRouteStub; beforeEach(waitForAsync(() => { // stub activated route ActivatedRouteStub = { parent: { - data: { - subscribe: (next: (value) => void) => { - next({project: Project}); - const sub = new Subscription(); - sub.unsubscribe = jest.fn(); - return sub; - } - } + data: of({project: Project}) } }; + const configServiceMock = { + checkFeatureFlag: jest.fn() // Create a mock function + }; TestBed.configureTestingModule({ providers: [ { provide: ActivatedRoute, useValue: ActivatedRouteStub }, - ConfigService, + { provide: ConfigService, useValue: configServiceMock }, ContentService, Apollo ], @@ -51,8 +46,7 @@ describe('ComplianceTabContentComponent', () => { OrderByPipe ], imports: [ - RouterTestingModule, - HttpClientModule + ] }) .compileComponents(); @@ -61,6 +55,7 @@ describe('ComplianceTabContentComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(ComplianceTabContentComponent); component = fixture.componentInstance; + configService = TestBed.inject(ConfigService); component.project = new Project(); component.project.moreInspectionsLink = null; component.collections = new CollectionsArray(); @@ -73,6 +68,9 @@ describe('ComplianceTabContentComponent', () => { it('should return project data', () => { expect(component.project).toBeTruthy(); }); + it('should check feature flag', () => { + expect(configService.checkFeatureFlag).toHaveBeenCalledWith('nrced-link', 'true'); + }) }); describe('parseData(data)', () => { beforeEach(() => { diff --git a/frontend/src/app/projects/project-detail/compliance/compliance-tab-content.component.ts b/frontend/src/app/projects/project-detail/compliance/compliance-tab-content.component.ts index eeeef8a..54272a1 100644 --- a/frontend/src/app/projects/project-detail/compliance/compliance-tab-content.component.ts +++ b/frontend/src/app/projects/project-detail/compliance/compliance-tab-content.component.ts @@ -27,20 +27,22 @@ export class ComplianceTabContentComponent implements OnInit, OnDestroy { NRCEDLinkEnabled: boolean; - constructor(private route: ActivatedRoute, private logger: LoggerService, private configService: ConfigService) { } + constructor(private readonly route: ActivatedRoute, private readonly logger: LoggerService, private readonly configService: ConfigService) { } ngOnInit(): void { this.loading = true; - this.sub = this.route.parent.data.subscribe( - (data: { project: Project }) => this.parseData(data), - error => this.logger.log(error), - () => this.loading = false - ); + + this.sub = this.route.parent.data.subscribe({ + next: (data: { project: Project }) => this.parseData(data), + error: (error) => this.logger.log(error), + complete: () => this.loading = false + }) + this.NRCEDLinkEnabled = this.configService.checkFeatureFlag("nrced-link","true"); } parseData(data: {project: Project}): void { - if (data.project && data.project.collections) { + if (data.project?.collections) { this.project = data.project; this.collections = data.project.collections.compliance;