Skip to content
Open
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
Expand Up @@ -253,7 +253,7 @@ export default defineComponent({
}),
onConfirm: (expirationDateTime: DateTime) => {
this.$emit('expirationDateChanged', {
expirationDateTime
expirationDateTime: expirationDateTime?.toISO() ?? null
})
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,8 @@ export default defineComponent({
this.selectedRole = role
},

collaboratorExpiryChanged({ expirationDate }: { expirationDate: string }) {
this.expirationDate = expirationDate
collaboratorExpiryChanged({ expirationDate }: { expirationDate: DateTime }) {
this.expirationDate = expirationDate?.toISO() ?? null
;(this.$refs.showMoreShareOptionsDropRef as InstanceType<typeof OcDrop>).hide()
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default defineComponent({
onConfirm: (expirationDateTime: DateTime) => {
emit('updateLink', {
linkShare: { ...props.linkShare },
options: { expirationDateTime }
options: { expirationDateTime: expirationDateTime?.toISO() ?? null }
})
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defaultPlugins, PartialComponentProps, shallowMount } from '@opencloud-
import { mock } from 'vitest-mock-extended'
import { Resource } from '@opencloud-eu/web-client'
import { OcButton } from '@opencloud-eu/design-system/components'
import { DateTime } from 'luxon'

const selectors = {
editBtn: '.collaborator-edit-dropdown-options-btn',
Expand Down Expand Up @@ -46,6 +47,35 @@ describe('EditDropdown', () => {
const { wrapper } = getWrapper({ canEdit: false })
expect(wrapper.find(selectors.expireDateMenuAction).exists()).toBeFalsy()
})
it('emits an ISO string when the date picker confirms a DateTime', () => {
const { wrapper } = getWrapper({ canEdit: true })

const dispatchModalSpy = vi.spyOn(wrapper.vm, 'dispatchModal')
wrapper.vm.showDatePickerModal()

const onConfirm = dispatchModalSpy.mock.calls[0][0].onConfirm
const expirationDateTime = DateTime.fromISO('2026-12-31T00:00:00.000Z')
onConfirm(expirationDateTime)

expect(wrapper.emitted('expirationDateChanged')).toBeTruthy()
expect(wrapper.emitted('expirationDateChanged')[0][0]).toEqual({
expirationDateTime: expirationDateTime.toISO()
})
})
it('emits null when the date picker confirms with null', () => {
const { wrapper } = getWrapper({ canEdit: true })

const dispatchModalSpy = vi.spyOn(wrapper.vm, 'dispatchModal')
wrapper.vm.showDatePickerModal()

const onConfirm = dispatchModalSpy.mock.calls[0][0].onConfirm
onConfirm(null)

expect(wrapper.emitted('expirationDateChanged')).toBeTruthy()
expect(wrapper.emitted('expirationDateChanged')[0][0]).toEqual({
expirationDateTime: null
})
})
})
describe('navigate to parent action', () => {
it('is being rendered when sharedParentRoute is given', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import InviteCollaboratorForm from '../../../../../../../src/components/SideBar/
import {
defaultComponentMocks,
defaultPlugins,
ocDropStub,
RouteLocation,
shallowMount
} from '@opencloud-eu/web-test-helpers'
Expand All @@ -17,6 +18,7 @@ import { Group, User } from '@opencloud-eu/web-client/graph/generated'
import { OcButton } from '@opencloud-eu/design-system/components'
import RoleDropdown from '../../../../../../../src/components/SideBar/Shares/Collaborators/RoleDropdown.vue'
import { ShareRoleType } from '../../../../../../../src/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.vue'
import { DateTime } from 'luxon'

vi.mock('lodash-es', () => ({ debounce: (fn: any) => fn() }))

Expand Down Expand Up @@ -145,6 +147,41 @@ describe('InviteCollaboratorForm', () => {

expect(addShare).toHaveBeenCalled()
})
it('passes the expiration date set via collaboratorExpiryChanged to addShare', async () => {
const { wrapper } = getWrapper({}, { OcDrop: ocDropStub })

wrapper.vm.selectedCollaborators = [mock<CollaboratorAutoCompleteItem>()]

const expirationDateTime = DateTime.fromISO('2026-12-31T00:00:00.000Z')
wrapper.vm.collaboratorExpiryChanged({ expirationDate: expirationDateTime })

const { addShare } = useSharesStore()
vi.mocked(addShare).mockResolvedValue(undefined)

await wrapper.vm.$nextTick()
await wrapper.vm.share()

expect(addShare).toHaveBeenCalledWith(
expect.objectContaining({
options: expect.objectContaining({
expirationDateTime: expirationDateTime.toISO()
})
})
)
})
it('converts DateTime to ISO string in collaboratorExpiryChanged', () => {
const { wrapper } = getWrapper({}, { OcDrop: ocDropStub })

const expirationDateTime = DateTime.fromISO('2026-12-31T00:00:00.000Z')
wrapper.vm.collaboratorExpiryChanged({ expirationDate: expirationDateTime })

expect(wrapper.vm.expirationDate).toBe(expirationDateTime.toISO())
})
it('sets expirationDate to null when DateTime is null', () => {
const { wrapper } = getWrapper({}, { OcDrop: ocDropStub })
wrapper.vm.collaboratorExpiryChanged({ expirationDate: null })
expect(wrapper.vm.expirationDate).toBeNull()
})
it.todo('resets focus upon selecting an invitee')
})
describe('share role type filter', () => {
Expand Down Expand Up @@ -177,23 +214,26 @@ describe('InviteCollaboratorForm', () => {
})
})

function getWrapper({
storageId = 'fake-storage-id',
resource = mock<Resource>(folderMock),
users = [],
groups = [],
existingCollaborators = [],
externalShareRoles = [],
user = mock<User>({ id: '1' })
}: {
storageId?: string
resource?: Resource
users?: User[]
groups?: Group[]
existingCollaborators?: CollaboratorShare[]
externalShareRoles?: ShareRole[]
user?: User
} = {}) {
function getWrapper(
{
storageId = 'fake-storage-id',
resource = mock<Resource>(folderMock),
users = [],
groups = [],
existingCollaborators = [],
externalShareRoles = [],
user = mock<User>({ id: '1' })
}: {
storageId?: string
resource?: Resource
users?: User[]
groups?: Group[]
existingCollaborators?: CollaboratorShare[]
externalShareRoles?: ShareRole[]
user?: User
} = {},
additionalStubs: Record<string, unknown> = {}
) {
const mocks = defaultComponentMocks({
currentRoute: mock<RouteLocation>({ params: { storageId } })
})
Expand Down Expand Up @@ -226,7 +266,7 @@ function getWrapper({
availableInternalShareRoles: [mock<ShareRole>()]
},
mocks,
stubs: { OcSelect: false, VueSelect: false }
stubs: { OcSelect: false, VueSelect: false, ...additionalStubs }
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import { mock } from 'vitest-mock-extended'
import {
AncestorMetaDataValue,
useGetMatchingSpace,
useModals,
useResourcesStore
} from '@opencloud-eu/web-pkg'
import { SharingLinkType } from '@opencloud-eu/web-client/graph/generated'
import { Resource } from '@opencloud-eu/web-client'
import { DateTime } from 'luxon'

vi.mock('@opencloud-eu/web-pkg', async (importOriginal) => ({
...(await importOriginal<any>()),
Expand Down Expand Up @@ -58,6 +60,53 @@ describe('EditDropdown component', () => {
const { wrapper } = getWrapper()
expect(wrapper.vm.editOptions.some((option) => option.id === 'add-expiration')).toBeTruthy()
})
it('emits an ISO string when the date picker confirms a DateTime', () => {
const linkShareWithExpiration = {
...exampleLink,
expirationDateTime: '2026-12-01T00:00:00.000Z'
} as LinkShare

const { wrapper } = getWrapper({ linkShare: linkShareWithExpiration })
const modalsStore = useModals()
const dispatchModalSpy = vi.spyOn(modalsStore, 'dispatchModal')

const editExpirationOption = wrapper.vm.editOptions.find(
(option) => option.id === 'edit-expiration'
)
editExpirationOption.method()

const onConfirm = dispatchModalSpy.mock.calls[0][0].onConfirm
const expirationDateTime = DateTime.fromISO('2026-12-31T00:00:00.000Z')
onConfirm(expirationDateTime)

expect(wrapper.emitted('updateLink')).toBeTruthy()
expect(wrapper.emitted('updateLink')[0][0]).toMatchObject({
options: { expirationDateTime: expirationDateTime.toISO() }
})
})
it('emits null when the date picker confirms with null', () => {
const linkShareWithExpiration = {
...exampleLink,
expirationDateTime: '2026-12-01T00:00:00.000Z'
} as LinkShare

const { wrapper } = getWrapper({ linkShare: linkShareWithExpiration })
const modalsStore = useModals()
const dispatchModalSpy = vi.spyOn(modalsStore, 'dispatchModal')

const editExpirationOption = wrapper.vm.editOptions.find(
(option) => option.id === 'edit-expiration'
)
editExpirationOption.method()

const onConfirm = dispatchModalSpy.mock.calls[0][0].onConfirm
onConfirm(null)

expect(wrapper.emitted('updateLink')).toBeTruthy()
expect(wrapper.emitted('updateLink')[0][0]).toMatchObject({
options: { expirationDateTime: null }
})
})
})
describe('rename', () => {
it('does not contain "rename" option if user cannot rename the link', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/web-app-search/tests/unit/portals/SearchBar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe('Search Bar portal component', () => {
})
wrapper
.findComponent<typeof SearchBarFilter>(selectors.searchFilters)
.vm.$emit('update:model-value', {
.vm.$emit('update:modelValue', {
value: { id: SearchLocationFilterConstants.currentFolder }
})

Expand All @@ -208,7 +208,7 @@ describe('Search Bar portal component', () => {
const { wrapper } = getMountedWrapper()
wrapper
.findComponent<typeof SearchBarFilter>(selectors.searchFilters)
.vm.$emit('update:model-value', {
.vm.$emit('update:modelValue', {
value: { id: SearchLocationFilterConstants.currentFolder }
})

Expand Down
2 changes: 1 addition & 1 deletion packages/web-pkg/src/components/Filters/DateFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ const setDateRangeDate = (
type: 'from' | 'to'
) => {
if (error) {
console.error('date could not be set')
console.warn('date could not be set')
return
}

Expand Down
3 changes: 1 addition & 2 deletions packages/web-pkg/tests/unit/services/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const getClientServiceMock = () => {
})
}
const v4uuid = '00000000-0000-0000-0000-000000000000'
vi.mock('../../../src/http')
vi.mock('uuid', () => ({ v4: () => v4uuid }))
vi.mock('@opencloud-eu/web-client', async (importOriginal) => ({
...(await importOriginal<any>()),
Expand All @@ -42,7 +43,6 @@ describe('ClientService', () => {
expect(clientService.httpAuthenticated).toBeInstanceOf(HttpClient)
})
it('initializes the http client with baseURL and static headers', () => {
vi.mock('../../../src/http')
const mocky = vi.mocked(HttpClient)
getClientServiceMock()

Expand All @@ -61,7 +61,6 @@ describe('ClientService', () => {
expect(clientService.httpUnAuthenticated).toBeInstanceOf(HttpClient)
})
it('initializes the http client with baseURL and static headers', () => {
vi.mock('../../../src/http')
const mocky = vi.mocked(HttpClient)
getClientServiceMock()

Expand Down