-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent trashing of trashed assets (#10028)
* fix: prevent trashing of trashed assets Motivation ---------- This will improve user experience by hiding a pointless action. You can not trash a trashed asset again. It won't get any trashier than it already is. How to test ----------- 1. Visit route `/trash` 2. Click on an asset 3. Press "Delete" on your keyboard 4. Nothing happens 5. Try to find the trash button in the top right 6. You can't find it * refactor: follow @michelheusschen's review See: #10028 (review) * refactor: follow @michelheusschen's 2nd review See: #10028 (comment)
- Loading branch information
1 parent
e1e7de4
commit d8d64ec
Showing
6 changed files
with
129 additions
and
8 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
web/src/lib/components/asset-viewer/asset-viewer-nav-bar.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { resetSavedUser, user as userStore } from '$lib/stores/user.store'; | ||
import { assetFactory } from '@test-data/factories/asset-factory'; | ||
import { userAdminFactory } from '@test-data/factories/user-factory'; | ||
import '@testing-library/jest-dom'; | ||
import { render } from '@testing-library/svelte'; | ||
import AssetViewerNavBar from './asset-viewer-nav-bar.svelte'; | ||
|
||
describe('AssetViewerNavBar component', () => { | ||
const additionalProps = { | ||
showCopyButton: false, | ||
showZoomButton: false, | ||
showDetailButton: false, | ||
showDownloadButton: false, | ||
showMotionPlayButton: false, | ||
showShareButton: false, | ||
onZoomImage: () => {}, | ||
onCopyImage: () => {}, | ||
}; | ||
|
||
afterEach(() => { | ||
vi.resetAllMocks(); | ||
resetSavedUser(); | ||
}); | ||
|
||
it('shows back button', () => { | ||
const asset = assetFactory.build({ isTrashed: false }); | ||
const { getByTitle } = render(AssetViewerNavBar, { asset, ...additionalProps }); | ||
expect(getByTitle('go_back')).toBeInTheDocument(); | ||
}); | ||
|
||
describe('if the current user owns the asset', () => { | ||
it('shows delete button', () => { | ||
const ownerId = 'id-of-the-user'; | ||
const user = userAdminFactory.build({ id: ownerId }); | ||
const asset = assetFactory.build({ ownerId, isTrashed: false }); | ||
userStore.set(user); | ||
const { getByTitle } = render(AssetViewerNavBar, { asset, ...additionalProps }); | ||
expect(getByTitle('delete')).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { type AssetResponseDto } from '@immich/sdk'; | ||
|
||
import { assetFactory } from '@test-data/factories/asset-factory'; | ||
import '@testing-library/jest-dom'; | ||
import { render } from '@testing-library/svelte'; | ||
import DeleteButton from './delete-button.svelte'; | ||
|
||
let asset: AssetResponseDto; | ||
|
||
describe('DeleteButton component', () => { | ||
describe('given an asset which is not trashed yet', () => { | ||
beforeEach(() => { | ||
asset = assetFactory.build({ isTrashed: false }); | ||
}); | ||
|
||
it('displays a button to move the asset to the trash bin', () => { | ||
const { getByTitle, queryByTitle } = render(DeleteButton, { asset }); | ||
expect(getByTitle('delete')).toBeInTheDocument(); | ||
expect(queryByTitle('deletePermanently')).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('but if the asset is already trashed', () => { | ||
beforeEach(() => { | ||
asset = assetFactory.build({ isTrashed: true }); | ||
}); | ||
|
||
it('displays a button to permanently delete the asset', () => { | ||
const { getByTitle, queryByTitle } = render(DeleteButton, { asset }); | ||
expect(getByTitle('permanently_delete')).toBeInTheDocument(); | ||
expect(queryByTitle('delete')).toBeNull(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<script lang="ts"> | ||
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte'; | ||
import { createEventDispatcher } from 'svelte'; | ||
import { t } from 'svelte-i18n'; | ||
import { mdiDeleteOutline } from '@mdi/js'; | ||
import { type AssetResponseDto } from '@immich/sdk'; | ||
export let asset: AssetResponseDto; | ||
type EventTypes = { | ||
delete: void; | ||
permanentlyDelete: void; | ||
}; | ||
const dispatch = createEventDispatcher<EventTypes>(); | ||
</script> | ||
|
||
{#if asset.isTrashed} | ||
<CircleIconButton | ||
color="opaque" | ||
icon={mdiDeleteOutline} | ||
on:click={() => dispatch('permanentlyDelete')} | ||
title={$t('permanently_delete')} | ||
/> | ||
{:else} | ||
<CircleIconButton color="opaque" icon={mdiDeleteOutline} on:click={() => dispatch('delete')} title={$t('delete')} /> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters