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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file.
* Prefix the internal-address index with the user id
### Fixed
* Quick actions for special folders
* Prevent a stuck dialog when moving a folder onto itself
* Show the unified inbox icon
* Detect message language in the browser for translation
* Skip IMAP fetch results without a UID during sync
Expand Down
51 changes: 27 additions & 24 deletions src/components/MoveMailboxModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,36 @@ export default {
},

async onMove() {
if (this.mailbox.databaseId === this.destMailboxId) {
this.$emit('close')
return
}

this.moving = true
if (this.mailbox.id !== this.destMailboxId) {
try {
if (!this.destMailboxId) {
const newName = this.mailbox.displayName
await this.mainStore.renameMailbox({
account: this.account,
mailbox: this.mailbox,
newName,
})
} else {
const destMailbox = this.mainStore.getMailbox(this.destMailboxId)
const newName = destMailbox.name + this.mailbox.delimiter + this.mailbox.displayName
await this.mainStore.renameMailbox({
account: this.account,
mailbox: this.mailbox,
newName,
})
}
} catch (error) {
logger.error('could not move folder', {
error,
try {
if (!this.destMailboxId) {
const newName = this.mailbox.displayName
await this.mainStore.renameMailbox({
account: this.account,
mailbox: this.mailbox,
newName,
})
} else {
const destMailbox = this.mainStore.getMailbox(this.destMailboxId)
const newName = destMailbox.name + this.mailbox.delimiter + this.mailbox.displayName
await this.mainStore.renameMailbox({
account: this.account,
mailbox: this.mailbox,
newName,
})
} finally {
this.moving = false
this.$emit('close')
}
} catch (error) {
logger.error('could not move folder', {
error,
})
} finally {
this.moving = false
this.$emit('close')
}
},

Expand Down
73 changes: 73 additions & 0 deletions src/tests/unit/components/MoveMailboxModal.vue.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { createTestingPinia } from '@pinia/testing'
import { createLocalVue, shallowMount } from '@vue/test-utils'
import { PiniaVuePlugin, setActivePinia } from 'pinia'
import MoveMailboxModal from '../../../components/MoveMailboxModal.vue'
import Nextcloud from '../../../mixins/Nextcloud.js'
import useMainStore from '../../../store/mainStore.js'

const localVue = createLocalVue()
localVue.use(PiniaVuePlugin)
localVue.mixin(Nextcloud)

describe('MoveMailboxModal', () => {
let store

const mount = (mailbox) => shallowMount(MoveMailboxModal, {
propsData: {
account: { accountId: 1 },
mailbox,
},
localVue,
})

beforeEach(() => {
setActivePinia(createTestingPinia())
store = useMainStore()
store.renameMailbox = vi.fn().mockResolvedValue()
})

it('treats selecting the same mailbox as a no-op and closes', async () => {
store.getMailbox = vi.fn().mockReturnValue({ name: 'INBOX' })
const view = mount({ databaseId: 7, id: 'SU5CT1g=', displayName: 'INBOX', delimiter: '.' })
view.vm.destMailboxId = 7

await view.vm.onMove()

expect(store.renameMailbox).not.toHaveBeenCalled()
expect(view.vm.moving).toBe(false)
expect(view.emitted().close).toBeTruthy()
})

it('moves the folder when the destination differs and resets state', async () => {
store.getMailbox = vi.fn().mockReturnValue({ name: 'Archive' })
const view = mount({ databaseId: 7, id: 'SU5CT1g=', displayName: 'INBOX', delimiter: '.' })
view.vm.destMailboxId = 9

await view.vm.onMove()

expect(store.renameMailbox).toHaveBeenCalledWith({
account: { accountId: 1 },
mailbox: view.vm.mailbox,
newName: 'Archive.INBOX',
})
expect(view.vm.moving).toBe(false)
expect(view.emitted().close).toBeTruthy()
})

it('resets moving state after a failed move', async () => {
store.getMailbox = vi.fn().mockReturnValue({ name: 'Archive' })
store.renameMailbox = vi.fn().mockRejectedValue(new Error('IMAP error'))
const view = mount({ databaseId: 7, id: 'SU5CT1g=', displayName: 'INBOX', delimiter: '.' })
view.vm.destMailboxId = 9

await view.vm.onMove()

expect(view.vm.moving).toBe(false)
expect(view.emitted().close).toBeTruthy()
})
})