Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions renderers/angular/src/v0_8/components/image.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ describe('Image Component', () => {
expect(sectionEl.nativeElement.className).toContain('image-all-class');
});

it('should render <img> with altText if provided', () => {
fixture.componentRef.setInput('url', { literalString: 'http://example.com/a.png' });
fixture.componentRef.setInput('altText', { literalString: 'A beautiful sunset' });
fixture.detectChanges();

const imgEl = fixture.debugElement.query(By.css('img'));
expect(imgEl).toBeTruthy();
expect(imgEl.nativeElement.alt).toBe('A beautiful sunset');
});

it('should NOT render <img> if url is null', () => {
fixture.componentRef.setInput('usageHint', null);
fixture.detectChanges();
Expand Down
5 changes: 4 additions & 1 deletion renderers/angular/src/v0_8/components/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ import { DynamicComponent } from '../rendering/dynamic-component';
`,
template: `
@let resolvedUrl = this.resolvedUrl();
@let resolvedAltText = this.resolvedAltText();

@if (resolvedUrl) {
<section [class]="classes()" [style]="theme.additionalStyles?.Image">
<img [src]="resolvedUrl" alt="" />
<img [src]="resolvedUrl" [alt]="resolvedAltText" />
</section>
}
`,
Expand All @@ -52,8 +53,10 @@ export class Image extends DynamicComponent<Types.ImageNode> {
readonly url = input<Primitives.StringValue | null>(null);
readonly usageHint = input<Types.ResolvedImage['usageHint'] | null>(null);
readonly fit = input<Types.ResolvedImage['fit'] | null>(null);
readonly altText = input<Primitives.StringValue | null>(null);

protected readonly resolvedUrl = computed(() => this.resolvePrimitive(this.url()));
protected readonly resolvedAltText = computed(() => this.resolvePrimitive(this.altText()) || '');

protected classes = computed(() => {
const usageHint = this.usageHint();
Expand Down
10 changes: 10 additions & 0 deletions renderers/angular/src/v0_9/catalog/basic/simple-components.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ describe('Simple Components', () => {
expect(img.style.objectFit).toBe('cover');
expect(img.className).toContain('avatar');
});

it('should render image with description', () => {
fixture.componentRef.setInput('props', {
url: createBoundProperty('https://example.com/image.png'),
description: createBoundProperty('A cute cat'),
});
fixture.detectChanges();
const img = fixture.nativeElement.querySelector('img') as HTMLImageElement;
expect(img.alt).toBe('A cute cat');
});
});

describe('IconComponent', () => {
Expand Down
Loading
Loading