1- import { MockComponents } from 'ng-mocks' ;
1+ import { MockComponents , MockProvider } from 'ng-mocks' ;
2+
3+ import { of } from 'rxjs' ;
24
35import { ComponentFixture , TestBed } from '@angular/core/testing' ;
46
5- import { EducationHistoryComponent , EmploymentHistoryComponent } from '@osf/shared/components' ;
7+ import { IS_MEDIUM } from '@osf/shared/helpers' ;
8+ import { SocialModel , UserModel } from '@osf/shared/models' ;
9+ import { EducationHistoryComponent , EmploymentHistoryComponent } from '@shared/components' ;
10+ import { MOCK_USER } from '@shared/mocks' ;
611
712import { ProfileInformationComponent } from './profile-information.component' ;
813
14+ import { MOCK_EDUCATION , MOCK_EMPLOYMENT } from '@testing/mocks/user-employment-education.mock' ;
915import { OSFTestingModule } from '@testing/osf.testing.module' ;
1016
1117describe ( 'ProfileInformationComponent' , ( ) => {
1218 let component : ProfileInformationComponent ;
1319 let fixture : ComponentFixture < ProfileInformationComponent > ;
1420
21+ const mockUser : UserModel = MOCK_USER ;
22+
1523 beforeEach ( async ( ) => {
1624 await TestBed . configureTestingModule ( {
1725 imports : [
1826 ProfileInformationComponent ,
19- ...MockComponents ( EmploymentHistoryComponent , EducationHistoryComponent ) ,
2027 OSFTestingModule ,
28+ ...MockComponents ( EmploymentHistoryComponent , EducationHistoryComponent ) ,
2129 ] ,
30+ providers : [ MockProvider ( IS_MEDIUM , of ( false ) ) ] ,
2231 } ) . compileComponents ( ) ;
2332
2433 fixture = TestBed . createComponent ( ProfileInformationComponent ) ;
@@ -29,4 +38,145 @@ describe('ProfileInformationComponent', () => {
2938 it ( 'should create' , ( ) => {
3039 expect ( component ) . toBeTruthy ( ) ;
3140 } ) ;
41+
42+ it ( 'should initialize with default inputs' , ( ) => {
43+ expect ( component . currentUser ( ) ) . toBeUndefined ( ) ;
44+ expect ( component . showEdit ( ) ) . toBe ( false ) ;
45+ } ) ;
46+
47+ it ( 'should accept user input' , ( ) => {
48+ fixture . componentRef . setInput ( 'currentUser' , mockUser ) ;
49+ fixture . detectChanges ( ) ;
50+ expect ( component . currentUser ( ) ) . toEqual ( mockUser ) ;
51+ } ) ;
52+
53+ it ( 'should accept showEdit input' , ( ) => {
54+ fixture . componentRef . setInput ( 'showEdit' , true ) ;
55+ fixture . detectChanges ( ) ;
56+ expect ( component . showEdit ( ) ) . toBe ( true ) ;
57+ } ) ;
58+
59+ it ( 'should return true when user has employment' , ( ) => {
60+ fixture . componentRef . setInput ( 'currentUser' , {
61+ ...mockUser ,
62+ employment : MOCK_EMPLOYMENT ,
63+ education : [ ] ,
64+ } ) ;
65+ fixture . detectChanges ( ) ;
66+ expect ( component . isEmploymentAndEducationVisible ( ) ) . toBeTruthy ( ) ;
67+ } ) ;
68+
69+ it ( 'should return true when user has education' , ( ) => {
70+ fixture . componentRef . setInput ( 'currentUser' , {
71+ ...mockUser ,
72+ employment : [ ] ,
73+ education : MOCK_EDUCATION ,
74+ } ) ;
75+ fixture . detectChanges ( ) ;
76+ expect ( component . isEmploymentAndEducationVisible ( ) ) . toBeTruthy ( ) ;
77+ } ) ;
78+
79+ it ( 'should return true when user has both employment and education' , ( ) => {
80+ fixture . componentRef . setInput ( 'currentUser' , mockUser ) ;
81+ fixture . detectChanges ( ) ;
82+ expect ( component . isEmploymentAndEducationVisible ( ) ) . toBeTruthy ( ) ;
83+ } ) ;
84+
85+ it ( 'should return falsy when user has neither employment nor education' , ( ) => {
86+ fixture . componentRef . setInput ( 'currentUser' , {
87+ ...mockUser ,
88+ employment : [ ] ,
89+ education : [ ] ,
90+ } ) ;
91+ fixture . detectChanges ( ) ;
92+ expect ( component . isEmploymentAndEducationVisible ( ) ) . toBeFalsy ( ) ;
93+ } ) ;
94+
95+ it ( 'should return falsy when currentUser is null' , ( ) => {
96+ fixture . componentRef . setInput ( 'currentUser' , null ) ;
97+ fixture . detectChanges ( ) ;
98+ expect ( component . isEmploymentAndEducationVisible ( ) ) . toBeFalsy ( ) ;
99+ } ) ;
100+
101+ it ( 'should map user social data to view models' , ( ) => {
102+ fixture . componentRef . setInput ( 'currentUser' , mockUser ) ;
103+ fixture . detectChanges ( ) ;
104+
105+ const socials = component . userSocials ( ) ;
106+ expect ( socials ) . toBeDefined ( ) ;
107+ expect ( socials . length ) . toBeGreaterThan ( 0 ) ;
108+ } ) ;
109+
110+ it ( 'should include GitHub social link when present' , ( ) => {
111+ fixture . componentRef . setInput ( 'currentUser' , mockUser ) ;
112+ fixture . detectChanges ( ) ;
113+
114+ const socials = component . userSocials ( ) ;
115+ const github = socials . find ( ( s ) => s . icon . includes ( 'github' ) ) ;
116+ expect ( github ) . toBeDefined ( ) ;
117+ expect ( github ?. url ) . toContain ( 'github.com' ) ;
118+ } ) ;
119+
120+ it ( 'should include Twitter social link when present' , ( ) => {
121+ fixture . componentRef . setInput ( 'currentUser' , mockUser ) ;
122+ fixture . detectChanges ( ) ;
123+
124+ const socials = component . userSocials ( ) ;
125+ const twitter = socials . find ( ( s ) => s . icon . includes ( 'x.svg' ) ) ;
126+ expect ( twitter ) . toBeDefined ( ) ;
127+ expect ( twitter ?. url ) . toContain ( 'x.com' ) ;
128+ } ) ;
129+
130+ it ( 'should include LinkedIn social link when present' , ( ) => {
131+ fixture . componentRef . setInput ( 'currentUser' , mockUser ) ;
132+ fixture . detectChanges ( ) ;
133+
134+ const socials = component . userSocials ( ) ;
135+ const linkedin = socials . find ( ( s ) => s . icon . includes ( 'linkedin' ) ) ;
136+ expect ( linkedin ) . toBeDefined ( ) ;
137+ expect ( linkedin ?. url ) . toContain ( 'linkedin.com' ) ;
138+ } ) ;
139+
140+ it ( 'should return empty array when user has no social data' , ( ) => {
141+ fixture . componentRef . setInput ( 'currentUser' , {
142+ ...mockUser ,
143+ social : { } as SocialModel ,
144+ } ) ;
145+ fixture . detectChanges ( ) ;
146+
147+ const socials = component . userSocials ( ) ;
148+ expect ( socials ) . toEqual ( [ ] ) ;
149+ } ) ;
150+
151+ it ( 'should return empty array when currentUser is null' , ( ) => {
152+ fixture . componentRef . setInput ( 'currentUser' , null ) ;
153+ fixture . detectChanges ( ) ;
154+
155+ const socials = component . userSocials ( ) ;
156+ expect ( socials ) . toEqual ( [ ] ) ;
157+ } ) ;
158+
159+ it ( 'should not include profileWebsites in social links' , ( ) => {
160+ fixture . componentRef . setInput ( 'currentUser' , mockUser ) ;
161+ fixture . detectChanges ( ) ;
162+
163+ const socials = component . userSocials ( ) ;
164+ const websites = socials . filter ( ( s ) => s . alt === 'settings.profileSettings.social.labels.profileWebsites' ) ;
165+ expect ( websites . length ) . toBe ( 0 ) ;
166+ } ) ;
167+
168+ it ( 'should emit editProfile event when called' , ( done ) => {
169+ component . editProfile . subscribe ( ( ) => {
170+ expect ( true ) . toBe ( true ) ;
171+ done ( ) ;
172+ } ) ;
173+
174+ component . toProfileSettings ( ) ;
175+ } ) ;
176+
177+ it ( 'should emit editProfile event on button click' , ( ) => {
178+ jest . spyOn ( component . editProfile , 'emit' ) ;
179+ component . toProfileSettings ( ) ;
180+ expect ( component . editProfile . emit ) . toHaveBeenCalled ( ) ;
181+ } ) ;
32182} ) ;
0 commit comments