@@ -2,7 +2,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
22import { provideRouter } from '@angular/router' ;
33
44import { collectionFilterNames } from '@osf/features/collections/constants' ;
5- import { CedarMetadataDataTemplateJsonApi , CedarMetadataRecordData } from '@osf/features/metadata/models' ;
5+ import { CedarMetadataDataTemplateJsonApi } from '@osf/features/metadata/models' ;
66import { CollectionSubmission } from '@osf/shared/models/collections/collections.model' ;
77
88import { CEDAR_METADATA_DATA_TEMPLATE_JSON_API_MOCK } from '@testing/mocks/cedar-metadata-data-template-json-api.mock' ;
@@ -96,47 +96,49 @@ describe('OverviewCollectionsComponent', () => {
9696 expect ( typeof statusAttr ?. value ) . toBe ( 'string' ) ;
9797 } ) ;
9898
99- it ( 'should render cedar-artifact-viewer when isCedarMode is true with matching record and template' , async ( ) => {
99+ it ( 'should display cedar attributes as key-value pairs when isCedarMode is true with matching record and template' , async ( ) => {
100100 const cedarSubmission : CollectionSubmission = {
101101 ...MOCK_COLLECTION_SUBMISSION_EMPTY_FILTERS ,
102102 requiredMetadataTemplateId : 'template-1' ,
103103 } ;
104- const cedarRecord : CedarMetadataRecordData = MOCK_CEDAR_METADATA_RECORD_DATA ;
105104 const cedarTemplate : CedarMetadataDataTemplateJsonApi =
106105 CEDAR_METADATA_DATA_TEMPLATE_JSON_API_MOCK as CedarMetadataDataTemplateJsonApi ;
107106
108107 fixture . componentRef . setInput ( 'projectSubmissions' , [ cedarSubmission ] ) ;
109108 fixture . componentRef . setInput ( 'isCedarMode' , true ) ;
110- fixture . componentRef . setInput ( 'cedarRecords' , [ cedarRecord ] ) ;
109+ fixture . componentRef . setInput ( 'cedarRecords' , [ MOCK_CEDAR_METADATA_RECORD_DATA ] ) ;
111110 fixture . componentRef . setInput ( 'cedarTemplates' , [ cedarTemplate ] ) ;
112111 fixture . detectChanges ( ) ;
113112 await fixture . whenStable ( ) ;
114113
115- const viewer = fixture . nativeElement . querySelector ( 'cedar-artifact-viewer' ) ;
116- expect ( viewer ) . toBeTruthy ( ) ;
114+ const paragraphs = fixture . nativeElement . querySelectorAll ( 'p.font-normal' ) ;
115+ expect ( paragraphs . length ) . toBeGreaterThan ( 0 ) ;
116+ expect ( fixture . nativeElement . textContent ) . toContain ( 'Project Name' ) ;
117+ expect ( fixture . nativeElement . textContent ) . toContain ( 'Test Project Name' ) ;
117118 } ) ;
118119
119- it ( 'should not render cedar-artifact-viewer when isCedarMode is false' , async ( ) => {
120+ it ( 'should display submission attributes when isCedarMode is false' , async ( ) => {
120121 const cedarSubmission : CollectionSubmission = {
121122 ...MOCK_COLLECTION_SUBMISSION_WITH_FILTERS ,
122123 requiredMetadataTemplateId : 'template-1' ,
123124 } ;
124- const cedarRecord : CedarMetadataRecordData = MOCK_CEDAR_METADATA_RECORD_DATA ;
125125 const cedarTemplate : CedarMetadataDataTemplateJsonApi =
126126 CEDAR_METADATA_DATA_TEMPLATE_JSON_API_MOCK as CedarMetadataDataTemplateJsonApi ;
127127
128128 fixture . componentRef . setInput ( 'projectSubmissions' , [ cedarSubmission ] ) ;
129129 fixture . componentRef . setInput ( 'isCedarMode' , false ) ;
130- fixture . componentRef . setInput ( 'cedarRecords' , [ cedarRecord ] ) ;
130+ fixture . componentRef . setInput ( 'cedarRecords' , [ MOCK_CEDAR_METADATA_RECORD_DATA ] ) ;
131131 fixture . componentRef . setInput ( 'cedarTemplates' , [ cedarTemplate ] ) ;
132132 fixture . detectChanges ( ) ;
133133 await fixture . whenStable ( ) ;
134134
135- const viewer = fixture . nativeElement . querySelector ( 'cedar-artifact-viewer' ) ;
136- expect ( viewer ) . toBeNull ( ) ;
135+ const attributes = component . getSubmissionAttributes ( cedarSubmission ) ;
136+ expect ( attributes . length ) . toBeGreaterThan ( 0 ) ;
137+ const paragraphs = fixture . nativeElement . querySelectorAll ( 'p.font-normal' ) ;
138+ expect ( paragraphs . length ) . toBe ( attributes . length ) ;
137139 } ) ;
138140
139- it ( 'should show traditional attributes when isCedarMode is true but no matching record' , async ( ) => {
141+ it ( 'should fall back to submission attributes when isCedarMode is true but no matching record' , async ( ) => {
140142 const cedarSubmission : CollectionSubmission = {
141143 ...MOCK_COLLECTION_SUBMISSION_WITH_FILTERS ,
142144 requiredMetadataTemplateId : 'non-existent-template' ,
@@ -149,9 +151,19 @@ describe('OverviewCollectionsComponent', () => {
149151 fixture . detectChanges ( ) ;
150152 await fixture . whenStable ( ) ;
151153
152- const viewer = fixture . nativeElement . querySelector ( 'cedar-artifact-viewer' ) ;
153- expect ( viewer ) . toBeNull ( ) ;
154- expect ( component . getSubmissionAttributes ( cedarSubmission ) . length ) . toBeGreaterThan ( 0 ) ;
154+ const attributes = component . getSubmissionAttributes ( cedarSubmission ) ;
155+ expect ( attributes . length ) . toBeGreaterThan ( 0 ) ;
156+ const paragraphs = fixture . nativeElement . querySelectorAll ( 'p.font-normal' ) ;
157+ expect ( paragraphs . length ) . toBe ( attributes . length ) ;
158+ } ) ;
159+
160+ it ( 'should extract key-value pairs from a cedar record using template field order and labels' , ( ) => {
161+ const cedarTemplate : CedarMetadataDataTemplateJsonApi =
162+ CEDAR_METADATA_DATA_TEMPLATE_JSON_API_MOCK as CedarMetadataDataTemplateJsonApi ;
163+
164+ const result = component . getCedarAttributes ( MOCK_CEDAR_METADATA_RECORD_DATA , cedarTemplate ) ;
165+
166+ expect ( result ) . toContainEqual ( { key : 'Project Name' , label : 'Project Name' , value : 'Test Project Name' } ) ;
155167 } ) ;
156168
157169 it ( 'should compute empty cedarRecordByTemplateId map when cedarRecords is null' , ( ) => {
0 commit comments