mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-30 04:44:28 +00:00
feat(asset): Recently Deleted previews, retention countdown, and version stack delete/restore (#418)
* feat(asset): improve Recently Deleted previews and retention indicators - Include soft-deleted children when building folder previews for the Recently Deleted view, and resolve deleted version stacks to their latest version so a trashed folder shows what was inside it. - Add a "days left" badge (clock + Nd) to file and folder cards in the Recently Deleted view, placed to the left of the comments badge. - Fix an issue where deleting or restoring a version stack from the file list did nothing because the WebUI dropped version_stack items before calling the API. - Share the 30-day trash retention window through TRASH_RETENTION_DAYS. * test(asset): use typed MediaInfo in recently-deleted preview tests Replace the explicit any cast with a fully typed MediaInfo object so the new tests comply with the no-explicit-any policy.
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { cleanup, render, screen } from '@testing-library/react'
|
||||
import React from 'react'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { AssetInfo } from '@shumai/dtos'
|
||||
import { FolderCard } from './folder-card'
|
||||
|
||||
vi.mock('@dnd-kit/react', () => ({
|
||||
useDraggable: () => ({
|
||||
ref: vi.fn(),
|
||||
isDragging: false,
|
||||
}),
|
||||
useDroppable: () => ({
|
||||
ref: vi.fn(),
|
||||
isDropTarget: false,
|
||||
}),
|
||||
}))
|
||||
|
||||
describe('FolderCard', () => {
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
})
|
||||
|
||||
const folderItem: AssetInfo = {
|
||||
id: 'folder-123',
|
||||
name: 'regular_folder',
|
||||
type: 'folder',
|
||||
status: 'processed',
|
||||
fileCount: 2,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
} as AssetInfo
|
||||
|
||||
const renderComponent = (props: Partial<React.ComponentProps<typeof FolderCard>> = {}) => {
|
||||
return render(
|
||||
<FolderCard
|
||||
item={folderItem}
|
||||
isSelected={false}
|
||||
isChecked={false}
|
||||
isEditing={false}
|
||||
onSelect={vi.fn()}
|
||||
onDoubleClick={vi.fn()}
|
||||
onContextMenu={vi.fn()}
|
||||
onDragStart={vi.fn()}
|
||||
onDrop={vi.fn()}
|
||||
onRename={vi.fn()}
|
||||
onFinishEditing={vi.fn()}
|
||||
{...props}
|
||||
/>,
|
||||
)
|
||||
}
|
||||
|
||||
it('renders previews for the children of a folder', () => {
|
||||
const itemWithChildren: AssetInfo = {
|
||||
...folderItem,
|
||||
latestChildren: [
|
||||
{ type: 'image', preview: { proxyType: 'image', thumbnailUrl: 'http://x/thumb-1.png' } },
|
||||
{ type: 'image', preview: { proxyType: 'image', thumbnailUrl: 'http://x/thumb-2.png' } },
|
||||
],
|
||||
} as AssetInfo
|
||||
|
||||
renderComponent({ item: itemWithChildren })
|
||||
|
||||
const previews = screen.getAllByAltText('Preview')
|
||||
expect(previews).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('renders the days-left badge in the preview area for recently deleted folders', () => {
|
||||
const deletedItem: AssetInfo = {
|
||||
...folderItem,
|
||||
deletedAt: new Date().toISOString(),
|
||||
latestChildren: [
|
||||
{ type: 'image', preview: { proxyType: 'image', thumbnailUrl: 'http://x/thumb-1.png' } },
|
||||
],
|
||||
} as AssetInfo
|
||||
|
||||
renderComponent({ item: deletedItem, isRecentlyDeleted: true })
|
||||
|
||||
const badge = screen.getByTestId('folder-card-days-left')
|
||||
expect(badge.textContent).toMatch(/30\s*(d|天)/)
|
||||
// The badge must not hide the preview of the deleted folder's content
|
||||
expect(screen.getAllByAltText('Preview')).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('does not render the days-left badge outside of recently deleted', () => {
|
||||
const deletedItem: AssetInfo = {
|
||||
...folderItem,
|
||||
deletedAt: new Date().toISOString(),
|
||||
} as AssetInfo
|
||||
|
||||
renderComponent({ item: deletedItem, isRecentlyDeleted: false })
|
||||
expect(screen.queryByTestId('folder-card-days-left')).toBeNull()
|
||||
})
|
||||
|
||||
it('does not render the days-left badge when deletedAt is missing', () => {
|
||||
renderComponent({ item: folderItem, isRecentlyDeleted: true })
|
||||
expect(screen.queryByTestId('folder-card-days-left')).toBeNull()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user