Skip to content

Commit

Permalink
Build proper folder hierarchy
Browse files Browse the repository at this point in the history
Signed-off-by: Holger Dehnhardt <holger@dehnhardt.org>
  • Loading branch information
dehnhardt authored and ChristophWurst committed Aug 27, 2020
1 parent fbb4b0e commit 8c8784e
Show file tree
Hide file tree
Showing 4 changed files with 264 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/store/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export const getters = {
},
getSubMailboxes: (state, getters) => (id) => {
const mailbox = getters.getMailbox(id)

return mailbox.mailboxes.map((id) => state.mailboxes[id])
},
getUnifiedMailbox: (state) => (specialRole) => {
Expand Down
4 changes: 4 additions & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,27 @@ export default new Vuex.Store({
accountId: 0,
attributes: ['\\subscribed'],
isUnified: true,
path: '',
specialUse: ['inbox'],
specialRole: 'inbox',
unread: 0,
mailboxes: [],
envelopeLists: {},
name: 'UNIFIED INBOX',
},
[PRIORITY_INBOX_ID]: {
id: PRIORITY_INBOX_ID,
databaseId: PRIORITY_INBOX_ID,
accountId: 0,
attributes: ['\\subscribed'],
isPriorityInbox: true,
path: '',
specialUse: ['inbox'],
specialRole: 'inbox',
unread: 0,
mailboxes: [],
envelopeLists: {},
name: 'PRIORITY INBOX',
},
},
envelopes: {},
Expand Down
20 changes: 16 additions & 4 deletions src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,27 @@ export default {
)

// Save the mailboxes to the store, but only keep IDs in the account's mailboxes list
const mailboxes = buildMailboxHierarchy(sortMailboxes(account.mailboxes), havePrefix(account.mailboxes))
const mailboxes = sortMailboxes(account.mailboxes || [])
Vue.set(account, 'mailboxes', [])
const addToState = addMailboxToState(state, account)
mailboxes.forEach((mailbox) => {
mailbox.mailboxes = []
// Add all mailboxes (including submailboxes to state, but only toplevel to account
const id = addToState(mailbox)
Vue.set(mailbox, 'mailboxes', mailbox.mailboxes.map(addToState))
if (mailbox.name.includes(mailbox.delimiter)) {
mailbox.displayName = mailbox.name.substr(mailbox.name.lastIndexOf(mailbox.delimiter) + 1)
mailbox.path = mailbox.name.substr(0, mailbox.name.lastIndexOf(mailbox.delimiter))
} else {
mailbox.displayName = mailbox.name
mailbox.path = ''
}

account.mailboxes.push(id)
const id = addToState(mailbox)
const parent = Object.values(state.mailboxes).find(mb => mb.name === mailbox.path)
if (mailbox.path === '' || !parent) {
account.mailboxes.push(id)
} else {
parent.mailboxes.push(id)
}
})
},
editAccount(state, account) {
Expand Down
244 changes: 244 additions & 0 deletions src/tests/unit/store/mutations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,250 @@ import {
} from '../../../store/constants'

describe('Vuex store mutations', () => {
it('adds an account with no mailboxes', () => {
const state = {
accountList: [],
accounts: {},
envelopes: {},
mailboxes: {},
}

mutations.addAccount(state, {
accountId: 13,
id: 13,
mailboxes: [],
})

expect(state).to.deep.equal({
accountList: [13],
accounts: {
13: {
accountId: 13,
id: 13,
mailboxes: [],
collapsed: true,
},
},
envelopes: {},
mailboxes: {},
})
})

it('adds an account with one level of mailboxes', () => {
const state = {
accountList: [],
accounts: {},
envelopes: {},
mailboxes: {},
}

mutations.addAccount(state, {
accountId: 13,
id: 13,
mailboxes: [
{
databaseId: 345,
name: 'INBOX',
delimiter: '.',
},
],
})

expect(state).to.deep.equal({
accountList: [13],
accounts: {
13: {
accountId: 13,
id: 13,
mailboxes: [
345,
],
collapsed: true,
},
},
envelopes: {},
mailboxes: {
345: {
accountId: 13,
databaseId: 345,
name: 'INBOX',
displayName: 'INBOX',
delimiter: '.',
envelopeLists: {},
path: '',
mailboxes: [],
},
},
})
})

it('adds an account with two levels of mailboxes', () => {
const state = {
accountList: [],
accounts: {},
envelopes: {},
mailboxes: {},
}

mutations.addAccount(state, {
accountId: 13,
id: 13,
mailboxes: [
{
databaseId: 345,
name: 'Archive',
delimiter: '.',
specialUse: ['archive'],
specialRole: 'archive',
},
{
databaseId: 346,
name: 'Archive.2020',
delimiter: '.',
specialUse: ['archive'],
specialRole: 'archive',
},
],
})

expect(state).to.deep.equal({
accountList: [13],
accounts: {
13: {
accountId: 13,
id: 13,
mailboxes: [
345,
],
collapsed: true,
},
},
envelopes: {},
mailboxes: {
345: {
accountId: 13,
databaseId: 345,
name: 'Archive',
displayName: 'Archive',
delimiter: '.',
envelopeLists: {},
path: '',
specialUse: ['archive'],
specialRole: 'archive',
mailboxes: [
346,
],
},
346: {
accountId: 13,
databaseId: 346,
name: 'Archive.2020',
displayName: '2020',
delimiter: '.',
envelopeLists: {},
path: 'Archive',
specialUse: ['archive'],
specialRole: 'archive',
mailboxes: [],
},
},
})
})

it('adds an account with three levels of mailboxes', () => {
const state = {
accountList: [],
accounts: {},
envelopes: {},
mailboxes: {},
}

mutations.addAccount(state, {
accountId: 13,
id: 13,
mailboxes: [
{
databaseId: 345,
name: 'Archive',
delimiter: '.',
specialUse: ['archive'],
specialRole: 'archive',
},
{
databaseId: 346,
name: 'Archive.2020',
delimiter: '.',
specialUse: ['archive'],
specialRole: 'archive',
},
{
databaseId: 347,
name: 'Archive.2020.08',
delimiter: '.',
specialUse: ['archive'],
specialRole: 'archive',
},
],
})

expect(state).to.deep.equal({
accountList: [13],
accounts: {
13: {
accountId: 13,
id: 13,
mailboxes: [
345,
],
collapsed: true,
},
},
envelopes: {},
mailboxes: {
345: {
accountId: 13,
databaseId: 345,
name: 'Archive',
displayName: 'Archive',
delimiter: '.',
envelopeLists: {},
path: '',
specialUse: ['archive'],
specialRole: 'archive',
mailboxes: [
346,
],
},
346: {
accountId: 13,
databaseId: 346,
name: 'Archive.2020',
displayName: '2020',
delimiter: '.',
envelopeLists: {},
path: 'Archive',
specialUse: ['archive'],
specialRole: 'archive',
mailboxes: [
347,
],
},
347: {
accountId: 13,
databaseId: 347,
name: 'Archive.2020.08',
displayName: '08',
delimiter: '.',
envelopeLists: {},
path: 'Archive.2020',
specialUse: ['archive'],
specialRole: 'archive',
mailboxes: [],
},
},
})
})

it('adds envelopes', () => {
const state = {
accounts: {
Expand Down

0 comments on commit 8c8784e

Please sign in to comment.