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
40 changes: 6 additions & 34 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ module.exports = {
'<rootDir>/src/app/app.config.ts',
'<rootDir>/src/app/app.routes.ts',
'<rootDir>/src/app/features/registry/',
'<rootDir>/src/app/features/my-projects/',
'<rootDir>/src/app/features/project/addons',
'<rootDir>/src/app/features/project/analytics/',
'<rootDir>/src/app/features/project/contributors/',
Expand All @@ -77,47 +78,18 @@ module.exports = {
'<rootDir>/src/app/features/settings/tokens/mappers/',
'<rootDir>/src/app/features/settings/tokens/store/',
'<rootDir>/src/app/features/settings/tokens/pages/tokens-list/',
'<rootDir>/src/app/shared/components/education-history/',
'<rootDir>/src/app/shared/components/education-history-dialog/',
'<rootDir>/src/app/shared/components/employment-history/',
'<rootDir>/src/app/shared/components/employment-history-dialog/',
'<rootDir>/src/app/shared/components/file-menu/',
'<rootDir>/src/app/shared/components/files-tree/',
'<rootDir>/src/app/shared/components/filter-chips/',
'<rootDir>/src/app/shared/components/form-select/',
'<rootDir>/src/app/shared/components/full-screen-loader/',
'<rootDir>/src/app/shared/components/generic-filter/',
'<rootDir>/src/app/shared/components/icon/',
'<rootDir>/src/app/shared/components/info-icon/',
'<rootDir>/src/app/shared/components/license/',
'<rootDir>/src/app/shared/components/line-chart/',
'<rootDir>/src/app/shared/components/list-info-shortener/',
'<rootDir>/src/app/shared/components/loading-spinner/',
'<rootDir>/src/app/shared/components/make-decision-dialog/',
'<rootDir>/src/app/shared/components/markdown/',
'<rootDir>/src/app/shared/components/password-input-hint/',
'<rootDir>/src/app/shared/components/pie-chart/',
'<rootDir>/src/app/shared/components/readonly-input/',
'<rootDir>/src/app/shared/components/registration-card/',
'<rootDir>/src/app/shared/components/resource-card/',
'<rootDir>/src/app/shared/components/resource-citations/',
'<rootDir>/src/app/shared/components/resource-metadata/',
'<rootDir>/src/app/shared/components/reusable-filter/',
'<rootDir>/src/app/shared/components/search-help-tutorial/',
'<rootDir>/src/app/shared/components/search-input/',
'<rootDir>/src/app/shared/components/search-results-container/',
'<rootDir>/src/app/shared/components/select/',
'<rootDir>/src/app/shared/components/shared-metadata/',
'<rootDir>/src/app/shared/components/statistic-card/',
'<rootDir>/src/app/shared/components/status-badge/',
'<rootDir>/src/app/shared/components/stepper/',
'<rootDir>/src/app/shared/components/sub-header/',
'<rootDir>/src/app/shared/components/shared-metadata/dialogs/affiliated-institutions-dialog/',
'<rootDir>/src/app/shared/components/shared-metadata/dialogs/contributors-dialog/',
'<rootDir>/src/app/shared/components/shared-metadata/shared-metadata',
'<rootDir>/src/app/shared/components/subjects/',
'<rootDir>/src/app/shared/components/tags-input/',
'<rootDir>/src/app/shared/components/text-input/',
'<rootDir>/src/app/shared/components/toast/',
'<rootDir>/src/app/shared/components/truncated-text/',
'<rootDir>/src/app/shared/components/view-only-table/',
'<rootDir>/src/app/shared/components/wiki/',
'<rootDir>/src/app/shared/components/wiki/edit-section/',
'<rootDir>/src/app/shared/components/wiki/wiki-list/',
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { provideHttpClientTesting } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';

import { UserState } from '@core/store/user';
import { ModeratorsTableComponent } from '@osf/features/moderation/components';
import { ModeratorsState } from '@osf/features/moderation/store/moderators';
import { SearchInputComponent } from '@shared/components';
Expand Down Expand Up @@ -41,7 +42,7 @@ describe('ModeratorsListComponent', () => {
provide: ActivatedRoute,
useValue: mockRoute,
},
provideStore([ModeratorsState]),
provideStore([ModeratorsState, UserState]),
provideHttpClient(),
provideHttpClientTesting(),
],
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/project/metadata/services/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './project-metadata.service';
export * from './metadata.service';
15 changes: 8 additions & 7 deletions src/app/features/project/wiki/wiki.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ import { provideHttpClientTesting } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivatedRoute, Router } from '@angular/router';

import { WikiComponent } from '@osf/features/project/wiki/wiki.component';
import { SubHeaderComponent } from '@osf/shared/components';
import { ToastService } from '@osf/shared/services';

import { CompareSectionComponent } from './components/compare-section/compare-section.component';
import { EditSectionComponent } from './components/edit-section/edit-section.component';
import { ViewSectionComponent } from './components/view-section/view-section.component';
import { WikiListComponent } from './components/wiki-list/wiki-list.component';
import { WikiState } from './store';
import { WikiComponent } from './wiki.component';
import {
CompareSectionComponent,
EditSectionComponent,
ViewSectionComponent,
WikiListComponent,
} from '@shared/components/wiki';
import { WikiState } from '@shared/stores';

describe('WikiComponent', () => {
let component: WikiComponent;
Expand Down
1 change: 0 additions & 1 deletion src/app/features/registry/pages/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './registry-metadata/registry-metadata.component';
export * from './registry-metadata-add/registry-metadata-add.component';
export * from '@osf/features/registry/pages/registry-files/registry-files.component';
export * from '@osf/features/registry/pages/registry-overview/registry-overview.component';
export * from '@osf/features/registry/pages/registry-resources/registry-resources.component';
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { signal } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';

import { UserSettings } from '@osf/core/models';
import { UserSelectors } from '@osf/core/store/user';
import { LoaderService, ToastService } from '@osf/shared/services';
import { SubscriptionEvent, SubscriptionFrequency } from '@shared/enums';
import { MOCK_STORE, MOCK_USER } from '@shared/mocks';
import { UserSettings } from '@shared/models';

import { NotificationsComponent } from './notifications.component';
import { NotificationSubscriptionSelectors } from './store';
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 { MockPipe, MockProvider } from 'ng-mocks';
import { MockComponent, MockPipe, MockProvider } from 'ng-mocks';

import { DynamicDialogRef } from 'primeng/dynamicdialog';

Expand All @@ -13,8 +13,9 @@ import { FormControl, FormGroup, Validators } from '@angular/forms';
import { MY_PROJECTS_TABLE_PARAMS } from '@osf/shared/constants/my-projects-table.constants';
import { ProjectFormControls } from '@osf/shared/enums/create-project-form-controls.enum';
import { CustomValidators } from '@osf/shared/helpers';
import { IdName, ProjectForm } from '@osf/shared/models';
import { ProjectForm } from '@osf/shared/models';
import { GetMyProjects, InstitutionsState, MyResourcesState } from '@osf/shared/stores';
import { ProjectSelectorComponent } from '@shared/components';
import { RegionsState } from '@shared/stores/regions';

import { AddProjectFormComponent } from './add-project-form.component';
Expand All @@ -34,11 +35,6 @@ describe('AddProjectFormComponent', () => {
{ id: 'aff2', name: 'Affiliation 2', assets: { logo: 'logo2.png' } },
];

const mockTemplates: IdName[] = [
{ id: '1', name: 'Template 1' },
{ id: '2', name: 'Template 2' },
];

const createProjectForm = (): FormGroup<ProjectForm> => {
return new FormGroup<ProjectForm>({
[ProjectFormControls.Title]: new FormControl('', {
Expand Down Expand Up @@ -69,7 +65,7 @@ describe('AddProjectFormComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AddProjectFormComponent, MockPipe(TranslatePipe)],
imports: [AddProjectFormComponent, MockPipe(TranslatePipe), MockComponent(ProjectSelectorComponent)],
providers: [
provideStore([MyResourcesState, InstitutionsState, RegionsState]),
provideHttpClient(),
Expand All @@ -85,7 +81,6 @@ describe('AddProjectFormComponent', () => {
fixture = TestBed.createComponent(AddProjectFormComponent);
component = fixture.componentInstance;

fixture.componentRef.setInput('templates', mockTemplates);
fixture.componentRef.setInput('projectForm', createProjectForm());

fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,125 @@ describe('AddonTermsComponent', () => {
expect(term.status).not.toContain('{provider}');
});
});

it('should show all terms when isCitationService is false', () => {
const regularAddon: Addon = {
...mockAddon,
supportedFeatures: ['STORAGE', 'FORKING'],
};

mockIsCitationAddon.mockReturnValue(false);
fixture.componentRef.setInput('addon', regularAddon);

const terms = (component as any).terms();

expect(terms.length).toBeGreaterThan(0);

const allTerms = (component as any).getAddonTerms(regularAddon);
expect(terms.length).toBe(allTerms.length);
});

it('should handle citation service without required features', () => {
const citationAddonWithoutFeatures: Addon = {
...mockAddon,
supportedFeatures: [],
};

mockIsCitationAddon.mockReturnValue(true);
fixture.componentRef.setInput('addon', citationAddonWithoutFeatures);

const terms = (component as any).terms();

expect(terms.length).toBeGreaterThan(0);

const hasDangerTerm = terms.some((term: AddonTerm) => term.type === 'danger');
expect(hasDangerTerm).toBe(true);
});

it('should handle citation service with full features', () => {
const citationAddonWithFullFeatures: Addon = {
...mockAddon,
supportedFeatures: ['STORAGE', 'FORKING'],
};

mockIsCitationAddon.mockReturnValue(true);
fixture.componentRef.setInput('addon', citationAddonWithFullFeatures);

const terms = (component as any).terms();

expect(terms.length).toBeGreaterThan(0);

const hasInfoTerm = terms.some((term: AddonTerm) => term.type === 'info');
expect(hasInfoTerm).toBe(true);
});

it('should handle null addon input', () => {
fixture.componentRef.setInput('addon', null);

const terms = (component as any).terms();

expect(terms).toEqual([]);
});

it('should handle undefined addon input', () => {
fixture.componentRef.setInput('addon', undefined);

const terms = (component as any).terms();

expect(terms).toEqual([]);
});

it('should handle addon with empty supportedFeatures', () => {
const addonWithEmptyFeatures: Addon = {
...mockAddon,
supportedFeatures: [],
};

mockIsCitationAddon.mockReturnValue(false);
fixture.componentRef.setInput('addon', addonWithEmptyFeatures);

const terms = (component as any).terms();

expect(terms.length).toBeGreaterThan(0);

terms.forEach((term: AddonTerm) => {
expect(term.type).toBe('danger');
});
});

it('should handle addon with partial features only', () => {
const addonWithPartialOnly: Addon = {
...mockAddon,
supportedFeatures: ['STORAGE_PARTIAL', 'FORKING_PARTIAL'],
};

mockIsCitationAddon.mockReturnValue(false);
fixture.componentRef.setInput('addon', addonWithPartialOnly);

const terms = (component as any).terms();

expect(terms.length).toBeGreaterThan(0);

const hasWarningTerm = terms.some((term: AddonTerm) => term.type === 'warning');
expect(hasWarningTerm).toBe(true);
});

it('should handle addon with mixed features (full, partial, none)', () => {
const addonWithMixedFeatures: Addon = {
...mockAddon,
supportedFeatures: ['STORAGE', 'FORKING_PARTIAL'],
};
mockIsCitationAddon.mockReturnValue(false);
fixture.componentRef.setInput('addon', addonWithMixedFeatures);

const terms = (component as any).terms();

expect(terms.length).toBeGreaterThan(0);

const hasInfoTerm = terms.some((term: AddonTerm) => term.type === 'info');
const hasWarningTerm = terms.some((term: AddonTerm) => term.type === 'warning');
const hasDangerTerm = terms.some((term: AddonTerm) => term.type === 'danger');

expect(hasInfoTerm || hasWarningTerm || hasDangerTerm).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,12 @@ describe('ContributorsListComponent', () => {
id: 'minimal-id',
userId: 'minimal-user-id',
type: 'user',
isBibliographic: true,
isCurator: true,
fullName: 'Minimal User',
givenName: 'Minimal User',
familyName: 'Minimal User',
permission: 'read',
isBibliographic: false,
isCurator: false,
education: [],
employment: [],
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { MockProvider } from 'ng-mocks';

import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog';

import { ComponentFixture, TestBed } from '@angular/core/testing';

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

import { EducationHistoryDialogComponent } from './education-history-dialog.component';

describe('EducationHistoryDialogComponent', () => {
Expand All @@ -9,6 +15,7 @@ describe('EducationHistoryDialogComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [EducationHistoryDialogComponent],
providers: [MockProvider(DynamicDialogRef), MockProvider(DynamicDialogConfig), TranslateServiceMock],
}).compileComponents();

fixture = TestBed.createComponent(EducationHistoryDialogComponent);
Expand All @@ -19,4 +26,11 @@ describe('EducationHistoryDialogComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

it('should call close method successfully', () => {
const dialogRef = TestBed.inject(DynamicDialogRef);
jest.spyOn(dialogRef, 'close');
component.close();
expect(dialogRef.close).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { MockProvider } from 'ng-mocks';

import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog';

import { ComponentFixture, TestBed } from '@angular/core/testing';

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

import { EmploymentHistoryDialogComponent } from './employment-history-dialog.component';

describe('EmploymentHistoryDialogComponent', () => {
Expand All @@ -9,6 +15,7 @@ describe('EmploymentHistoryDialogComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [EmploymentHistoryDialogComponent],
providers: [MockProvider(DynamicDialogRef), MockProvider(DynamicDialogConfig), TranslateServiceMock],
}).compileComponents();

fixture = TestBed.createComponent(EmploymentHistoryDialogComponent);
Expand All @@ -19,4 +26,11 @@ describe('EmploymentHistoryDialogComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

it('should call close method successfully', () => {
const dialogRef = TestBed.inject(DynamicDialogRef);
jest.spyOn(dialogRef, 'close');
component.close();
expect(dialogRef.close).toHaveBeenCalledTimes(1);
});
});
Loading