-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add navigate to trash for spaces (#10179)
* Add navigate to trash for spaces * Update snapshots * fix func signature * Add unit tests
- Loading branch information
1 parent
2b3fe6a
commit 3daa591
Showing
6 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
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,6 @@ | ||
Bugfix: Space navigate to trash missing | ||
|
||
We've fixed the bug that it was not possible to directly navigate into a space-specific trash, | ||
from within the space root. | ||
|
||
https://github.com/owncloud/web/pull/10179 |
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
51 changes: 51 additions & 0 deletions
51
packages/web-pkg/src/composables/actions/spaces/useSpaceActionsNavigateToTrash.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,51 @@ | ||
import { computed } from 'vue' | ||
import { SpaceAction } from '../types' | ||
import { useGettext } from 'vue3-gettext' | ||
import { useRouter } from '../../router' | ||
import { SpaceResource } from '@ownclouders/web-client' | ||
import { createLocationTrash } from '../../../router' | ||
import { createFileRouteOptions } from '../../../helpers' | ||
import { isProjectSpaceResource } from '@ownclouders/web-client/src/helpers' | ||
|
||
export const useSpaceActionsNavigateToTrash = () => { | ||
const router = useRouter() | ||
const { $gettext } = useGettext() | ||
|
||
const getTrashLink = (space: SpaceResource) => { | ||
return createLocationTrash('files-trash-generic', { | ||
...createFileRouteOptions(space, { fileId: space.fileId }) | ||
}) | ||
} | ||
|
||
const actions = computed((): SpaceAction[] => [ | ||
{ | ||
name: 'navigateToTrash', | ||
icon: 'delete-bin', | ||
label: () => $gettext('Show deleted files'), | ||
handler: ({ resources }) => { | ||
router.push(getTrashLink(resources[0])) | ||
}, | ||
isEnabled: ({ resources }) => { | ||
if (resources.length !== 1) { | ||
return false | ||
} | ||
|
||
if (!isProjectSpaceResource(resources[0])) { | ||
return false | ||
} | ||
|
||
if (resources[0].disabled) { | ||
return false | ||
} | ||
|
||
return true | ||
}, | ||
componentType: 'button', | ||
class: 'oc-files-actions-navigate-to-trash-trigger' | ||
} | ||
]) | ||
|
||
return { | ||
actions | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
...ages/web-pkg/tests/unit/composables/actions/spaces/useSpaceActionsNavigateToTrash.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,103 @@ | ||
import { useSpaceActionsNavigateToTrash } from '../../../../../src' | ||
import { mock } from 'jest-mock-extended' | ||
import { | ||
createStore, | ||
defaultComponentMocks, | ||
defaultStoreMockOptions, | ||
RouteLocation, | ||
getComposableWrapper | ||
} from 'web-test-helpers' | ||
import { unref } from 'vue' | ||
import { SpaceResource } from '@ownclouders/web-client/src' | ||
|
||
describe('navigateToSpace', () => { | ||
describe('isEnabled property', () => { | ||
it('should be false when no resource given', () => { | ||
getWrapper({ | ||
setup: ({ actions }) => { | ||
expect(unref(actions)[0].isEnabled({ resources: [] })).toBe(false) | ||
} | ||
}) | ||
}) | ||
it('should be false when the space is disabled', () => { | ||
getWrapper({ | ||
setup: ({ actions }) => { | ||
expect( | ||
unref(actions)[0].isEnabled({ | ||
resources: [ | ||
mock<SpaceResource>({ | ||
disabled: true, | ||
driveType: 'project' | ||
}) | ||
] | ||
}) | ||
).toBe(false) | ||
} | ||
}) | ||
}) | ||
it('should be false when the space is no project space', () => { | ||
getWrapper({ | ||
setup: ({ actions }) => { | ||
expect( | ||
unref(actions)[0].isEnabled({ | ||
resources: [ | ||
mock<SpaceResource>({ | ||
disabled: false, | ||
driveType: 'personal' | ||
}) | ||
] | ||
}) | ||
).toBe(false) | ||
} | ||
}) | ||
}) | ||
}) | ||
describe('handler', () => { | ||
it('should redirect to respective trash', async () => { | ||
const { mocks } = getWrapper({ | ||
setup: async ({ actions }) => { | ||
await unref(actions)[0].handler({ | ||
resources: [mock<SpaceResource>()] | ||
}) | ||
expect(mocks.$router.push).toHaveBeenCalled() | ||
} | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
function getWrapper({ | ||
setup | ||
}: { | ||
setup: ( | ||
instance: ReturnType<typeof useSpaceActionsNavigateToTrash>, | ||
{ | ||
storeOptions | ||
}: { | ||
storeOptions: typeof defaultStoreMockOptions | ||
} | ||
) => void | ||
}) { | ||
const storeOptions = { | ||
...defaultStoreMockOptions, | ||
modules: { ...defaultStoreMockOptions.modules, user: { state: { id: 'alice', uuid: 1 } } } | ||
} | ||
const store = createStore(storeOptions) | ||
const mocks = defaultComponentMocks({ | ||
currentRoute: mock<RouteLocation>({ name: 'files-spaces-projects' }) | ||
}) | ||
return { | ||
mocks, | ||
wrapper: getComposableWrapper( | ||
() => { | ||
const instance = useSpaceActionsNavigateToTrash() | ||
setup(instance, { storeOptions }) | ||
}, | ||
{ | ||
store, | ||
mocks, | ||
provide: mocks | ||
} | ||
) | ||
} | ||
} |