11import { Store } from '@ngxs/store' ;
22
3- import { TranslateModule } from '@ngx-translate/core' ;
4- import { MockComponent , MockModule , MockProvider } from 'ng-mocks' ;
5-
6- import { Button } from 'primeng/button' ;
3+ import { TranslatePipe , TranslateService } from '@ngx-translate/core' ;
4+ import { MockComponents , MockPipe , MockProvider } from 'ng-mocks' ;
75
86import { BehaviorSubject , of } from 'rxjs' ;
97
@@ -12,53 +10,21 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
1210import { By } from '@angular/platform-browser' ;
1311import { Router } from '@angular/router' ;
1412
15- import { IS_XSMALL } from '@osf/shared/utils' ;
16-
17- import { ResetFiltersState } from '../search/components/resource-filters/store' ;
18- import { SearchComponent } from '../search/search.component' ;
19- import { ResetSearchState } from '../search/store' ;
13+ import { EducationHistoryComponent , EmploymentHistoryComponent } from '@osf/shared/components' ;
14+ import { MOCK_USER } from '@osf/shared/mocks' ;
15+ import { IS_MEDIUM } from '@osf/shared/utils' ;
2016
17+ import { MyProfileSearchComponent } from './components' ;
2118import { MyProfileComponent } from './my-profile.component' ;
22- import { SetIsMyProfile } from './store' ;
2319
2420describe ( 'MyProfileComponent' , ( ) => {
2521 let component : MyProfileComponent ;
2622 let fixture : ComponentFixture < MyProfileComponent > ;
2723 let store : Partial < Store > ;
2824 let router : Partial < Router > ;
29- let isXSmallSubject : BehaviorSubject < boolean > ;
25+ let isMediumSubject : BehaviorSubject < boolean > ;
3026
31- const mockUser = {
32- id : '1' ,
33- fullName : 'John Doe' ,
34- email : 'john@example.com' ,
35- givenName : 'John' ,
36- familyName : 'Doe' ,
37- middleNames : '' ,
38- suffix : '' ,
39- dateRegistered : '2024-01-01' ,
40- employment : [
41- {
42- title : 'Software Engineer' ,
43- institution : 'Tech Corp' ,
44- startDate : '2020-01-01' ,
45- endDate : null ,
46- } ,
47- ] ,
48- education : [
49- {
50- degree : 'Bachelor of Science' ,
51- institution : 'University of Technology' ,
52- startDate : '2016-01-01' ,
53- endDate : '2020-01-01' ,
54- ongoing : false ,
55- } ,
56- ] ,
57- socials : {
58- orcid : '0000-0000-0000-0000' ,
59- } ,
60- link : 'https://example.com/profile' ,
61- } ;
27+ const mockUser = MOCK_USER ;
6228
6329 beforeEach ( async ( ) => {
6430 store = {
@@ -70,14 +36,19 @@ describe('MyProfileComponent', () => {
7036 navigate : jest . fn ( ) ,
7137 } ;
7238
73- isXSmallSubject = new BehaviorSubject < boolean > ( false ) ;
39+ isMediumSubject = new BehaviorSubject < boolean > ( false ) ;
7440
7541 await TestBed . configureTestingModule ( {
76- imports : [ MyProfileComponent , MockModule ( TranslateModule ) , MockComponent ( Button ) , MockComponent ( SearchComponent ) ] ,
42+ imports : [
43+ MyProfileComponent ,
44+ MockPipe ( TranslatePipe ) ,
45+ ...MockComponents ( MyProfileSearchComponent , EducationHistoryComponent , EmploymentHistoryComponent ) ,
46+ ] ,
7747 providers : [
7848 MockProvider ( Store , store ) ,
7949 MockProvider ( Router , router ) ,
80- { provide : IS_XSMALL , useValue : isXSmallSubject } ,
50+ MockProvider ( TranslateService ) ,
51+ MockProvider ( IS_MEDIUM , isMediumSubject ) ,
8152 ] ,
8253 } ) . compileComponents ( ) ;
8354
@@ -95,24 +66,8 @@ describe('MyProfileComponent', () => {
9566 expect ( router . navigate ) . toHaveBeenCalledWith ( [ 'settings/profile-settings' ] ) ;
9667 } ) ;
9768
98- it ( 'should handle mobile view correctly' , ( ) => {
99- isXSmallSubject . next ( true ) ;
100- fixture . detectChanges ( ) ;
101-
102- const compiled = fixture . nativeElement ;
103- const editButton = compiled . querySelector ( '.btn-full-width' ) ;
104- expect ( editButton ) . toBeTruthy ( ) ;
105- } ) ;
106-
107- it ( 'should clean up store state on destroy' , ( ) => {
108- component . ngOnDestroy ( ) ;
109- expect ( store . dispatch ) . toHaveBeenCalledWith ( ResetFiltersState ) ;
110- expect ( store . dispatch ) . toHaveBeenCalledWith ( ResetSearchState ) ;
111- expect ( store . dispatch ) . toHaveBeenCalledWith ( new SetIsMyProfile ( false ) ) ;
112- } ) ;
113-
11469 it ( 'should render search component' , ( ) => {
115- const searchComponent = fixture . debugElement . query ( By . directive ( SearchComponent ) ) ;
70+ const searchComponent = fixture . debugElement . query ( By . directive ( MyProfileSearchComponent ) ) ;
11671 expect ( searchComponent ) . toBeTruthy ( ) ;
11772 } ) ;
11873} ) ;
0 commit comments