diff --git a/front-end/src/app/app.component.ts b/front-end/src/app/app.component.ts index f31a17a2b7..5463c47b11 100644 --- a/front-end/src/app/app.component.ts +++ b/front-end/src/app/app.component.ts @@ -6,9 +6,10 @@ import { NavigationEnd, Router, RouterOutlet } from '@angular/router'; import { SecondCommitteeAdminDialogComponent } from './shared/components/second-committee-admin-dialog/second-committee-admin-dialog.component'; import { ButtonModule } from 'primeng/button'; import { GlossaryComponent } from './shared/components/glossary/glossary.component'; -import { environment } from 'environments/environment'; + import { ConfirmDialogComponent } from './shared/components/confirm-dialog/confirm-dialog.component'; import { CommitteeMemberService } from 'app/shared/services/committee-member.service'; +import { FEATURE_FLAGS } from 'environments/config/feature-flag.config'; import { Store } from '@ngrx/store'; import { singleClickEnableAction } from './store/single-click.actions'; import { toSignal } from '@angular/core/rxjs-interop'; @@ -32,7 +33,7 @@ import { map } from 'rxjs'; export class AppComponent { protected readonly elementRef = inject(ElementRef); readonly memberService = inject(CommitteeMemberService); - readonly showGlossary = environment.showGlossary; + readonly showGlossary = inject(FEATURE_FLAGS).showGlossary; private readonly store = inject(Store); private readonly router = inject(Router); diff --git a/front-end/src/app/contacts/contact-list/contact-list.component.spec.ts b/front-end/src/app/contacts/contact-list/contact-list.component.spec.ts index 40a5cbda53..fe72dc2e70 100644 --- a/front-end/src/app/contacts/contact-list/contact-list.component.spec.ts +++ b/front-end/src/app/contacts/contact-list/contact-list.component.spec.ts @@ -1,7 +1,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { FormBuilder } from '@angular/forms'; import { provideMockStore } from '@ngrx/store/testing'; -import { testContact, testMockStore } from 'app/shared/utils/unit-test.utils'; +import { testContact, testFeatureFlags, testMockStore } from 'app/shared/utils/unit-test.utils'; import { ConfirmationService, MessageService } from 'primeng/api'; import { ConfirmDialogModule } from 'primeng/confirmdialog'; import { DialogModule } from 'primeng/dialog'; @@ -20,6 +20,7 @@ import { MemoCodePipe } from 'app/shared/pipes/memo-code.pipe'; import { FecDatePipe } from 'app/shared/pipes/fec-date.pipe'; import { TransactionIdPipe } from 'app/shared/pipes/transaction-id.pipe'; import { DefaultZeroPipe } from 'app/shared/pipes/default-zero.pipe'; +import { FEATURE_FLAGS } from 'environments/config/feature-flag.config'; describe('ContactListComponent', () => { let component: ContactListComponent; @@ -42,7 +43,7 @@ describe('ContactListComponent', () => { }; let deletedContactService: DeletedContactService; - beforeEach(async () => { + async function setup(showRestoreDeletedContacts = true) { await TestBed.configureTestingModule({ imports: [ ToastModule, @@ -74,20 +75,22 @@ describe('ContactListComponent', () => { snapshot: { params: { reportId: '99' } }, }, }, + { + provide: FEATURE_FLAGS, + useValue: { ...testFeatureFlags(), showRestoreDeletedContacts }, + }, ], }).compileComponents(); - deletedContactService = TestBed.inject(DeletedContactService); - }); - beforeEach(() => { + deletedContactService = TestBed.inject(DeletedContactService); service = TestBed.inject(ContactService); fixture = TestBed.createComponent(ContactListComponent); component = fixture.componentInstance; - }); + } describe('typical', () => { - beforeEach(() => { - component.showRestoreDeletedContacts = true; + beforeEach(async () => { + await setup(); fixture.detectChanges(); }); @@ -177,7 +180,6 @@ describe('ContactListComponent', () => { it('#restoreButton should be visible if there is a deleted contact', async () => { expect(component.restoreContactsButtonIsVisible).toBe(false); - vi.spyOn(deletedContactService, 'getTableData').mockReturnValue( Promise.resolve({ count: 1, @@ -188,13 +190,11 @@ describe('ContactListComponent', () => { }), ); await component.checkForDeletedContacts(); - expect(component.restoreContactsButtonIsVisible).toBe(true); }); it('#restoreButton should not be visible if there are no deleted contacts', async () => { component.restoreContactsButtonIsVisible = true; - vi.spyOn(deletedContactService, 'getTableData').mockReturnValue( Promise.resolve({ count: 0, @@ -204,25 +204,8 @@ describe('ContactListComponent', () => { results: [], }), ); - await component.checkForDeletedContacts(); - - expect(component.restoreContactsButtonIsVisible).toBe(false); - }); - - it('Restore deleted contacts should not be visible when the feature flag is disabled', async () => { - component.showRestoreDeletedContacts = false; - vi.spyOn(deletedContactService, 'getTableData').mockReturnValue( - Promise.resolve({ - count: 1, - next: '', - previous: '', - pageNumber: 1, - results: [contact], - }), - ); await component.checkForDeletedContacts(); - expect(component.restoreContactsButtonIsVisible).toBe(false); }); @@ -244,8 +227,31 @@ describe('ContactListComponent', () => { }); }); + describe('show restore button is false', () => { + beforeEach(async () => { + await setup(false); + fixture.detectChanges(); + }); + + it('Restore deleted contacts should not be visible when the feature flag is disabled', async () => { + vi.spyOn(deletedContactService, 'getTableData').mockReturnValue( + Promise.resolve({ + count: 1, + next: '', + previous: '', + pageNumber: 1, + results: [contact], + }), + ); + + await component.checkForDeletedContacts(); + expect(component.restoreContactsButtonIsVisible).toBe(false); + }); + }); + describe('restoreContactsButtonIsVisible true', () => { - beforeEach(() => { + beforeEach(async () => { + await setup(); component.restoreContactsButtonIsVisible = true; fixture.detectChanges(); }); diff --git a/front-end/src/app/contacts/contact-list/contact-list.component.ts b/front-end/src/app/contacts/contact-list/contact-list.component.ts index 36b0513650..8354d55271 100644 --- a/front-end/src/app/contacts/contact-list/contact-list.component.ts +++ b/front-end/src/app/contacts/contact-list/contact-list.component.ts @@ -12,7 +12,7 @@ import { ContactService, DeletedContactService } from 'app/shared/services/conta import { SelectModule } from 'primeng/select'; import { TableAction } from 'app/shared/components/table-actions-button/table-actions'; import { RouterLink } from '@angular/router'; -import { environment } from 'environments/environment'; +import { FEATURE_FLAGS } from 'environments/config/feature-flag.config'; @Component({ selector: 'app-contact-list', @@ -37,7 +37,7 @@ export class ContactListComponent extends TableListBaseComponent { contactTypeLabels: LabelList = ContactTypeLabels; dialogContactTypeOptions: PrimeOptions = []; - showRestoreDeletedContacts = environment.showRestoreDeletedContacts; + showRestoreDeletedContacts = inject(FEATURE_FLAGS).showRestoreDeletedContacts; restoreContactsButtonIsVisible = false; searchTerm = ''; diff --git a/front-end/src/app/layout/header/header-links/default-header-links/default-header-links.component.html b/front-end/src/app/layout/header/header-links/default-header-links/default-header-links.component.html index 4d550cbe2a..b6e899d8a4 100644 --- a/front-end/src/app/layout/header/header-links/default-header-links/default-header-links.component.html +++ b/front-end/src/app/layout/header/header-links/default-header-links/default-header-links.component.html @@ -1,6 +1,6 @@