From dc600f3ca82d4e579f37229b7d1877f69fc540ce Mon Sep 17 00:00:00 2001 From: Brian Pilati Date: Tue, 16 Sep 2025 11:48:32 -0500 Subject: [PATCH] fix(helpscout): added the help-scout to the preprint-details page --- .../preprint-details.component.spec.ts | 20 ++++++++++++++++++- .../preprint-details.component.ts | 7 +++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/app/features/preprints/pages/preprint-details/preprint-details.component.spec.ts b/src/app/features/preprints/pages/preprint-details/preprint-details.component.spec.ts index 10dfb5eb4..e94ed966e 100644 --- a/src/app/features/preprints/pages/preprint-details/preprint-details.component.spec.ts +++ b/src/app/features/preprints/pages/preprint-details/preprint-details.component.spec.ts @@ -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'; @@ -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; + let helpScountService: HelpScoutService; let dataciteService: jest.Mocked; @@ -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(); }); diff --git a/src/app/features/preprints/pages/preprint-details/preprint-details.component.ts b/src/app/features/preprints/pages/preprint-details/preprint-details.component.ts index 9b3a8903d..372215ad6 100644 --- a/src/app/features/preprints/pages/preprint-details/preprint-details.component.ts +++ b/src/app/features/preprints/pages/preprint-details/preprint-details.component.ts @@ -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 { @@ -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); @@ -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; }); @@ -292,6 +298,7 @@ export class PreprintDetailsComponent implements OnInit, OnDestroy { ngOnDestroy() { this.actions.resetState(); this.actions.clearCurrentProvider(); + this.helpScoutService.unsetResourceType(); } fetchPreprintVersion(preprintVersionId: string) {