Skip to content

Commit c5977e1

Browse files
committed
refactor(settings): switch wipe dialog to confirm
Signed-off-by: Peter Ringelmann <peter.ringelmann@nextcloud.com>
1 parent edabe34 commit c5977e1

3 files changed

Lines changed: 27 additions & 83 deletions

File tree

apps/settings/src/components/AuthToken.spec.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ vi.hoisted(() => {
1616

1717
import type { IToken } from '../store/authtoken.ts'
1818

19+
// Mock @nextcloud/dialogs so the wipe action's showConfirmation call resolves
20+
// synchronously in tests. Hoisted so it's installed before AuthToken.vue imports.
21+
const showConfirmationMock = vi.hoisted(() => vi.fn())
22+
vi.mock('@nextcloud/dialogs', () => ({
23+
showConfirmation: showConfirmationMock,
24+
}))
25+
1926
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
2027
import AuthToken from './AuthToken.vue'
2128
import AuthTokenDeleteDialog from './AuthTokenDeleteDialog.vue'
22-
import AuthTokenWipeDialog from './AuthTokenWipeDialog.vue'
2329
import { TokenType, useAuthTokenStore } from '../store/authtoken.ts'
2430
import { detect } from '../utils/userAgentDetect.ts'
2531

@@ -143,33 +149,27 @@ describe('AuthToken wipe flow', () => {
143149
vi.clearAllMocks()
144150
})
145151

146-
it('does not call wipeToken when the wipe action is triggered (dialog opens first)', async () => {
152+
it('does not call wipeToken when the user rejects the confirmation', async () => {
153+
showConfirmationMock.mockResolvedValueOnce(false)
147154
const token = makeToken()
148155
const wrapper = mountAuthToken(token)
149156
const store = useAuthTokenStore()
150157

151-
;(wrapper.vm as unknown as { wipe: () => void }).wipe()
152-
await wrapper.vm.$nextTick()
158+
await (wrapper.vm as unknown as { wipe: () => Promise<void> }).wipe()
153159

154-
const dialog = wrapper.findComponent(AuthTokenWipeDialog)
155-
expect(dialog.exists()).toBe(true)
156-
expect(dialog.props('open')).toBe(true)
160+
expect(showConfirmationMock).toHaveBeenCalledTimes(1)
157161
expect(store.wipeToken).not.toHaveBeenCalled()
158162
})
159163

160-
it('calls wipeToken only after the dialog emits confirm', async () => {
164+
it('calls wipeToken when the user accepts the confirmation', async () => {
165+
showConfirmationMock.mockResolvedValueOnce(true)
161166
const token = makeToken()
162167
const wrapper = mountAuthToken(token)
163168
const store = useAuthTokenStore()
164169

165-
;(wrapper.vm as unknown as { wipe: () => void }).wipe()
166-
await wrapper.vm.$nextTick()
167-
168-
const dialog = wrapper.findComponent(AuthTokenWipeDialog)
169-
dialog.vm.$emit('confirm')
170-
dialog.vm.$emit('update:open', false)
171-
await wrapper.vm.$nextTick()
170+
await (wrapper.vm as unknown as { wipe: () => Promise<void> }).wipe()
172171

172+
expect(showConfirmationMock).toHaveBeenCalledTimes(1)
173173
expect(store.wipeToken).toHaveBeenCalledTimes(1)
174174
expect(store.wipeToken).toHaveBeenCalledWith(token)
175175
})

apps/settings/src/components/AuthToken.vue

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@
8787
:token="token"
8888
:open.sync="deleteDialogOpen"
8989
@confirm="confirmDelete" />
90-
<AuthTokenWipeDialog
91-
v-if="wipeDialogOpen"
92-
:token="token"
93-
:open.sync="wipeDialogOpen"
94-
@confirm="confirmWipe" />
9590
</tr>
9691
</template>
9792

@@ -100,6 +95,7 @@ import type { PropType } from 'vue'
10095
import type { IToken } from '../store/authtoken.ts'
10196
10297
import { mdiAndroid, mdiAppleIos, mdiAppleSafari, mdiCellphone, mdiCheck, mdiFirefox, mdiGoogleChrome, mdiKeyOutline, mdiMicrosoftEdge, mdiMonitor, mdiTablet, mdiWeb } from '@mdi/js'
98+
import { showConfirmation } from '@nextcloud/dialogs'
10399
import { translate as t } from '@nextcloud/l10n'
104100
import { defineComponent } from 'vue'
105101
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
@@ -110,7 +106,6 @@ import NcDateTime from '@nextcloud/vue/components/NcDateTime'
110106
import NcIconSvgWrapper from '@nextcloud/vue/components/NcIconSvgWrapper'
111107
import NcTextField from '@nextcloud/vue/components/NcTextField'
112108
import AuthTokenDeleteDialog from './AuthTokenDeleteDialog.vue'
113-
import AuthTokenWipeDialog from './AuthTokenWipeDialog.vue'
114109
import { TokenType, useAuthTokenStore } from '../store/authtoken.ts'
115110
import { detect } from '../utils/userAgentDetect.ts'
116111
@@ -137,7 +132,6 @@ export default defineComponent({
137132
name: 'AuthToken',
138133
components: {
139134
AuthTokenDeleteDialog,
140-
AuthTokenWipeDialog,
141135
NcActions,
142136
NcActionButton,
143137
NcActionCheckbox,
@@ -166,7 +160,6 @@ export default defineComponent({
166160
newName: '',
167161
oldName: '',
168162
deleteDialogOpen: false,
169-
wipeDialogOpen: false,
170163
mdiCheck,
171164
TokenType,
172165
}
@@ -306,13 +299,18 @@ export default defineComponent({
306299
this.authTokenStore.renameToken(this.token, this.newName)
307300
},
308301
309-
wipe() {
302+
async wipe() {
310303
this.actionOpen = false
311-
this.wipeDialogOpen = true
312-
},
313-
314-
confirmWipe() {
315-
this.authTokenStore.wipeToken(this.token)
304+
const confirmed = await showConfirmation({
305+
name: t('settings', 'Confirm wipe'),
306+
text: t('settings', 'Do you really want to wipe your data from this device?'),
307+
labelConfirm: t('settings', 'Wipe device'),
308+
labelReject: t('settings', 'Cancel'),
309+
severity: 'warning',
310+
})
311+
if (confirmed) {
312+
this.authTokenStore.wipeToken(this.token)
313+
}
316314
},
317315
},
318316
})

apps/settings/src/components/AuthTokenWipeDialog.vue

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)