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
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ module.exports = {
'<rootDir>/src/app/features/project/addons/',
'<rootDir>/src/app/features/project/overview/',
'<rootDir>/src/app/features/project/registrations',
'<rootDir>/src/app/features/project/settings',
'<rootDir>/src/app/features/project/wiki',
'<rootDir>/src/app/features/registries/',
'<rootDir>/src/app/features/registry/',
Expand Down
3 changes: 3 additions & 0 deletions src/app/core/components/root/root.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { SidenavComponent } from '../sidenav/sidenav.component';

import { RootComponent } from './root.component';

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

describe('RootComponent', () => {
let component: RootComponent;
let fixture: ComponentFixture<RootComponent>;
Expand All @@ -30,6 +32,7 @@ describe('RootComponent', () => {
await TestBed.configureTestingModule({
imports: [
RootComponent,
OSFTestingModule,
...MockComponents(
HeaderComponent,
FooterComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
import { MockComponent } from 'ng-mocks';

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

import { SelectComponent } from '@shared/components';

import { ProjectDetailSettingAccordionComponent } from './project-detail-setting-accordion.component';

describe('AccordionTableComponent', () => {
import { OSFTestingModule } from '@testing/osf.testing.module';

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

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ProjectDetailSettingAccordionComponent],
imports: [ProjectDetailSettingAccordionComponent, OSFTestingModule, MockComponent(SelectComponent)],
}).compileComponents();

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

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

it('should initialize with expanded set to false', () => {
expect(component.expanded()).toBe(false);
});

it('should toggle expanded state when toggle() is called', () => {
expect(component.expanded()).toBe(false);

component.toggle();
expect(component.expanded()).toBe(true);

component.toggle();
expect(component.expanded()).toBe(false);
});
});
Original file line number Diff line number Diff line change
@@ -1,22 +1,117 @@
import { MockComponent, MockPipe } from 'ng-mocks';

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

import { ProjectDetailSettingAccordionComponent } from '@osf/features/project/settings/components';
import { NotificationDescriptionPipe } from '@osf/features/project/settings/pipes';
import { SubscriptionEvent, SubscriptionFrequency } from '@osf/shared/enums';
import { MOCK_NOTIFICATION_SUBSCRIPTIONS } from '@osf/shared/mocks';

import { ProjectSettingNotificationsComponent } from './project-setting-notifications.component';

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

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

const mockNotifications = MOCK_NOTIFICATION_SUBSCRIPTIONS;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ProjectSettingNotificationsComponent],
imports: [
ProjectSettingNotificationsComponent,
OSFTestingModule,
MockComponent(ProjectDetailSettingAccordionComponent),
MockPipe(NotificationDescriptionPipe),
],
}).compileComponents();

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

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

it('should initialize with empty accordion data', () => {
expect(component.allAccordionData).toEqual([]);
});

it('should have correct subscription frequency options', () => {
const expectedOptions = [
{ label: 'Never', value: SubscriptionFrequency.Never },
{ label: 'Daily', value: SubscriptionFrequency.Daily },
{ label: 'Instant', value: SubscriptionFrequency.Instant },
];

expect(component.subscriptionFrequencyOptions).toEqual(expectedOptions);
});

it('should update accordion data when notifications input changes', () => {
fixture.componentRef.setInput('notifications', mockNotifications);
fixture.detectChanges();

expect(component.allAccordionData).toBeDefined();
expect(component.allAccordionData?.length).toBe(4);

if (component.allAccordionData) {
expect(component.allAccordionData[0]).toEqual({
label: 'settings.notifications.notificationPreferences.items.files',
value: SubscriptionFrequency.Instant,
type: 'dropdown',
options: component.subscriptionFrequencyOptions,
event: SubscriptionEvent.FileUpdated,
});

expect(component.allAccordionData[1]).toEqual({
label: 'settings.notifications.notificationPreferences.items.files',
value: SubscriptionFrequency.Daily,
type: 'dropdown',
options: component.subscriptionFrequencyOptions,
event: SubscriptionEvent.GlobalFileUpdated,
});
}
});

it('should emit notification value change when changeEmittedValue is called', () => {
jest.spyOn(component.notificationEmitValue, 'emit');
fixture.componentRef.setInput('notifications', mockNotifications);
fixture.detectChanges();

const emittedValue = { index: 0, value: SubscriptionFrequency.Never };
component.changeEmittedValue(emittedValue);

expect(component.notificationEmitValue.emit).toHaveBeenCalledWith({
id: mockNotifications[0].id,
event: SubscriptionEvent.FileUpdated,
frequency: SubscriptionFrequency.Never,
});
});

it('should not emit when allAccordionData is undefined', () => {
jest.spyOn(component.notificationEmitValue, 'emit');
component.allAccordionData = undefined;

const emittedValue = { index: 0, value: SubscriptionFrequency.Never };
component.changeEmittedValue(emittedValue);

expect(component.notificationEmitValue.emit).not.toHaveBeenCalled();
});

it('should handle multiple notifications correctly', () => {
const multipleNotifications = MOCK_NOTIFICATION_SUBSCRIPTIONS.slice(0, 3);

fixture.componentRef.setInput('notifications', multipleNotifications);
fixture.detectChanges();

expect(component.allAccordionData?.length).toBe(3);

if (component.allAccordionData) {
expect(component.allAccordionData[0].event).toBe(SubscriptionEvent.FileUpdated);
expect(component.allAccordionData[1].event).toBe(SubscriptionEvent.GlobalFileUpdated);
expect(component.allAccordionData[2].event).toBe(SubscriptionEvent.GlobalMentions);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,43 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';

import { SettingsAccessRequestsCardComponent } from './settings-access-requests-card.component';

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

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

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

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

it('should create', () => {
fixture.componentRef.setInput('accessRequest', true);
fixture.detectChanges();
expect(component).toBeTruthy();
});

it('should initialize with accessRequest input', () => {
const testValue = true;
fixture.componentRef.setInput('accessRequest', testValue);
fixture.detectChanges();

expect(component.accessRequest()).toBe(testValue);
});

it('should emit accessRequestChange when checkbox value changes', () => {
jest.spyOn(component.accessRequestChange, 'emit');
fixture.componentRef.setInput('accessRequest', false);
fixture.detectChanges();

const newValue = true;
component.accessRequestChange.emit(newValue);

expect(component.accessRequestChange.emit).toHaveBeenCalledWith(newValue);
});
});
Original file line number Diff line number Diff line change
@@ -1,22 +1,54 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { Institution } from '@osf/shared/models';
import { MOCK_INSTITUTION } from '@shared/mocks';

import { SettingsProjectAffiliationComponent } from './settings-project-affiliation.component';

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

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

const mockInstitutions: Institution[] = [MOCK_INSTITUTION];

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

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

it('should create', () => {
fixture.componentRef.setInput('affiliations', []);
fixture.detectChanges();
expect(component).toBeTruthy();
});

it('should initialize with empty affiliations array', () => {
fixture.componentRef.setInput('affiliations', []);
fixture.detectChanges();

expect(component.affiliations()).toEqual([]);
});

it('should display affiliations when provided', () => {
fixture.componentRef.setInput('affiliations', mockInstitutions);
fixture.detectChanges();

expect(component.affiliations()).toEqual(mockInstitutions);
});

it('should emit removed event when removeAffiliation is called', () => {
jest.spyOn(component.removed, 'emit');
fixture.componentRef.setInput('affiliations', mockInstitutions);
fixture.detectChanges();

component.removeAffiliation(MOCK_INSTITUTION);

expect(component.removed.emit).toHaveBeenCalledWith(MOCK_INSTITUTION);
});
});
Loading
Loading