Skip to content

Commit 015fad2

Browse files
authored
Merge pull request #5688 from nextcloud/fix/addressbook-checkbox
fix: addressbook checkbox
2 parents f16791f + bde7194 commit 015fad2

2 files changed

Lines changed: 51 additions & 8 deletions

File tree

src/store/addressbooks.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,25 +108,25 @@ const mutations = {
108108
/**
109109
* Toggle whether a Addressbook is Enabled
110110
*
111-
* @param {object} context the store mutations
111+
* @param {object} state the store data
112112
* @param {object} addressbook the addressbook to toggle
113113
*/
114-
toggleAddressbookEnabled(context, addressbook) {
115-
addressbook = state.addressbooks.find((search) => search.id === addressbook.id)
116-
addressbook.enabled = !addressbook.enabled
114+
toggleAddressbookEnabled(state, addressbook) {
115+
const storedAddressbook = state.addressbooks.find((search) => search.id === addressbook.id)
116+
storedAddressbook.enabled = !storedAddressbook.enabled
117117
},
118118

119119
/**
120120
* Rename a Addressbook
121121
*
122-
* @param {object} context the store mutations
122+
* @param {object} state the store data
123123
* @param {object} data destructuring object
124124
* @param {object} data.addressbook the addressbook to rename
125125
* @param {string} data.newName the new name of the addressbook
126126
*/
127-
renameAddressbook(context, { addressbook, newName }) {
128-
addressbook = state.addressbooks.find((search) => search.id === addressbook.id)
129-
addressbook.displayName = newName
127+
renameAddressbook(state, { addressbook, newName }) {
128+
const storedAddressbook = state.addressbooks.find((search) => search.id === addressbook.id)
129+
storedAddressbook.displayName = newName
130130
},
131131

132132
/**
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { computed } from 'vue'
7+
// The store index has to be imported first to avoid a circular import issue
8+
import store from '../../../src/store/index.js'
9+
10+
describe('addressbooks mutations', () => {
11+
beforeEach(() => {
12+
store.state.addressbooks.addressbooks.splice(0)
13+
store.commit('addAddressbook', {
14+
id: 'ab1',
15+
displayName: 'Address book',
16+
enabled: true,
17+
url: '/remote.php/dav/addressbooks/users/admin/ab1/',
18+
})
19+
})
20+
21+
test('toggleAddressbookEnabled updates the reactive state', () => {
22+
const addressbook = store.getters.getAddressbooks[0]
23+
const enabled = computed(() => addressbook.enabled)
24+
expect(enabled.value).toBe(true)
25+
26+
store.commit('toggleAddressbookEnabled', addressbook)
27+
28+
expect(addressbook.enabled).toBe(false)
29+
// the change has to be picked up by reactive consumers, e.g. the settings dialog
30+
expect(enabled.value).toBe(false)
31+
})
32+
33+
test('renameAddressbook updates the reactive state', () => {
34+
const addressbook = store.getters.getAddressbooks[0]
35+
const displayName = computed(() => addressbook.displayName)
36+
expect(displayName.value).toBe('Address book')
37+
38+
store.commit('renameAddressbook', { addressbook, newName: 'Renamed' })
39+
40+
expect(addressbook.displayName).toBe('Renamed')
41+
expect(displayName.value).toBe('Renamed')
42+
})
43+
})

0 commit comments

Comments
 (0)