-
Notifications
You must be signed in to change notification settings - Fork 2k
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
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
- Loading branch information
1 parent
c8f2d99
commit 0d8daa4
Showing
4 changed files
with
92 additions
and
13 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
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,55 @@ | ||
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 { init } from 'svelte-i18n'; | ||
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, | ||
}; | ||
|
||
beforeAll(async () => { | ||
await init({ fallbackLocale: 'en-US' }); | ||
}); | ||
|
||
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 trash 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(); | ||
}); | ||
|
||
describe('but if the asset is already trashed', () => { | ||
it('hides trash button', () => { | ||
const ownerId = 'id-of-the-user'; | ||
const user = userAdminFactory.build({ id: ownerId }); | ||
const asset = assetFactory.build({ ownerId, isTrashed: true }); | ||
userStore.set(user); | ||
const { queryByTitle } = render(AssetViewerNavBar, { asset, ...additionalProps }); | ||
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
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