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 @@ -10,6 +10,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideNoopAnimations } from '@angular/platform-browser/animations';
import { ActivatedRoute, Router } from '@angular/router';

import { HelpScoutService } from '@core/services/help-scout.service';
import { AdditionalInfoComponent } from '@osf/features/preprints/components/preprint-details/additional-info/additional-info.component';
import { GeneralInformationComponent } from '@osf/features/preprints/components/preprint-details/general-information/general-information.component';
import { PreprintFileSectionComponent } from '@osf/features/preprints/components/preprint-details/preprint-file-section/preprint-file-section.component';
Expand All @@ -24,9 +25,10 @@ import { PreprintDetailsComponent } from './preprint-details.component';

import { DataciteMockFactory } from '@testing/mocks/datacite.service.mock';

describe('PreprintDetailsComponent', () => {
describe('Component: Preprint Details', () => {
let component: PreprintDetailsComponent;
let fixture: ComponentFixture<PreprintDetailsComponent>;
let helpScountService: HelpScoutService;

let dataciteService: jest.Mocked<DataciteService>;

Expand Down Expand Up @@ -73,14 +75,30 @@ describe('PreprintDetailsComponent', () => {
MockProvider(ActivatedRoute, mockRoute),
TranslateServiceMock,
MockProvider(MetaTagsService),
{
provide: HelpScoutService,
useValue: {
setResourceType: jest.fn(),
unsetResourceType: jest.fn(),
},
},
],
}).compileComponents();

helpScountService = TestBed.inject(HelpScoutService);
fixture = TestBed.createComponent(PreprintDetailsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should have a default value', () => {
expect(component.classes).toBe('');
});

it('should called the helpScoutService', () => {
expect(helpScountService.setResourceType).toHaveBeenCalledWith('preprint');
});

it('isOsfPreprint should be true if providerId === osf', () => {
expect(component.isOsfPreprint()).toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import { takeUntilDestroyed, toObservable, toSignal } from '@angular/core/rxjs-interop';
import { ActivatedRoute, Router } from '@angular/router';

import { HelpScoutService } from '@core/services/help-scout.service';
import { ClearCurrentProvider } from '@core/store/provider';
import { UserSelectors } from '@core/store/user';
import {
Expand Down Expand Up @@ -80,6 +81,7 @@ import { environment } from 'src/environments/environment';
export class PreprintDetailsComponent implements OnInit, OnDestroy {
@HostBinding('class') classes = 'flex-1 flex flex-column w-full';

private readonly helpScoutService = inject(HelpScoutService);
private readonly router = inject(Router);
private readonly route = inject(ActivatedRoute);
private readonly location = inject(Location);
Expand Down Expand Up @@ -148,6 +150,10 @@ export class PreprintDetailsComponent implements OnInit, OnDestroy {
return actions[0];
});

constructor() {
this.helpScoutService.setResourceType('preprint');
}

private currentUserIsAdmin = computed(() => {
return this.preprint()?.currentUserPermissions.includes(UserPermissions.Admin) || false;
});
Expand Down Expand Up @@ -292,6 +298,7 @@ export class PreprintDetailsComponent implements OnInit, OnDestroy {
ngOnDestroy() {
this.actions.resetState();
this.actions.clearCurrentProvider();
this.helpScoutService.unsetResourceType();
}

fetchPreprintVersion(preprintVersionId: string) {
Expand Down