Skip to content

Commit

Permalink
fix(web): use fallback image if shared asset isn't resized (#11704)
Browse files Browse the repository at this point in the history
* fix(web): use fallback image if shared asset isn't resized

* remove test-data index file
  • Loading branch information
michelheusschen authored Aug 11, 2024
1 parent 9ed0458 commit 30aa2c9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sdkMock } from '$lib/__mocks__/sdk.mock';
import { albumFactory } from '@test-data';
import { albumFactory } from '@test-data/factories/album-factory';
import '@testing-library/jest-dom';
import { fireEvent, render, waitFor, type RenderResult } from '@testing-library/svelte';
import { init, register, waitLocale } from 'svelte-i18n';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AlbumCover from '$lib/components/album-page/album-cover.svelte';
import { getAssetThumbnailUrl } from '$lib/utils';
import { albumFactory } from '@test-data';
import { albumFactory } from '@test-data/factories/album-factory';
import { render } from '@testing-library/svelte';

vi.mock('$lib/utils');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import ShareCover from '$lib/components/sharedlinks-page/covers/share-cover.svelte';
import { getAssetThumbnailUrl } from '$lib/utils';
import type { SharedLinkResponseDto } from '@immich/sdk';
import { albumFactory } from '@test-data';
import { render } from '@testing-library/svelte';
import { albumFactory } from '@test-data/factories/album-factory';
import { assetFactory } from '@test-data/factories/asset-factory';
import { sharedLinkFactory } from '@test-data/factories/shared-link-factory';
import { render, screen } from '@testing-library/svelte';

vi.mock('$lib/utils');

describe('ShareCover component', () => {
it('renders an image when the shared link is an album', () => {
const component = render(ShareCover, {
link: {
album: albumFactory.build({
albumName: '123',
}),
} as SharedLinkResponseDto,
link: sharedLinkFactory.build({ album: albumFactory.build({ albumName: '123' }) }),
preload: false,
class: 'text',
});
Expand All @@ -26,13 +23,7 @@ describe('ShareCover component', () => {
it('renders an image when the shared link is an individual share', () => {
vi.mocked(getAssetThumbnailUrl).mockReturnValue('/asdf');
const component = render(ShareCover, {
link: {
assets: [
{
id: 'someId',
},
],
} as SharedLinkResponseDto,
link: sharedLinkFactory.build({ assets: [assetFactory.build({ id: 'someId' })] }),
preload: false,
class: 'text',
});
Expand All @@ -46,9 +37,7 @@ describe('ShareCover component', () => {

it('renders an image when the shared link has no album or assets', () => {
const component = render(ShareCover, {
link: {
assets: [],
} as unknown as SharedLinkResponseDto,
link: sharedLinkFactory.build(),
preload: false,
class: 'text',
});
Expand All @@ -57,4 +46,15 @@ describe('ShareCover component', () => {
expect(img.getAttribute('loading')).toBe('lazy');
expect(img.className).toBe('z-0 rounded-xl object-cover text');
});

it('renders fallback image when asset is not resized', () => {
const link = sharedLinkFactory.build({ assets: [assetFactory.build({ resized: false })] });
render(ShareCover, {
link: link,
preload: false,
});

const img = screen.getByTestId<HTMLImageElement>('album-image');
expect(img.alt).toBe('unnamed_share');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="relative aspect-square shrink-0">
{#if link?.album}
<AlbumCover album={link.album} class={className} {preload} />
{:else if link.assets[0]}
{:else if link.assets[0]?.resized}
<AssetCover
alt={$t('individual_share')}
class={className}
Expand Down
1 change: 0 additions & 1 deletion web/src/test-data/index.ts

This file was deleted.

0 comments on commit 30aa2c9

Please sign in to comment.