@@ -58,4 +58,108 @@ describe('SettingsProjectAffiliationComponent', () => {
5858
5959 expect ( component . removed . emit ) . toHaveBeenCalledWith ( MOCK_INSTITUTION ) ;
6060 } ) ;
61+
62+ describe ( 'canRemoveAffiliation' , ( ) => {
63+ const affiliatedInstitution = { ...MOCK_INSTITUTION , id : 'affiliated-id' } ;
64+ const nonAffiliatedInstitution = { ...MOCK_INSTITUTION , id : 'non-affiliated-id' } ;
65+ const userInstitutions = [ { ...MOCK_INSTITUTION , id : 'affiliated-id' } ] ;
66+
67+ beforeEach ( ( ) => {
68+ TestBed . resetTestingModule ( ) ;
69+ TestBed . configureTestingModule ( {
70+ imports : [ SettingsProjectAffiliationComponent , OSFTestingModule ] ,
71+ providers : [
72+ provideMockStore ( {
73+ signals : [ { selector : InstitutionsSelectors . getUserInstitutions , value : userInstitutions } ] ,
74+ } ) ,
75+ ] ,
76+ } ) . compileComponents ( ) ;
77+
78+ fixture = TestBed . createComponent ( SettingsProjectAffiliationComponent ) ;
79+ component = fixture . componentInstance ;
80+ } ) ;
81+
82+ it ( 'should return true when canRemove is true' , ( ) => {
83+ fixture . componentRef . setInput ( 'canRemove' , true ) ;
84+ fixture . componentRef . setInput ( 'canEdit' , false ) ;
85+ fixture . detectChanges ( ) ;
86+
87+ expect ( component . canRemoveAffiliation ( affiliatedInstitution ) ) . toBe ( true ) ;
88+ expect ( component . canRemoveAffiliation ( nonAffiliatedInstitution ) ) . toBe ( true ) ;
89+ } ) ;
90+
91+ it ( 'should return true when canEdit is true and user is affiliated with institution' , ( ) => {
92+ fixture . componentRef . setInput ( 'canRemove' , false ) ;
93+ fixture . componentRef . setInput ( 'canEdit' , true ) ;
94+ fixture . detectChanges ( ) ;
95+
96+ expect ( component . canRemoveAffiliation ( affiliatedInstitution ) ) . toBe ( true ) ;
97+ } ) ;
98+
99+ it ( 'should return false when canEdit is true but user is not affiliated with institution' , ( ) => {
100+ fixture . componentRef . setInput ( 'canRemove' , false ) ;
101+ fixture . componentRef . setInput ( 'canEdit' , true ) ;
102+ fixture . detectChanges ( ) ;
103+
104+ expect ( component . canRemoveAffiliation ( nonAffiliatedInstitution ) ) . toBe ( false ) ;
105+ } ) ;
106+
107+ it ( 'should return false when both canRemove and canEdit are false' , ( ) => {
108+ fixture . componentRef . setInput ( 'canRemove' , false ) ;
109+ fixture . componentRef . setInput ( 'canEdit' , false ) ;
110+ fixture . detectChanges ( ) ;
111+
112+ expect ( component . canRemoveAffiliation ( affiliatedInstitution ) ) . toBe ( false ) ;
113+ expect ( component . canRemoveAffiliation ( nonAffiliatedInstitution ) ) . toBe ( false ) ;
114+ } ) ;
115+ } ) ;
116+
117+ describe ( 'userInstitutionIds' , ( ) => {
118+ it ( 'should create a Set of user institution IDs' , ( ) => {
119+ const userInstitutions = [
120+ { ...MOCK_INSTITUTION , id : 'id1' } ,
121+ { ...MOCK_INSTITUTION , id : 'id2' } ,
122+ ] ;
123+
124+ TestBed . resetTestingModule ( ) ;
125+ TestBed . configureTestingModule ( {
126+ imports : [ SettingsProjectAffiliationComponent , OSFTestingModule ] ,
127+ providers : [
128+ provideMockStore ( {
129+ signals : [ { selector : InstitutionsSelectors . getUserInstitutions , value : userInstitutions } ] ,
130+ } ) ,
131+ ] ,
132+ } ) . compileComponents ( ) ;
133+
134+ fixture = TestBed . createComponent ( SettingsProjectAffiliationComponent ) ;
135+ component = fixture . componentInstance ;
136+ fixture . detectChanges ( ) ;
137+
138+ const result = component . userInstitutionIds ( ) ;
139+ expect ( result ) . toBeInstanceOf ( Set ) ;
140+ expect ( result . has ( 'id1' ) ) . toBe ( true ) ;
141+ expect ( result . has ( 'id2' ) ) . toBe ( true ) ;
142+ expect ( result . has ( 'id3' ) ) . toBe ( false ) ;
143+ } ) ;
144+
145+ it ( 'should return empty Set when no user institutions' , ( ) => {
146+ TestBed . resetTestingModule ( ) ;
147+ TestBed . configureTestingModule ( {
148+ imports : [ SettingsProjectAffiliationComponent , OSFTestingModule ] ,
149+ providers : [
150+ provideMockStore ( {
151+ signals : [ { selector : InstitutionsSelectors . getUserInstitutions , value : [ ] } ] ,
152+ } ) ,
153+ ] ,
154+ } ) . compileComponents ( ) ;
155+
156+ fixture = TestBed . createComponent ( SettingsProjectAffiliationComponent ) ;
157+ component = fixture . componentInstance ;
158+ fixture . detectChanges ( ) ;
159+
160+ const result = component . userInstitutionIds ( ) ;
161+ expect ( result ) . toBeInstanceOf ( Set ) ;
162+ expect ( result . size ) . toBe ( 0 ) ;
163+ } ) ;
164+ } ) ;
61165} ) ;
0 commit comments