@@ -29,6 +29,13 @@ describe('VocabularyTreeviewComponent test suite', () => {
2929 item . id = 'node1' ;
3030 const item2 = new VocabularyEntryDetail ( ) ;
3131 item2 . id = 'node2' ;
32+ const entryWithAuthority = new VocabularyEntryDetail ( ) ;
33+ entryWithAuthority . authority = 'entryWithAuthority' ;
34+ entryWithAuthority . id = 'entryWithAuthority' ;
35+ entryWithAuthority . value = 'test' ;
36+ const entryWithoutAuthority = new VocabularyEntryDetail ( ) ;
37+ entryWithoutAuthority . id = 'entryWithoutAuthority' ;
38+ entryWithoutAuthority . value = 'test2' ;
3239 const emptyNodeMap = new Map < string , TreeviewFlatNode > ( ) ;
3340 const storedNodeMap = new Map < string , TreeviewFlatNode > ( ) . set ( 'test' , new TreeviewFlatNode ( item2 ) ) ;
3441 const nodeMap = new Map < string , TreeviewFlatNode > ( ) . set ( 'test' , new TreeviewFlatNode ( item ) ) ;
@@ -169,11 +176,31 @@ describe('VocabularyTreeviewComponent test suite', () => {
169176 expect ( vocabularyTreeviewServiceStub . loadMore ) . toHaveBeenCalledWith ( node . item , [ ] , true ) ;
170177 } ) ;
171178
172- it ( 'should emit select event' , ( ) => {
173- spyOn ( comp , 'onSelect' ) ;
174- comp . onSelect ( item ) ;
179+ it ( 'should emit proper FormFieldMetadataValueObject when VocabularyEntryDetail has authority' , ( ) => {
180+ spyOn ( compAsAny , 'getSelectedEntryIds' ) . and . returnValue ( [ ] ) ;
181+ spyOn ( comp . select , 'emit' ) ;
182+ comp . onSelect ( entryWithAuthority ) ;
175183
176- expect ( comp . onSelect ) . toHaveBeenCalledWith ( item ) ;
184+ const expected = new FormFieldMetadataValueObject ( entryWithAuthority . value , null , null , entryWithAuthority . authority ) ;
185+ expect ( comp . select . emit ) . toHaveBeenCalledWith ( expected ) ;
186+ } ) ;
187+
188+ it ( 'should emit proper FormFieldMetadataValueObject when VocabularyEntryDetail has no authority' , ( ) => {
189+ spyOn ( compAsAny , 'getSelectedEntryIds' ) . and . returnValue ( [ ] ) ;
190+ spyOn ( comp . select , 'emit' ) ;
191+ comp . onSelect ( entryWithoutAuthority ) ;
192+
193+ const expected = new FormFieldMetadataValueObject ( entryWithoutAuthority . value ) ;
194+ expect ( comp . select . emit ) . toHaveBeenCalledWith ( expected ) ;
195+ } ) ;
196+
197+ it ( 'should emit deselect when entry is already present' , ( ) => {
198+ spyOn ( compAsAny , 'getSelectedEntryIds' ) . and . returnValue ( [ entryWithAuthority . id ] ) ;
199+ spyOn ( comp . select , 'emit' ) ;
200+ spyOn ( comp . deselect , 'emit' ) ;
201+ comp . onSelect ( entryWithAuthority ) ;
202+
203+ expect ( comp . deselect . emit ) . toHaveBeenCalled ( ) ;
177204 } ) ;
178205
179206 it ( 'should call searchByQuery function and set storedNodeMap properly' , ( ) => {
0 commit comments