mirror of
https://github.com/immich-app/immich.git
synced 2026-10-28 23:16:49 +08:00
fix(web): asset remains in timeline after archive (#31348)
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
import type { AssetResponseDto } from '@immich/sdk';
|
||||
import { canCopyImageToClipboard, getAssetFilename, getFilenameExtension } from './asset-utils';
|
||||
import { AssetVisibility, updateAsset, type AssetResponseDto } from '@immich/sdk';
|
||||
import { canCopyImageToClipboard, getAssetFilename, getFilenameExtension, toggleArchive } from './asset-utils';
|
||||
|
||||
vi.mock('@immich/sdk', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@immich/sdk')>();
|
||||
return {
|
||||
...actual,
|
||||
updateAsset: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
describe('get file extension from filename', () => {
|
||||
it('returns the extension without including the dot', () => {
|
||||
@@ -63,3 +71,36 @@ describe('copy image to clipboard', () => {
|
||||
expect(canCopyImageToClipboard()).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toggleArchive', () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(updateAsset).mockReset();
|
||||
});
|
||||
|
||||
it('updates both isArchived and visibility when archiving', async () => {
|
||||
vi.mocked(updateAsset).mockResolvedValue({
|
||||
isArchived: true,
|
||||
visibility: AssetVisibility.Archive,
|
||||
} as AssetResponseDto);
|
||||
|
||||
const asset = { id: '1', isArchived: false, visibility: AssetVisibility.Timeline } as AssetResponseDto;
|
||||
await toggleArchive(asset);
|
||||
|
||||
expect(asset.isArchived).toBe(true);
|
||||
// regression: visibility must be refreshed so the timeline correctly excludes the archived asset
|
||||
expect(asset.visibility).toBe(AssetVisibility.Archive);
|
||||
});
|
||||
|
||||
it('updates both isArchived and visibility when unarchiving', async () => {
|
||||
vi.mocked(updateAsset).mockResolvedValue({
|
||||
isArchived: false,
|
||||
visibility: AssetVisibility.Timeline,
|
||||
} as AssetResponseDto);
|
||||
|
||||
const asset = { id: '1', isArchived: true, visibility: AssetVisibility.Archive } as AssetResponseDto;
|
||||
await toggleArchive(asset);
|
||||
|
||||
expect(asset.isArchived).toBe(false);
|
||||
expect(asset.visibility).toBe(AssetVisibility.Timeline);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -403,6 +403,7 @@ export const toggleArchive = async (asset: AssetResponseDto) => {
|
||||
});
|
||||
|
||||
asset.isArchived = data.isArchived;
|
||||
asset.visibility = data.visibility;
|
||||
if (asset.isArchived) {
|
||||
const timelineAsset = toTimelineAsset(asset);
|
||||
showUndoArchiveToast($t('added_to_archive'), [timelineAsset]);
|
||||
|
||||
Reference in New Issue
Block a user