Skip to content

Commit

Permalink
fix(components/indicators): hide illustration while loading (#2526) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
blackbaud-sky-build-user authored Jul 23, 2024
1 parent 9ac8cd1 commit b384178
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
loading="lazy"
[attr.data-sky-illustration-name]="name()"
[height]="pixelSize()"
[ngClass]="{
'sky-illustration-img-loaded': !!url(),
}"
[src]="url()"
[width]="pixelSize()"
/>
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ describe('Illustration', () => {
provideResolver: boolean,
name: string,
size: SkyIllustrationSize,
resolver?: {
resolveUrl: (url: string) => Promise<string>;
},
): void {
const providers: Provider[] = [];

if (provideResolver) {
providers.push({
provide: SkyIllustrationResolverService,
useClass: SkyIllustrationTestResolverService,
useFactory: () => resolver ?? new SkyIllustrationTestResolverService(),
});
}

Expand All @@ -50,6 +53,17 @@ describe('Illustration', () => {
expect(getImgEl()?.getAttribute(name)).toBe(expectedValue);
}

function validateImageVisibility(expectedVisible: boolean): void {
const imgEl = getImgEl();
let visibility: string | undefined;

if (imgEl) {
visibility = getComputedStyle(imgEl).visibility;
}

expect(visibility).toBe(expectedVisible ? 'visible' : 'hidden');
}

function detectUrlChanges(): void {
fixture.detectChanges();

Expand Down Expand Up @@ -101,6 +115,33 @@ describe('Illustration', () => {

await expectAsync(fixture.nativeElement).toBeAccessible();
});

it('should be hidden until the URL is resolved', fakeAsync(async () => {
// TODO: Use the more concise Promise.withResolvers() when it's available in TypeScript
// to avoid this awkward workaround for strict type checking.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers
let resolveUrl = (_: string): void => void _;

const resolvePromise = new Promise<string>(
(resolve) => (resolveUrl = resolve),
);

setupTest(true, 'test', 'sm', {
resolveUrl: () => resolvePromise,
});

detectUrlChanges();

validateImageVisibility(false);

resolveUrl('https://example.com/success.svg');

detectUrlChanges();

validateImageVisibility(true);

await resolvePromise;
}));
});

describe('without resolver provided', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@

@include mixins.sky-component('default', '.sky-illustration-img') {
display: block;

&[src=''] {
visibility: hidden;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@

@include mixins.sky-component('modern', '.sky-illustration-img') {
display: block;

&[src=''] {
visibility: hidden;
}
}

0 comments on commit b384178

Please sign in to comment.