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
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';

import { CedarMetadataHelper } from '@osf/features/metadata/helpers';
import { CedarMetadataDataTemplateJsonApi } from '@osf/features/metadata/models';
import { CEDAR_METADATA_DATA_TEMPLATE_JSON_API_MOCK, TranslateServiceMock } from '@shared/mocks';
import { CEDAR_METADATA_DATA_TEMPLATE_JSON_API_MOCK } from '@shared/mocks';

import { CedarTemplateFormComponent } from './cedar-template-form.component';

import { OSFTestingModule } from '@testing/osf.testing.module';

describe('CedarTemplateFormComponent', () => {
let component: CedarTemplateFormComponent;
let fixture: ComponentFixture<CedarTemplateFormComponent>;
Expand All @@ -14,8 +16,7 @@ describe('CedarTemplateFormComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [CedarTemplateFormComponent],
providers: [TranslateServiceMock],
imports: [CedarTemplateFormComponent, OSFTestingModule],
}).compileComponents();

fixture = TestBed.createComponent(CedarTemplateFormComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { MockComponent } from 'ng-mocks';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { AffiliatedInstitutionsViewComponent } from '@osf/shared/components';
import { MOCK_PROJECT_AFFILIATED_INSTITUTIONS, TranslateServiceMock } from '@osf/shared/mocks';
import { MOCK_PROJECT_AFFILIATED_INSTITUTIONS } from '@osf/shared/mocks';

import { MetadataAffiliatedInstitutionsComponent } from './metadata-affiliated-institutions.component';

import { OSFTestingModule } from '@testing/osf.testing.module';

describe('MetadataAffiliatedInstitutionsComponent', () => {
let component: MetadataAffiliatedInstitutionsComponent;
let fixture: ComponentFixture<MetadataAffiliatedInstitutionsComponent>;
Expand All @@ -15,8 +17,11 @@ describe('MetadataAffiliatedInstitutionsComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MetadataAffiliatedInstitutionsComponent, MockComponent(AffiliatedInstitutionsViewComponent)],
providers: [TranslateServiceMock],
imports: [
MetadataAffiliatedInstitutionsComponent,
MockComponent(AffiliatedInstitutionsViewComponent),
OSFTestingModule,
],
}).compileComponents();

fixture = TestBed.createComponent(MetadataAffiliatedInstitutionsComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@ import { ActivatedRoute } from '@angular/router';

import { ContributorsListComponent } from '@osf/shared/components';
import { ContributorModel } from '@osf/shared/models';
import { MOCK_CONTRIBUTOR, TranslateServiceMock } from '@shared/mocks';
import { MOCK_CONTRIBUTOR } from '@shared/mocks';

import { MetadataContributorsComponent } from './metadata-contributors.component';

import { OSFTestingModule } from '@testing/osf.testing.module';
import { ActivatedRouteMockBuilder } from '@testing/providers/route-provider.mock';

describe('MetadataContributorsComponent', () => {
let component: MetadataContributorsComponent;
let fixture: ComponentFixture<MetadataContributorsComponent>;

let activatedRouteMock: ReturnType<ActivatedRouteMockBuilder['build']>;
const mockContributors: ContributorModel[] = [MOCK_CONTRIBUTOR];

beforeEach(async () => {
activatedRouteMock = ActivatedRouteMockBuilder.create().build();

await TestBed.configureTestingModule({
imports: [MetadataContributorsComponent, MockComponent(ContributorsListComponent)],
providers: [TranslateServiceMock, MockProvider(ActivatedRoute)],
imports: [MetadataContributorsComponent, MockComponent(ContributorsListComponent), OSFTestingModule],
providers: [MockProvider(ActivatedRoute, activatedRouteMock)],
}).compileComponents();

fixture = TestBed.createComponent(MetadataContributorsComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,86 @@ describe('MetadataDateInfoComponent', () => {

fixture = TestBed.createComponent(MetadataDateInfoComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should initialize with default values', () => {
expect(component.dateCreated()).toBe('');
expect(component.dateModified()).toBe('');
expect(component.dateFormat).toBe('MMM d, y, h:mm a');
});

it('should set dateCreated input', () => {
const mockDate = '2024-01-15T10:30:00Z';
fixture.componentRef.setInput('dateCreated', mockDate);
fixture.detectChanges();

expect(component.dateCreated()).toBe(mockDate);
});

it('should set dateModified input', () => {
const mockDate = '2024-01-20T14:45:00Z';
fixture.componentRef.setInput('dateModified', mockDate);
fixture.detectChanges();

expect(component.dateModified()).toBe(mockDate);
});

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

expect(component.dateCreated()).toBeUndefined();
});

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

expect(component.dateModified()).toBeUndefined();
});

it('should render dateCreated in template', () => {
const mockDate = '2024-01-15T10:30:00Z';
fixture.componentRef.setInput('dateCreated', mockDate);
fixture.detectChanges();

const compiled = fixture.nativeElement;
const dateCreatedElement = compiled.querySelector('p');
expect(dateCreatedElement).toBeTruthy();
});

it('should render dateModified in template', () => {
const mockDate = '2024-01-20T14:45:00Z';
fixture.componentRef.setInput('dateModified', mockDate);
fixture.detectChanges();

const compiled = fixture.nativeElement;
const dateElements = compiled.querySelectorAll('p');
expect(dateElements.length).toBeGreaterThan(0);
});

it('should display translated labels', () => {
fixture.detectChanges();

const compiled = fixture.nativeElement;
const headings = compiled.querySelectorAll('h2');
expect(headings.length).toBe(2);
});

it('should handle empty date strings', () => {
fixture.componentRef.setInput('dateCreated', '');
fixture.componentRef.setInput('dateModified', '');
fixture.detectChanges();

expect(component.dateCreated()).toBe('');
expect(component.dateModified()).toBe('');
});

it('should use correct date format', () => {
expect(component.dateFormat).toBe('MMM d, y, h:mm a');
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

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

import { MetadataDescriptionComponent } from './metadata-description.component';

import { OSFTestingModule } from '@testing/osf.testing.module';

describe('MetadataDescriptionComponent', () => {
let component: MetadataDescriptionComponent;
let fixture: ComponentFixture<MetadataDescriptionComponent>;
Expand All @@ -12,8 +12,7 @@ describe('MetadataDescriptionComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MetadataDescriptionComponent],
providers: [TranslateServiceMock],
imports: [MetadataDescriptionComponent, OSFTestingModule],
}).compileComponents();

fixture = TestBed.createComponent(MetadataDescriptionComponent);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { Funder } from '@osf/features/metadata/models';
import { MOCK_FUNDERS, TranslateServiceMock } from '@shared/mocks';
import { MOCK_FUNDERS } from '@shared/mocks';

import { MetadataFundingComponent } from './metadata-funding.component';

import { OSFTestingModule } from '@testing/osf.testing.module';

describe('MetadataFundingComponent', () => {
let component: MetadataFundingComponent;
let fixture: ComponentFixture<MetadataFundingComponent>;
Expand All @@ -13,8 +15,7 @@ describe('MetadataFundingComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MetadataFundingComponent],
providers: [TranslateServiceMock],
imports: [MetadataFundingComponent, OSFTestingModule],
}).compileComponents();

fixture = TestBed.createComponent(MetadataFundingComponent);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

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

import { MetadataLicenseComponent } from './metadata-license.component';

import { OSFTestingModule } from '@testing/osf.testing.module';

describe('MetadataLicenseComponent', () => {
let component: MetadataLicenseComponent;
let fixture: ComponentFixture<MetadataLicenseComponent>;
Expand All @@ -12,8 +14,7 @@ describe('MetadataLicenseComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MetadataLicenseComponent],
providers: [TranslateServiceMock],
imports: [MetadataLicenseComponent, OSFTestingModule],
}).compileComponents();

fixture = TestBed.createComponent(MetadataLicenseComponent);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { MOCK_PROJECT_IDENTIFIERS, TranslateServiceMock } from '@osf/shared/mocks';
import { MOCK_PROJECT_IDENTIFIERS } from '@osf/shared/mocks';
import { Identifier } from '@osf/shared/models';

import { MetadataPublicationDoiComponent } from './metadata-publication-doi.component';

import { OSFTestingModule } from '@testing/osf.testing.module';

describe('MetadataPublicationDoiComponent', () => {
let component: MetadataPublicationDoiComponent;
let fixture: ComponentFixture<MetadataPublicationDoiComponent>;
Expand All @@ -13,8 +15,7 @@ describe('MetadataPublicationDoiComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MetadataPublicationDoiComponent],
providers: [TranslateServiceMock],
imports: [MetadataPublicationDoiComponent, OSFTestingModule],
}).compileComponents();

fixture = TestBed.createComponent(MetadataPublicationDoiComponent);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

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

import { MetadataRegistrationDoiComponent } from './metadata-registration-doi.component';

import { OSFTestingModule } from '@testing/osf.testing.module';

describe('MetadataRegistrationDoiComponent', () => {
let component: MetadataRegistrationDoiComponent;
let fixture: ComponentFixture<MetadataRegistrationDoiComponent>;

const mockIdentifiers: Identifier[] = [MOCK_PROJECT_IDENTIFIERS];

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MetadataRegistrationDoiComponent],
providers: [TranslateServiceMock],
imports: [MetadataRegistrationDoiComponent, OSFTestingModule],
}).compileComponents();

fixture = TestBed.createComponent(MetadataRegistrationDoiComponent);
Expand All @@ -21,4 +25,54 @@ describe('MetadataRegistrationDoiComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

it('should initialize with default values', () => {
expect(component.identifiers()).toEqual([]);
expect(component.doiHost).toBe('https://doi.org/');
});

it('should set identifiers input', () => {
fixture.componentRef.setInput('identifiers', mockIdentifiers);
fixture.detectChanges();

expect(component.identifiers()).toEqual(mockIdentifiers);
});

it('should compute registrationDoi correctly with identifiers', () => {
fixture.componentRef.setInput('identifiers', mockIdentifiers);
fixture.detectChanges();

const expectedDoi = component.doiHost + mockIdentifiers[0].value;
expect(component.registrationDoi()).toBe(expectedDoi);
});

it('should compute registrationDoi as empty string when identifiers is undefined', () => {
fixture.componentRef.setInput('identifiers', undefined);
fixture.detectChanges();

expect(component.registrationDoi()).toBe('');
});

it('should render DOI link in template', () => {
fixture.componentRef.setInput('identifiers', mockIdentifiers);
fixture.detectChanges();

const compiled = fixture.nativeElement;
const linkElement = compiled.querySelector('a');
expect(linkElement).toBeTruthy();
expect(linkElement.getAttribute('href')).toBe(component.registrationDoi());
expect(linkElement.getAttribute('target')).toBe('_blank');
});

it('should display translated label', () => {
fixture.detectChanges();

const compiled = fixture.nativeElement;
const heading = compiled.querySelector('h2');
expect(heading).toBeTruthy();
});

it('should use correct DOI host', () => {
expect(component.doiHost).toBe('https://doi.org/');
});
});
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { CustomItemMetadataRecord } from '@osf/features/metadata/models';
import { TranslateServiceMock } from '@shared/mocks';

import { MetadataResourceInformationComponent } from './metadata-resource-information.component';

import { OSFTestingModule } from '@testing/osf.testing.module';

describe('MetadataResourceInformationComponent', () => {
let component: MetadataResourceInformationComponent;
let fixture: ComponentFixture<MetadataResourceInformationComponent>;
Expand All @@ -17,8 +18,7 @@ describe('MetadataResourceInformationComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MetadataResourceInformationComponent],
providers: [TranslateServiceMock],
imports: [MetadataResourceInformationComponent, OSFTestingModule],
}).compileComponents();

fixture = TestBed.createComponent(MetadataResourceInformationComponent);
Expand Down
Loading
Loading