Skip to content

Commit b4f6e20

Browse files
milanmajchrakclaude
andcommitted
Cover the one behavioural change of #1300 with a real spec
clarin-description-item-field is the only component this port changes behaviourally: it used to join every description value into a single innerHTML with <br>, and now renders one <div> per value so each can carry its own lang. That component had no spec on dtq-dev-9-base. dtq-dev has one, but it is a bare "should create" smoke test that would not have caught any of this, and the source commit did not touch it. Adds five cases against the new shape: one element per value, per-value BCP 47 lang, no lang attribute for the wildcard language, makeLinks still producing anchors through [innerHTML], and the empty-metadata case. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 4039dbf commit b4f6e20

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import {
2+
ComponentFixture,
3+
TestBed,
4+
} from '@angular/core/testing';
5+
import { By } from '@angular/platform-browser';
6+
7+
import { Item } from '../../../../core/shared/item.model';
8+
import { ClarinDescriptionItemFieldComponent } from './clarin-description-item-field.component';
9+
10+
describe('ClarinDescriptionItemFieldComponent', () => {
11+
12+
let component: ClarinDescriptionItemFieldComponent;
13+
let fixture: ComponentFixture<ClarinDescriptionItemFieldComponent>;
14+
15+
function itemWithDescriptions(values: { value: string, language: string }[]): Item {
16+
return Object.assign(new Item(), {
17+
metadata: {
18+
'dc.description': values,
19+
},
20+
});
21+
}
22+
23+
function render(item: Item): void {
24+
fixture = TestBed.createComponent(ClarinDescriptionItemFieldComponent);
25+
component = fixture.componentInstance;
26+
component.fields = ['dc.description'];
27+
component.item = item;
28+
fixture.detectChanges();
29+
}
30+
31+
beforeEach(async () => {
32+
await TestBed.configureTestingModule({
33+
imports: [ClarinDescriptionItemFieldComponent],
34+
}).compileComponents();
35+
});
36+
37+
it('should render one element per description value', () => {
38+
render(itemWithDescriptions([
39+
{ value: 'first description', language: 'en_US' },
40+
{ value: 'second description', language: 'cs_CZ' },
41+
]));
42+
43+
const divs = fixture.debugElement.queryAll(By.css('div'));
44+
expect(divs.length).toBe(2);
45+
expect(divs[0].nativeElement.textContent).toContain('first description');
46+
expect(divs[1].nativeElement.textContent).toContain('second description');
47+
});
48+
49+
it('should give each value its own normalized BCP 47 lang attribute', () => {
50+
render(itemWithDescriptions([
51+
{ value: 'anglicky', language: 'en_US' },
52+
{ value: 'cesky', language: 'cs_CZ' },
53+
]));
54+
55+
const divs = fixture.debugElement.queryAll(By.css('div'));
56+
expect(divs[0].nativeElement.getAttribute('lang')).toEqual('en-US');
57+
expect(divs[1].nativeElement.getAttribute('lang')).toEqual('cs-CZ');
58+
expect(fixture.nativeElement.innerHTML).not.toContain('lang="en_US"');
59+
});
60+
61+
it('should omit the lang attribute for the wildcard language', () => {
62+
render(itemWithDescriptions([{ value: 'language independent', language: '*' }]));
63+
64+
const div = fixture.debugElement.query(By.css('div'));
65+
expect(div.nativeElement.hasAttribute('lang')).toBeFalse();
66+
expect(fixture.nativeElement.innerHTML).not.toContain('lang="*"');
67+
});
68+
69+
it('should still turn URLs in the description into links', () => {
70+
render(itemWithDescriptions([
71+
{ value: 'see https://lindat.cz for more', language: 'en_US' },
72+
]));
73+
74+
const anchor = fixture.debugElement.query(By.css('div a'));
75+
expect(anchor).toBeTruthy();
76+
expect(anchor.nativeElement.getAttribute('href')).toEqual('https://lindat.cz');
77+
expect(anchor.nativeElement.getAttribute('target')).toEqual('_blank');
78+
});
79+
80+
it('should render nothing when the item has no description', () => {
81+
render(Object.assign(new Item(), { metadata: {} }));
82+
83+
expect(component.descriptionEntries).toEqual([]);
84+
expect(fixture.debugElement.queryAll(By.css('div')).length).toBe(0);
85+
});
86+
87+
});

0 commit comments

Comments
 (0)