Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
SahilK-027 committed May 2, 2024
1 parent 92f9701 commit bb2cddd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 48 deletions.
42 changes: 20 additions & 22 deletions src/app/core/mock-data/extended-projects.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 0 additions & 3 deletions src/app/core/models/project-options.model.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<FyProjectSelectModalComponent>;
let modalController: jasmine.SpyObj<ModalController>;
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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();
});

Expand All @@ -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'
);
});
Expand Down Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -22,7 +21,7 @@ import { ProjectOptionTypeWithLabel } from 'src/app/core/models/project-options-
export class FyProjectSelectModalComponent implements AfterViewInit {
@ViewChild('searchBar') searchBarRef: ElementRef<HTMLInputElement>;

@Input() currentSelection: ExtendedProject | [ExtendedProject];
@Input() currentSelection: ExtendedProject;

@Input() filteredOptions$: Observable<ProjectOptionTypeWithLabel[]>;

Expand All @@ -38,9 +37,9 @@ export class FyProjectSelectModalComponent implements AfterViewInit {

@Input() label: string;

recentrecentlyUsedItems$: Observable<ExtendedProject[] | ProjectOptionTypeWithLabel[]>;
recentrecentlyUsedItems$: Observable<ProjectOptionTypeWithLabel[]>;

value;
value: string;

isLoading = false;

Expand All @@ -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<ProjectOptionTypeWithLabel[]> {
// set isLoading to true
this.isLoading = true;
// run ChangeDetectionRef.detectChanges to avoid 'expression has changed after it was checked error'.
Expand Down Expand Up @@ -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,
});
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bb2cddd

Please sign in to comment.