@@ -6,16 +6,13 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
66
77import { PreprintProviderDetails } from '@osf/features/preprints/models' ;
88import { PreprintSelectors } from '@osf/features/preprints/store/preprint' ;
9- import { IconComponent } from '@shared/components' ;
10- import { SocialShareLinks } from '@shared/models' ;
11- import { SocialShareService } from '@shared/services' ;
12- import { DataciteService } from '@shared/services/datacite/datacite.service' ;
9+ import { SocialsShareButtonComponent } from '@osf/shared/components' ;
10+ import { DataciteService } from '@osf/shared/services/datacite/datacite.service' ;
1311
1412import { ShareAndDownloadComponent } from './share-and-download.component' ;
1513
1614import { PREPRINT_MOCK } from '@testing/mocks/preprint.mock' ;
1715import { PREPRINT_PROVIDER_DETAILS_MOCK } from '@testing/mocks/preprint-provider-details' ;
18- import { SOCIAL_SHARE_LINKS_MOCK } from '@testing/mocks/social-share-links.mock' ;
1916import { TranslationServiceMock } from '@testing/mocks/translation.service.mock' ;
2017import { OSFTestingModule } from '@testing/osf.testing.module' ;
2118import { provideMockStore } from '@testing/providers/store-provider.mock' ;
@@ -24,39 +21,26 @@ describe('ShareAndDownloadComponent', () => {
2421 let component : ShareAndDownloadComponent ;
2522 let fixture : ComponentFixture < ShareAndDownloadComponent > ;
2623 let dataciteService : jest . Mocked < DataciteService > ;
27- let socialShareService : jest . Mocked < SocialShareService > ;
2824
2925 const mockPreprint = PREPRINT_MOCK ;
3026 const mockProvider : PreprintProviderDetails = PREPRINT_PROVIDER_DETAILS_MOCK ;
31- const mockShareLinks : SocialShareLinks = SOCIAL_SHARE_LINKS_MOCK ;
3227
3328 beforeEach ( async ( ) => {
3429 dataciteService = {
3530 logIdentifiableDownload : jest . fn ( ) . mockReturnValue ( of ( void 0 ) ) ,
3631 } as any ;
3732
38- socialShareService = {
39- createDownloadUrl : jest . fn ( ) . mockReturnValue ( 'https://example.com/download/preprint-1' ) ,
40- createPreprintUrl : jest . fn ( ) . mockReturnValue ( 'https://example.com/preprint/preprint-1' ) ,
41- generateAllSharingLinks : jest . fn ( ) . mockReturnValue ( mockShareLinks ) ,
42- } as any ;
43-
4433 await TestBed . configureTestingModule ( {
45- imports : [ ShareAndDownloadComponent , OSFTestingModule , MockComponent ( IconComponent ) ] ,
34+ imports : [ ShareAndDownloadComponent , OSFTestingModule , MockComponent ( SocialsShareButtonComponent ) ] ,
4635 providers : [
4736 TranslationServiceMock ,
4837 MockProvider ( DataciteService , dataciteService ) ,
49- MockProvider ( SocialShareService , socialShareService ) ,
5038 provideMockStore ( {
5139 signals : [
5240 {
5341 selector : PreprintSelectors . getPreprint ,
5442 value : mockPreprint ,
5543 } ,
56- {
57- selector : PreprintSelectors . isPreprintLoading ,
58- value : false ,
59- } ,
6044 ] ,
6145 } ) ,
6246 ] ,
@@ -77,85 +61,6 @@ describe('ShareAndDownloadComponent', () => {
7761 expect ( preprint ) . toBe ( mockPreprint ) ;
7862 } ) ;
7963
80- it ( 'should return preprint loading state from store' , ( ) => {
81- const loading = component . isPreprintLoading ( ) ;
82- expect ( loading ) . toBe ( false ) ;
83- } ) ;
84-
85- it ( 'should compute metrics from preprint' , ( ) => {
86- const metrics = component . metrics ( ) ;
87- expect ( metrics ) . toBe ( mockPreprint . metrics ) ;
88- } ) ;
89-
90- it ( 'should return null metrics when no preprint' , ( ) => {
91- jest . spyOn ( component , 'preprint' ) . mockReturnValue ( null ) ;
92- const metrics = component . metrics ( ) ;
93- expect ( metrics ) . toBeNull ( ) ;
94- } ) ;
95-
96- it ( 'should compute download link from preprint' , ( ) => {
97- const downloadLink = component . downloadLink ( ) ;
98- expect ( downloadLink ) . toBe ( 'https://example.com/download/preprint-1' ) ;
99- expect ( socialShareService . createDownloadUrl ) . toHaveBeenCalledWith ( 'preprint-1' ) ;
100- } ) ;
101-
102- it ( 'should return default download link when no preprint' , ( ) => {
103- jest . spyOn ( component , 'preprint' ) . mockReturnValue ( null ) ;
104- const downloadLink = component . downloadLink ( ) ;
105- expect ( downloadLink ) . toBe ( '#' ) ;
106- } ) ;
107-
108- it ( 'should return null shareable content when no preprint or provider' , ( ) => {
109- jest . spyOn ( component , 'preprint' ) . mockReturnValue ( null ) ;
110- const shareableContent = ( component as any ) . shareableContent ( ) ;
111- expect ( shareableContent ) . toBeNull ( ) ;
112- } ) ;
113-
114- it ( 'should compute share links from shareable content' , ( ) => {
115- const shareLinks = component . shareLinks ( ) ;
116- expect ( shareLinks ) . toBe ( mockShareLinks ) ;
117- expect ( socialShareService . generateAllSharingLinks ) . toHaveBeenCalled ( ) ;
118- } ) ;
119-
120- it ( 'should return null share links when no shareable content' , ( ) => {
121- jest . spyOn ( component as any , 'shareableContent' ) . mockReturnValue ( null ) ;
122- const shareLinks = component . shareLinks ( ) ;
123- expect ( shareLinks ) . toBeNull ( ) ;
124- } ) ;
125-
126- it ( 'should compute email share link' , ( ) => {
127- const emailLink = component . emailShareLink ( ) ;
128- expect ( emailLink ) . toBe ( mockShareLinks . email ) ;
129- } ) ;
130-
131- it ( 'should compute twitter share link' , ( ) => {
132- const twitterLink = component . twitterShareLink ( ) ;
133- expect ( twitterLink ) . toBe ( mockShareLinks . twitter ) ;
134- } ) ;
135-
136- it ( 'should compute facebook share link' , ( ) => {
137- const facebookLink = component . facebookShareLink ( ) ;
138- expect ( facebookLink ) . toBe ( mockShareLinks . facebook ) ;
139- } ) ;
140-
141- it ( 'should compute linkedIn share link' , ( ) => {
142- const linkedInLink = component . linkedInShareLink ( ) ;
143- expect ( linkedInLink ) . toBe ( mockShareLinks . linkedIn ) ;
144- } ) ;
145-
146- it ( 'should return empty string for share links when no share links' , ( ) => {
147- jest . spyOn ( component , 'shareLinks' ) . mockReturnValue ( null ) ;
148- expect ( component . emailShareLink ( ) ) . toBe ( '' ) ;
149- expect ( component . twitterShareLink ( ) ) . toBe ( '' ) ;
150- expect ( component . facebookShareLink ( ) ) . toBe ( '' ) ;
151- expect ( component . linkedInShareLink ( ) ) . toBe ( '' ) ;
152- } ) ;
153-
154- it ( 'should call dataciteService.logIdentifiableDownload when logDownload is called' , ( ) => {
155- component . logDownload ( ) ;
156- expect ( dataciteService . logIdentifiableDownload ) . toHaveBeenCalledWith ( component . preprint$ ) ;
157- } ) ;
158-
15964 it ( 'should handle preprint provider input' , ( ) => {
16065 const provider = component . preprintProvider ( ) ;
16166 expect ( provider ) . toBe ( mockProvider ) ;
0 commit comments