mirror of
https://github.com/immich-app/immich.git
synced 2026-03-22 14:19:26 +03:00
fix(web): download toast showing wrong filename for motion assets (#26689)
This commit is contained in:
@@ -1,9 +1,34 @@
|
|||||||
import { getAssetActions } from '$lib/services/asset.service';
|
import { getAssetActions, handleDownloadAsset } from '$lib/services/asset.service';
|
||||||
import { user as userStore } from '$lib/stores/user.store';
|
import { user as userStore } from '$lib/stores/user.store';
|
||||||
import { setSharedLink } from '$lib/utils';
|
import { setSharedLink } from '$lib/utils';
|
||||||
|
import { getFormatter } from '$lib/utils/i18n';
|
||||||
|
import { getAssetInfo } from '@immich/sdk';
|
||||||
|
import { toastManager } from '@immich/ui';
|
||||||
import { assetFactory } from '@test-data/factories/asset-factory';
|
import { assetFactory } from '@test-data/factories/asset-factory';
|
||||||
import { sharedLinkFactory } from '@test-data/factories/shared-link-factory';
|
import { sharedLinkFactory } from '@test-data/factories/shared-link-factory';
|
||||||
import { userAdminFactory } from '@test-data/factories/user-factory';
|
import { userAdminFactory } from '@test-data/factories/user-factory';
|
||||||
|
import { vitest } from 'vitest';
|
||||||
|
|
||||||
|
vitest.mock('@immich/ui', () => ({
|
||||||
|
toastManager: {
|
||||||
|
success: vitest.fn(),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
vitest.mock('$lib/utils/i18n', () => ({
|
||||||
|
getFormatter: vitest.fn(),
|
||||||
|
getPreferredLocale: vitest.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vitest.mock('@immich/sdk');
|
||||||
|
|
||||||
|
vitest.mock('$lib/utils', async () => {
|
||||||
|
const originalModule = await vitest.importActual('$lib/utils');
|
||||||
|
return {
|
||||||
|
...originalModule,
|
||||||
|
sleep: vitest.fn(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
describe('AssetService', () => {
|
describe('AssetService', () => {
|
||||||
describe('getAssetActions', () => {
|
describe('getAssetActions', () => {
|
||||||
@@ -34,4 +59,27 @@ describe('AssetService', () => {
|
|||||||
expect(assetActions.SharedLinkDownload.$if?.()).toStrictEqual(true);
|
expect(assetActions.SharedLinkDownload.$if?.()).toStrictEqual(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('handleDownloadAsset', () => {
|
||||||
|
it('should use the asset originalFileName when showing toasts', async () => {
|
||||||
|
const $t = vitest.fn().mockReturnValue('formatter');
|
||||||
|
vitest.mocked(getFormatter).mockResolvedValue($t);
|
||||||
|
const asset = assetFactory.build({ originalFileName: 'asset.heic' });
|
||||||
|
await handleDownloadAsset(asset, { edited: false });
|
||||||
|
expect($t).toHaveBeenNthCalledWith(1, 'downloading_asset_filename', { values: { filename: 'asset.heic' } });
|
||||||
|
expect(toastManager.success).toHaveBeenCalledWith('formatter');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use the motion asset originalFileName when showing toasts', async () => {
|
||||||
|
const $t = vitest.fn().mockReturnValue('formatter');
|
||||||
|
vitest.mocked(getFormatter).mockResolvedValue($t);
|
||||||
|
const motionAsset = assetFactory.build({ originalFileName: 'asset.mov' });
|
||||||
|
vitest.mocked(getAssetInfo).mockResolvedValue(motionAsset);
|
||||||
|
const asset = assetFactory.build({ originalFileName: 'asset.heic', livePhotoVideoId: '1' });
|
||||||
|
await handleDownloadAsset(asset, { edited: false });
|
||||||
|
expect($t).toHaveBeenNthCalledWith(1, 'downloading_asset_filename', { values: { filename: 'asset.heic' } });
|
||||||
|
expect($t).toHaveBeenNthCalledWith(2, 'downloading_asset_filename', { values: { filename: 'asset.mov' } });
|
||||||
|
expect(toastManager.success).toHaveBeenCalledWith('formatter');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -294,7 +294,6 @@ export const handleDownloadAsset = async (asset: AssetResponseDto, { edited }: {
|
|||||||
{
|
{
|
||||||
filename: asset.originalFileName,
|
filename: asset.originalFileName,
|
||||||
id: asset.id,
|
id: asset.id,
|
||||||
size: asset.exifInfo?.fileSizeInByte || 0,
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -308,7 +307,6 @@ export const handleDownloadAsset = async (asset: AssetResponseDto, { edited }: {
|
|||||||
assets.push({
|
assets.push({
|
||||||
filename: motionAsset.originalFileName,
|
filename: motionAsset.originalFileName,
|
||||||
id: asset.livePhotoVideoId,
|
id: asset.livePhotoVideoId,
|
||||||
size: motionAsset.exifInfo?.fileSizeInByte || 0,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -322,7 +320,7 @@ export const handleDownloadAsset = async (asset: AssetResponseDto, { edited }: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
toastManager.success($t('downloading_asset_filename', { values: { filename: asset.originalFileName } }));
|
toastManager.success($t('downloading_asset_filename', { values: { filename } }));
|
||||||
downloadUrl(
|
downloadUrl(
|
||||||
getBaseUrl() +
|
getBaseUrl() +
|
||||||
`/assets/${id}/original` +
|
`/assets/${id}/original` +
|
||||||
|
|||||||
Reference in New Issue
Block a user