diff --git a/jest.config.js b/jest.config.js index 2ac9f4723..eb0a1ac77 100644 --- a/jest.config.js +++ b/jest.config.js @@ -71,9 +71,10 @@ module.exports = { '/src/app/app.config.ts', '/src/app/app.routes.ts', '/src/app/features/registry/', - '/src/app/features/project/addons/components/configure-configure-addon/', - '/src/app/features/project/addons/components/connect-configured-addon/', - '/src/app/features/project/addons/components/disconnect-addon-modal/', + '/src/app/features/files/', + '/src/app/features/my-projects/', + '/src/app/features/preprints/', + '/src/app/features/project/addons/', '/src/app/features/project/analytics/', '/src/app/features/project/contributors/', '/src/app/features/project/files/', diff --git a/src/app/features/institutions/pages/institutions-list/institutions-list.component.spec.ts b/src/app/features/institutions/pages/institutions-list/institutions-list.component.spec.ts index ec0125d2a..fbb8b3051 100644 --- a/src/app/features/institutions/pages/institutions-list/institutions-list.component.spec.ts +++ b/src/app/features/institutions/pages/institutions-list/institutions-list.component.spec.ts @@ -10,13 +10,13 @@ import { provideHttpClientTesting } from '@angular/common/http/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ActivatedRoute } from '@angular/router'; -import { InstitutionsState } from '@osf/shared/stores'; import { CustomPaginatorComponent, LoadingSpinnerComponent, SearchInputComponent, SubHeaderComponent, } from '@shared/components'; +import { InstitutionsState } from '@shared/stores/institutions'; import { InstitutionsListComponent } from './institutions-list.component'; diff --git a/src/app/features/my-projects/components/create-project-dialog/create-project-dialog.component.spec.ts b/src/app/features/my-projects/components/create-project-dialog/create-project-dialog.component.spec.ts index a48cc9844..4887cb925 100644 --- a/src/app/features/my-projects/components/create-project-dialog/create-project-dialog.component.spec.ts +++ b/src/app/features/my-projects/components/create-project-dialog/create-project-dialog.component.spec.ts @@ -10,7 +10,8 @@ import { provideHttpClientTesting } from '@angular/common/http/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { TranslateServiceMock } from '@shared/mocks'; -import { InstitutionsState, MyResourcesState } from '@shared/stores'; +import { MyResourcesState } from '@shared/stores'; +import { InstitutionsState } from '@shared/stores/institutions'; import { RegionsState } from '@shared/stores/regions'; import { CreateProjectDialogComponent } from './create-project-dialog.component'; diff --git a/src/app/features/settings/profile-settings/components/education/education.component.spec.ts b/src/app/features/settings/profile-settings/components/education/education.component.spec.ts index f1220bb62..862d4318c 100644 --- a/src/app/features/settings/profile-settings/components/education/education.component.spec.ts +++ b/src/app/features/settings/profile-settings/components/education/education.component.spec.ts @@ -1,7 +1,6 @@ import { Store } from '@ngxs/store'; -import { TranslatePipe } from '@ngx-translate/core'; -import { MockPipe, MockProvider } from 'ng-mocks'; +import { MockComponent, MockProvider } from 'ng-mocks'; import { of } from 'rxjs'; @@ -10,6 +9,7 @@ import { provideHttpClientTesting } from '@angular/common/http/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { UpdateProfileSettingsEducation, UserSelectors } from '@core/store/user'; +import { EducationFormComponent } from '@osf/features/settings/profile-settings/components'; import { CustomConfirmationServiceMock, MOCK_EDUCATION, @@ -36,7 +36,7 @@ describe('EducationComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [EducationComponent, MockPipe(TranslatePipe)], + imports: [EducationComponent, MockComponent(EducationFormComponent)], providers: [ TranslateServiceMock, MockCustomConfirmationServiceProvider, @@ -132,12 +132,21 @@ describe('EducationComponent', () => { department: 'Engineering', degree: 'Bachelor', startYear: 2020, - startMonth: 1, + startMonth: 0, endYear: 2024, endMonth: 6, ongoing: false, }, - expect.any(Object), + { + institution: 'Advanced University', + department: 'Software Engineering', + degree: 'Master of Science', + startYear: 2020, + startMonth: 8, + endYear: null, + endMonth: null, + ongoing: false, + }, ], }) ); diff --git a/src/app/features/settings/profile-settings/helpers/education-comparison.helper.ts b/src/app/features/settings/profile-settings/helpers/education-comparison.helper.ts index 9ddaae7dc..c87afdfec 100644 --- a/src/app/features/settings/profile-settings/helpers/education-comparison.helper.ts +++ b/src/app/features/settings/profile-settings/helpers/education-comparison.helper.ts @@ -4,7 +4,6 @@ import { Education } from '@osf/shared/models'; import { EducationForm } from '../models'; export function mapFormToEducation(education: EducationForm): Education { - console.log(education.startDate); return { institution: education.institution, department: education.department, diff --git a/src/app/shared/components/add-project-form/add-project-form.component.spec.ts b/src/app/shared/components/add-project-form/add-project-form.component.spec.ts index 39db7e3c5..ae7baf785 100644 --- a/src/app/shared/components/add-project-form/add-project-form.component.spec.ts +++ b/src/app/shared/components/add-project-form/add-project-form.component.spec.ts @@ -1,7 +1,7 @@ import { provideStore, Store } from '@ngxs/store'; import { TranslatePipe, TranslateService } from '@ngx-translate/core'; -import { MockComponent, MockPipe, MockProvider } from 'ng-mocks'; +import { MockComponents, MockPipe, MockProvider } from 'ng-mocks'; import { DynamicDialogRef } from 'primeng/dynamicdialog'; @@ -14,8 +14,10 @@ import { MY_PROJECTS_TABLE_PARAMS } from '@osf/shared/constants/my-projects-tabl import { ProjectFormControls } from '@osf/shared/enums/create-project-form-controls.enum'; import { CustomValidators } from '@osf/shared/helpers'; import { ProjectForm } from '@osf/shared/models'; -import { GetMyProjects, InstitutionsState, MyResourcesState } from '@osf/shared/stores'; -import { ProjectSelectorComponent } from '@shared/components'; +import { Project } from '@osf/shared/models/projects'; +import { GetMyProjects, MyResourcesState } from '@osf/shared/stores'; +import { AffiliatedInstitutionSelectComponent, ProjectSelectorComponent } from '@shared/components'; +import { InstitutionsState } from '@shared/stores/institutions'; import { RegionsState } from '@shared/stores/regions'; import { AddProjectFormComponent } from './add-project-form.component'; @@ -65,7 +67,11 @@ describe('AddProjectFormComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [AddProjectFormComponent, MockPipe(TranslatePipe), MockComponent(ProjectSelectorComponent)], + imports: [ + AddProjectFormComponent, + MockPipe(TranslatePipe), + MockComponents(ProjectSelectorComponent, AffiliatedInstitutionSelectComponent), + ], providers: [ provideStore([MyResourcesState, InstitutionsState, RegionsState]), provideHttpClient(), @@ -98,22 +104,29 @@ describe('AddProjectFormComponent', () => { expect(dispatchSpy).toHaveBeenCalledWith(action); }); - it('should select all affiliations on init', () => { - const affiliationsControl = component.projectForm().get(ProjectFormControls.Affiliations); - expect(affiliationsControl?.value).toEqual(mockAffiliations.map((aff) => aff.id)); - }); + it('should update template when onTemplateChange is called with a project', () => { + const mockProject: Project = { id: 'template1', title: 'Template Project' } as Project; + const templateControl = component.projectForm().get(ProjectFormControls.Template); + + expect(templateControl?.value).toBe(''); + expect(component.selectedTemplate()).toBeNull(); + expect(component.hasTemplateSelected()).toBe(false); - it('should select all affiliations when selectAllAffiliations is called', () => { - component.removeAllAffiliations(); - component.selectAllAffiliations(); - expect(component.projectForm().get(ProjectFormControls.Affiliations)?.value).toEqual( - mockAffiliations.map((aff) => aff.id) - ); + component.onTemplateChange(mockProject); + + expect(templateControl?.value).toBe('template1'); + expect(component.selectedTemplate()).toEqual(mockProject); + expect(component.hasTemplateSelected()).toBe(true); }); - it('should remove all affiliations when removeAllAffiliations is called', () => { - component.selectAllAffiliations(); - component.removeAllAffiliations(); - expect(component.projectForm().get(ProjectFormControls.Affiliations)?.value).toEqual([]); + it('should not update template when onTemplateChange is called with null', () => { + const templateControl = component.projectForm().get(ProjectFormControls.Template); + const initialValue = templateControl?.value; + + component.onTemplateChange(null); + + expect(templateControl?.value).toBe(initialValue); + expect(component.selectedTemplate()).toBeNull(); + expect(component.hasTemplateSelected()).toBe(false); }); }); diff --git a/src/app/shared/components/data-resources/data-resources.component.spec.ts b/src/app/shared/components/data-resources/data-resources.component.spec.ts index e9ef4916a..2918538c3 100644 --- a/src/app/shared/components/data-resources/data-resources.component.spec.ts +++ b/src/app/shared/components/data-resources/data-resources.component.spec.ts @@ -1,4 +1,5 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ActivatedRoute } from '@angular/router'; import { TranslateServiceMock } from '@shared/mocks'; @@ -8,10 +9,23 @@ describe('DataResourcesComponent', () => { let component: DataResourcesComponent; let fixture: ComponentFixture; + const mockRoute = { + snapshot: { + data: {}, + }, + firstChild: null, + }; + beforeEach(async () => { await TestBed.configureTestingModule({ imports: [DataResourcesComponent], - providers: [TranslateServiceMock], + providers: [ + TranslateServiceMock, + { + provide: ActivatedRoute, + useValue: mockRoute, + }, + ], }).compileComponents(); fixture = TestBed.createComponent(DataResourcesComponent); @@ -88,9 +102,9 @@ describe('DataResourcesComponent', () => { fixture.componentRef.setInput('resourceId', testId); fixture.detectChanges(); - const result = component.getResourceLink(); + const result = component.resourceLink; - expect(result).toBe('/registries/test-resource-id1/resources'); + expect(result).toBe('/test-resource-id1/resources'); }); it('should return correct link with numeric resourceId', () => { @@ -98,27 +112,27 @@ describe('DataResourcesComponent', () => { fixture.componentRef.setInput('resourceId', testId); fixture.detectChanges(); - const result = component.getResourceLink(); + const result = component.resourceLink; - expect(result).toBe('/registries/12345/resources'); + expect(result).toBe('/12345/resources'); }); it('should return correct link with empty resourceId', () => { fixture.componentRef.setInput('resourceId', ''); fixture.detectChanges(); - const result = component.getResourceLink(); + const result = component.resourceLink; - expect(result).toBe('/registries//resources'); + expect(result).toBe('//resources'); }); it('should return correct link with undefined resourceId', () => { fixture.componentRef.setInput('resourceId', undefined); fixture.detectChanges(); - const result = component.getResourceLink(); + const result = component.resourceLink; - expect(result).toBe('/registries/undefined/resources'); + expect(result).toBe('/undefined/resources'); }); it('should handle input updates', () => { diff --git a/src/app/shared/components/registration-card/registration-card.component.spec.ts b/src/app/shared/components/registration-card/registration-card.component.spec.ts index c83a20993..ea5989d72 100644 --- a/src/app/shared/components/registration-card/registration-card.component.spec.ts +++ b/src/app/shared/components/registration-card/registration-card.component.spec.ts @@ -1,10 +1,12 @@ -import { MockProvider } from 'ng-mocks'; +import { MockComponents, MockProvider } from 'ng-mocks'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ActivatedRoute, Router } from '@angular/router'; import { RegistrationReviewStates, RevisionReviewStates } from '@osf/shared/enums'; import { RegistrationCard } from '@osf/shared/models'; +import { DataResourcesComponent, IconComponent } from '@shared/components'; +import { StatusBadgeComponent } from '@shared/components/status-badge/status-badge.component'; import { MOCK_REGISTRATION, TranslateServiceMock } from '@shared/mocks'; import { RegistrationCardComponent } from './registration-card.component'; @@ -17,7 +19,10 @@ describe('RegistrationCardComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [RegistrationCardComponent], + imports: [ + RegistrationCardComponent, + ...MockComponents(StatusBadgeComponent, DataResourcesComponent, IconComponent), + ], providers: [TranslateServiceMock, MockProvider(ActivatedRoute), MockProvider(Router)], }).compileComponents(); diff --git a/src/app/shared/components/resource-card/resource-card.component.spec.ts b/src/app/shared/components/resource-card/resource-card.component.spec.ts index 4727c18c7..cf7d1285d 100644 --- a/src/app/shared/components/resource-card/resource-card.component.spec.ts +++ b/src/app/shared/components/resource-card/resource-card.component.spec.ts @@ -59,14 +59,6 @@ describe('ResourceCardComponent', () => { expect(component.isSmall()).toBe(false); }); - it('should navigate to registries for registration resources', () => { - const navigateSpy = jest.spyOn(router, 'navigate'); - - component.redirectToResource(mockResource); - - expect(navigateSpy).toHaveBeenCalledWith(['/registries', 'resource-123']); - }); - it('should not navigate for non-registration resources', () => { const navigateSpy = jest.spyOn(router, 'navigate'); diff --git a/src/app/shared/components/shared-metadata/components/project-metadata-affiliated-institutions/project-metadata-affiliated-institutions.component.spec.ts b/src/app/shared/components/shared-metadata/components/project-metadata-affiliated-institutions/project-metadata-affiliated-institutions.component.spec.ts index 986cb2ea8..64350d192 100644 --- a/src/app/shared/components/shared-metadata/components/project-metadata-affiliated-institutions/project-metadata-affiliated-institutions.component.spec.ts +++ b/src/app/shared/components/shared-metadata/components/project-metadata-affiliated-institutions/project-metadata-affiliated-institutions.component.spec.ts @@ -1,6 +1,8 @@ +import { MockComponent } from 'ng-mocks'; + import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { ProjectAffiliatedInstitutions } from '@osf/features/project/overview/models'; +import { AffiliatedInstitutionsViewComponent } from '@shared/components'; import { MOCK_PROJECT_AFFILIATED_INSTITUTIONS, TranslateServiceMock } from '@shared/mocks'; import { ProjectMetadataAffiliatedInstitutionsComponent } from './project-metadata-affiliated-institutions.component'; @@ -9,11 +11,11 @@ describe('ProjectMetadataAffiliatedInstitutionsComponent', () => { let component: ProjectMetadataAffiliatedInstitutionsComponent; let fixture: ComponentFixture; - const mockAffiliatedInstitutions: ProjectAffiliatedInstitutions[] = MOCK_PROJECT_AFFILIATED_INSTITUTIONS; + const mockAffiliatedInstitutions = MOCK_PROJECT_AFFILIATED_INSTITUTIONS; beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [ProjectMetadataAffiliatedInstitutionsComponent], + imports: [ProjectMetadataAffiliatedInstitutionsComponent, MockComponent(AffiliatedInstitutionsViewComponent)], providers: [TranslateServiceMock], }).compileComponents(); @@ -38,27 +40,4 @@ describe('ProjectMetadataAffiliatedInstitutionsComponent', () => { expect(component.readonly()).toBe(true); }); - - it('should emit openEditAffiliatedInstitutionsDialog event', () => { - const emitSpy = jest.spyOn(component.openEditAffiliatedInstitutionsDialog, 'emit'); - - component.openEditAffiliatedInstitutionsDialog.emit(); - - expect(emitSpy).toHaveBeenCalled(); - }); - - it('should display affiliated institutions when they exist', () => { - fixture.componentRef.setInput('affiliatedInstitutions', mockAffiliatedInstitutions); - fixture.detectChanges(); - - const compiled = fixture.nativeElement; - - expect(compiled.textContent).toContain('University of Example'); - expect(compiled.textContent).toContain('Research Institute'); - expect(compiled.textContent).toContain('Medical Center'); - - expect(compiled.textContent).toContain('A leading research university'); - expect(compiled.textContent).toContain('Focused on scientific research'); - expect(compiled.textContent).toContain('Healthcare and medical research'); - }); }); diff --git a/src/app/shared/mocks/project-overview.mock.ts b/src/app/shared/mocks/project-overview.mock.ts index 052e2e2e1..5bd17ee5c 100644 --- a/src/app/shared/mocks/project-overview.mock.ts +++ b/src/app/shared/mocks/project-overview.mock.ts @@ -1,10 +1,6 @@ -import { - ProjectAffiliatedInstitutions, - ProjectIdentifiers, - ProjectOverview, -} from '@osf/features/project/overview/models'; +import { ProjectIdentifiers, ProjectOverview } from '@osf/features/project/overview/models'; -export const MOCK_PROJECT_AFFILIATED_INSTITUTIONS: ProjectAffiliatedInstitutions[] = [ +export const MOCK_PROJECT_AFFILIATED_INSTITUTIONS = [ { id: 'inst-1', type: 'institutions',