diff --git a/src/app/core/mock-data/extended-projects.data.ts b/src/app/core/mock-data/extended-projects.data.ts index 48f3b6290e..7461ae79b8 100644 --- a/src/app/core/mock-data/extended-projects.data.ts +++ b/src/app/core/mock-data/extended-projects.data.ts @@ -230,28 +230,26 @@ export const expectedProjects2 = [ value: null, }, { - label: undefined, - value: [ - { - ap1_email: null, - ap1_full_name: null, - ap2_email: null, - ap2_full_name: null, - project_active: true, - project_approver1_id: null, - project_approver2_id: null, - project_code: null, - project_created_at: new Date('2020-06-26T05:32:00.174Z'), - project_description: null, - project_id: 3943, - project_name: 'Staging Project', - project_org_category_ids: [16560, 224734, 201949], - project_org_id: 'orNVthTo2Zyo', - project_updated_at: new Date('2022-11-23T08:55:29.400Z'), - projectv2_name: 'Staging Project', - sub_project_name: null, - }, - ], + label: 'Staging Project', + value: { + ap1_email: null, + ap1_full_name: null, + ap2_email: null, + ap2_full_name: null, + project_active: true, + project_approver1_id: null, + project_approver2_id: null, + project_code: null, + project_created_at: new Date('2020-06-26T05:32:00.174Z'), + project_description: null, + project_id: 3943, + project_name: 'Staging Project', + project_org_category_ids: [16560, 224734, 201949], + project_org_id: 'orNVthTo2Zyo', + project_updated_at: new Date('2022-11-23T08:55:29.400Z'), + projectv2_name: 'Staging Project', + sub_project_name: null, + }, }, { label: 'Customer Mapped Project', diff --git a/src/app/core/models/project-options.model.ts b/src/app/core/models/project-options.model.ts deleted file mode 100644 index 3a8365def9..0000000000 --- a/src/app/core/models/project-options.model.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface ProjectOptionType { - value: string; -} diff --git a/src/app/shared/components/fy-select-project/fy-select-modal/fy-select-project-modal.component.spec.ts b/src/app/shared/components/fy-select-project/fy-select-modal/fy-select-project-modal.component.spec.ts index 69cee844a8..438bc19280 100644 --- a/src/app/shared/components/fy-select-project/fy-select-modal/fy-select-project-modal.component.spec.ts +++ b/src/app/shared/components/fy-select-project/fy-select-modal/fy-select-project-modal.component.spec.ts @@ -15,7 +15,7 @@ import { MatFormFieldModule } from '@angular/material/form-field'; import { FormsModule } from '@angular/forms'; import { MatInputModule } from '@angular/material/input'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { of } from 'rxjs'; +import { map, of } from 'rxjs'; import { orgUserSettingsData } from 'src/app/core/mock-data/org-user-settings.data'; import { orgSettingsData, orgSettingsDataWithoutAdvPro } from 'src/app/core/test-data/accounts.service.spec.data'; import { apiEouRes } from 'src/app/core/mock-data/extended-org-user.data'; @@ -36,7 +36,7 @@ import { click, getAllElementsBySelector, getElementBySelector, getTextContent } import { By } from '@angular/platform-browser'; import { recentlyUsedRes } from 'src/app/core/mock-data/recently-used.data'; -describe('FyProjectSelectModalComponent', () => { +fdescribe('FyProjectSelectModalComponent', () => { let component: FyProjectSelectModalComponent; let fixture: ComponentFixture; let modalController: jasmine.SpyObj; @@ -166,7 +166,7 @@ describe('FyProjectSelectModalComponent', () => { it('should get projects when current selection is defined', (done) => { projectService.getByParamsUnformatted.and.returnValue(of(projects)); - component.currentSelection = [testProjectV2]; + component.currentSelection = testProjectV2; fixture.detectChanges(); component.getProjects('projects').subscribe((res) => { @@ -289,8 +289,8 @@ describe('FyProjectSelectModalComponent', () => { it('should dismiss the modal with selected option', () => { modalController.dismiss.and.returnValue(Promise.resolve(true)); - component.onElementSelect('value'); - expect(modalController.dismiss).toHaveBeenCalledWith('value'); + component.onElementSelect({ label: '', value: null }); + expect(modalController.dismiss).toHaveBeenCalledWith({ label: '', value: null }); expect(recentLocalStorageItemsService.post).not.toHaveBeenCalled(); }); @@ -300,16 +300,12 @@ describe('FyProjectSelectModalComponent', () => { component.cacheName = 'cache'; fixture.detectChanges(); - component.onElementSelect({ - value: 'value', - }); + component.onElementSelect({ label: 'Staging Project', value: testProjectV2 }); - expect(modalController.dismiss).toHaveBeenCalledOnceWith({ - value: 'value', - }); + expect(modalController.dismiss).toHaveBeenCalledOnceWith({ label: 'Staging Project', value: testProjectV2 }); expect(recentLocalStorageItemsService.post).toHaveBeenCalledOnceWith( component.cacheName, - { value: 'value' }, + { label: 'Staging Project', value: testProjectV2 }, 'label' ); }); @@ -371,13 +367,20 @@ describe('FyProjectSelectModalComponent', () => { it('should select element on clicking recently used items', () => { spyOn(component, 'onElementSelect'); - component.recentrecentlyUsedItems$ = of([testProjectV2]); + component.recentrecentlyUsedItems$ = of(testProjectV2).pipe( + map((project) => [ + { + label: project.project_name, + value: project, + }, + ]) + ); fixture.detectChanges(); const itemsList = getAllElementsBySelector(fixture, '.selection-modal--recently-used-item-content'); click(itemsList[0] as HTMLElement); - expect(component.onElementSelect).toHaveBeenCalledOnceWith(testProjectV2); + expect(component.onElementSelect).toHaveBeenCalledOnceWith({ label: 'Staging Project', value: testProjectV2 }); }); it('should select an element on clicking filtered items', () => { diff --git a/src/app/shared/components/fy-select-project/fy-select-modal/fy-select-project-modal.component.ts b/src/app/shared/components/fy-select-project/fy-select-modal/fy-select-project-modal.component.ts index 3e80732053..24198f9bf4 100644 --- a/src/app/shared/components/fy-select-project/fy-select-modal/fy-select-project-modal.component.ts +++ b/src/app/shared/components/fy-select-project/fy-select-modal/fy-select-project-modal.component.ts @@ -11,7 +11,6 @@ import { UtilityService } from 'src/app/core/services/utility.service'; import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; import { OrgUserSettingsService } from 'src/app/core/services/org-user-settings.service'; import { OrgUserSettings } from 'src/app/core/models/org_user_settings.model'; -import { ProjectOptionType } from 'src/app/core/models/project-options.model'; import { ProjectOptionTypeWithLabel } from 'src/app/core/models/project-options-with-label.model'; @Component({ @@ -22,7 +21,7 @@ import { ProjectOptionTypeWithLabel } from 'src/app/core/models/project-options- export class FyProjectSelectModalComponent implements AfterViewInit { @ViewChild('searchBar') searchBarRef: ElementRef; - @Input() currentSelection: ExtendedProject | [ExtendedProject]; + @Input() currentSelection: ExtendedProject; @Input() filteredOptions$: Observable; @@ -38,9 +37,9 @@ export class FyProjectSelectModalComponent implements AfterViewInit { @Input() label: string; - recentrecentlyUsedItems$: Observable; + recentrecentlyUsedItems$: Observable; - value; + value: string; isLoading = false; @@ -55,7 +54,7 @@ export class FyProjectSelectModalComponent implements AfterViewInit { private orgSettingsService: OrgSettingsService ) {} - getProjects(searchNameText: string): Observable<{ label: string; value: ExtendedProject | ExtendedProject[] }[]> { + getProjects(searchNameText: string): Observable { // set isLoading to true this.isLoading = true; // run ChangeDetectionRef.detectChanges to avoid 'expression has changed after it was checked error'. @@ -117,10 +116,10 @@ export class FyProjectSelectModalComponent implements AfterViewInit { const currentElement = []; if ( this.currentSelection && - !projects.some((project) => project.project_id === (this.currentSelection as ExtendedProject).project_id) + !projects.some((project) => project.project_id === this.currentSelection.project_id) ) { currentElement.push({ - label: (this.currentSelection as ExtendedProject).project_name, + label: this.currentSelection.project_name, value: this.currentSelection, }); } @@ -199,8 +198,8 @@ export class FyProjectSelectModalComponent implements AfterViewInit { this.modalController.dismiss(); } - onElementSelect(option: ProjectOptionType | ProjectOptionTypeWithLabel | string | ExtendedProject): void { - if (this.cacheName && ((option as ProjectOptionType) || (option as ProjectOptionTypeWithLabel)).value) { + onElementSelect(option: ProjectOptionTypeWithLabel): void { + if (this.cacheName && option.value) { this.recentLocalStorageItemsService.post(this.cacheName, option, 'label'); } this.modalController.dismiss(option);