Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isSpaceResource, SpaceResource } from '@opencloud-eu/web-client'
import { isSpaceResource, isTrashResource, SpaceResource } from '@opencloud-eu/web-client'
import { computed } from 'vue'
import { useClientService } from '../../clientService'
import { useGettext } from 'vue3-gettext'
Expand All @@ -22,16 +22,18 @@ export const useFileActionsEmptyTrashBin = () => {
const { dispatchModal } = useModals()
const resourcesStore = useResourcesStore()
const spacesStore = useSpacesStore()

const loadingService = useLoadingService()

const emptyTrashBin = async ({ space }: { space: SpaceResource }) => {
try {
await clientService.webdav.clearTrashBin(space)
showMessage({ title: $gettext('All deleted files were removed') })
resourcesStore.clearResources()
resourcesStore.resetSelection()
spacesStore.updateSpaceField({ id: space.id, field: 'hasTrashedItems', value: false })
if (resourcesStore.resources.some(isTrashResource)) {
// trash resources mean we're inside a trash bin, hence we clear all resources
resourcesStore.clearResources()
}
} catch (error) {
console.error(error)
showErrorMessage({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import {
RouteLocation
} from '@opencloud-eu/web-test-helpers'
import { unref } from 'vue'
import { ProjectSpaceResource, SpaceResource } from '@opencloud-eu/web-client'
import {
ProjectSpaceResource,
Resource,
SpaceResource,
TrashResource
} from '@opencloud-eu/web-client'

describe('emptyTrashBin', () => {
describe('isVisible property', () => {
Expand Down Expand Up @@ -92,14 +97,26 @@ describe('emptyTrashBin', () => {

expect(showMessage).toHaveBeenCalledTimes(1)

expect(clearResources).toHaveBeenCalledTimes(1)
expect(clearResources).not.toHaveBeenCalled()
expect(resetSelection).toHaveBeenCalledTimes(1)

expect(updateSpaceField).toHaveBeenCalledTimes(1)
}
})
})

it('should clear resources when trash resources are present in the file list', () => {
getWrapper({
resources: [mock<TrashResource>({ ddate: 'date' })],
setup: async ({ emptyTrashBin }, { space }) => {
await emptyTrashBin({ space })

const { clearResources } = useResourcesStore()
expect(clearResources).toHaveBeenCalledTimes(1)
}
})
})

it('should show message on error', () => {
vi.spyOn(console, 'error').mockImplementation(() => undefined)

Expand Down Expand Up @@ -128,11 +145,13 @@ function getWrapper({
invalidLocation = false,
resolveClearTrashBin = true,
driveType = 'personal',
resources = [],
setup
}: {
invalidLocation?: boolean
resolveClearTrashBin?: boolean
driveType?: string
resources?: Resource[]
setup: (
instance: ReturnType<typeof useFileActionsEmptyTrashBin>,
{
Expand Down Expand Up @@ -165,7 +184,8 @@ function getWrapper({
},
{
mocks,
provide: mocks
provide: mocks,
pluginOptions: { piniaOptions: { resourcesStore: { resources } } }
}
)
}
Expand Down