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
23 changes: 13 additions & 10 deletions src/components/AppNavigation/GroupNavigationItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,22 @@ export default {
async onDrop(event, group) {
try {
const contactFromDropData = JSON.parse(event.dataTransfer.getData('item'))
const contactFromStore = this.$store.getters.getContact(Buffer.from(`${contactFromDropData.uid}~${contactFromDropData.addressbookId}`, 'utf-8').toString('base64'))
if (contactFromStore && !this.isInGroup(contactFromStore.groups, group.id)) {
const contact = this.$store.getters.getContact(Buffer.from(`${contactFromDropData.uid}~${contactFromDropData.addressbookId}`, 'utf-8').toString('base64'))
const contactId = Buffer.from(`${contactFromDropData.uid}~${contactFromDropData.addressbookId}`, 'utf-8').toString('base64')
let contact = this.$store.getters.getContact(contactId)
if (!contact) {
return
}

await this.$store.dispatch('fetchFullContact', { contact })
contact = this.$store.getters.getContact(contactId)

if (!this.isInGroup(contact.groups, group.id)) {
contact.groups = [...contact.groups, group.name]
await this.$store.dispatch('updateContactGroups', {
groupNames: [...contactFromStore.groups, group.name],
groupNames: contact.groups,
contact,
})
const localContact = Object.assign(
Object.create(Object.getPrototypeOf(contact)),
contact,
)
localContact.groups = [...contactFromStore.groups, group.name]
await this.$store.dispatch('updateContact', localContact)
await this.$store.dispatch('updateContact', contact)
}
} catch (e) {
console.error(e)
Expand Down
34 changes: 34 additions & 0 deletions tests/javascript/models/contact.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,37 @@ describe('Test stripping quotes from TYPE', () => {
})

})

describe('Test groups setter', () => {

let contact

beforeEach(() => {
contact = new Contact(
'BEGIN:VCARD\nVERSION:3.0\nUID:123456789-123465-123456-123456789\nFN:Test contact\nEND:VCARD',
)
})

test('groups setter updates jCal so the group is included in serialization', () => {
contact.groups = ['Friends']

expect(contact.groups).toEqual(['Friends'])
expect(contact.vCard.toString()).toContain('CATEGORIES:Friends')
})

test('groups setter replaces existing groups', () => {
contact.groups = ['OldGroup']
contact.groups = ['NewGroup']

expect(contact.groups).toEqual(['NewGroup'])
})

test('groups setter with empty array removes categories property', () => {
contact.groups = ['SomeGroup']
contact.groups = []

expect(contact.groups).toEqual([])
expect(contact.vCard.hasProperty('categories')).toBe(false)
})

})