Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ module.exports = {
'<rootDir>/src/app/app.config.ts',
'<rootDir>/src/app/app.routes.ts',
'<rootDir>/src/app/features/registry/',
'<rootDir>/src/app/features/project/addons/components/configure-configure-addon/',
'<rootDir>/src/app/features/project/addons/components/connect-configured-addon/',
'<rootDir>/src/app/features/project/addons/components/disconnect-addon-modal/',
'<rootDir>/src/app/features/files/',
'<rootDir>/src/app/features/my-projects/',
'<rootDir>/src/app/features/preprints/',
'<rootDir>/src/app/features/project/addons/',
'<rootDir>/src/app/features/project/analytics/',
'<rootDir>/src/app/features/project/contributors/',
'<rootDir>/src/app/features/project/files/',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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,
Expand All @@ -36,7 +36,7 @@ describe('EducationComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [EducationComponent, MockPipe(TranslatePipe)],
imports: [EducationComponent, MockComponent(EducationFormComponent)],
providers: [
TranslateServiceMock,
MockCustomConfirmationServiceProvider,
Expand Down Expand Up @@ -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,
},
],
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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';
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';

import { TranslateServiceMock } from '@shared/mocks';

Expand All @@ -8,10 +9,23 @@ describe('DataResourcesComponent', () => {
let component: DataResourcesComponent;
let fixture: ComponentFixture<DataResourcesComponent>;

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);
Expand Down Expand Up @@ -88,37 +102,37 @@ 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', () => {
const testId = '12345';
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', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -9,11 +11,11 @@ describe('ProjectMetadataAffiliatedInstitutionsComponent', () => {
let component: ProjectMetadataAffiliatedInstitutionsComponent;
let fixture: ComponentFixture<ProjectMetadataAffiliatedInstitutionsComponent>;

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();

Expand All @@ -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');
});
});
8 changes: 2 additions & 6 deletions src/app/shared/mocks/project-overview.mock.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down