refactor(08-03): migrate session-revoked inline toast to toastStore.show()

- Remove sessionRevokedToast ref + setTimeout + inline HTML from SettingsAccountTab.vue
- Remove sessionRevokedToast ref + setTimeout + inline HTML from TotpEnrollment.vue
- Add toastStore.show('Other sessions have been terminated.', 'success') in changePassword
- Add toastStore.show('Other sessions have been terminated.', 'success') in disableTotp
- Add toastStore.show('Other sessions have been terminated.', 'success') in confirmEnrollment
- Update SettingsAccountTab.test.js to assert on mockShow instead of DOM text
- Update TotpEnrollment.test.js to assert on mockShow instead of DOM text
This commit is contained in:
curo1305
2026-06-08 16:34:44 +02:00
parent e417b71539
commit 3b8e2c1bd4
4 changed files with 32 additions and 62 deletions
@@ -18,12 +18,19 @@ vi.mock('../../../api/client.js', () => ({
totpEnable: vi.fn(),
}))
// Mock toast store — capture show() calls so we can assert on them
const mockShow = vi.fn()
vi.mock('../../../stores/toast.js', () => ({
useToastStore: () => ({ show: mockShow }),
}))
import { totpEnable as totpEnableMock } from '../../../api/client.js'
import TotpEnrollment from '../TotpEnrollment.vue'
beforeEach(() => {
setActivePinia(createPinia())
vi.clearAllMocks()
mockShow.mockClear()
})
describe('TotpEnrollment — QR code rendering (AUTH-03)', () => {
@@ -90,7 +97,7 @@ describe('TotpEnrollment — sessions revoked toast (CR-02)', () => {
BackupCodesDisplay: { template: '<div />', props: ['codes'] },
}
it('renders "Other sessions have been terminated." after totpEnable returns sessions_revoked > 0 (CR-02)', async () => {
it('calls toastStore.show("Other sessions have been terminated.") after totpEnable returns sessions_revoked > 0 (CR-02)', async () => {
vi.mocked(totpEnableMock).mockResolvedValueOnce({
backup_codes: ['CODE1', 'CODE2'],
sessions_revoked: 1,
@@ -118,10 +125,10 @@ describe('TotpEnrollment — sessions revoked toast (CR-02)', () => {
await verifyBtn.trigger('click')
await flushPromises()
expect(wrapper.text()).toContain('Other sessions have been terminated.')
expect(mockShow).toHaveBeenCalledWith('Other sessions have been terminated.', 'success')
})
it('does NOT render the alert when totpEnable returns sessions_revoked is 0 (CR-02 negative)', async () => {
it('does NOT call toastStore.show when totpEnable returns sessions_revoked is 0 (CR-02 negative)', async () => {
vi.mocked(totpEnableMock).mockResolvedValueOnce({
backup_codes: [],
sessions_revoked: 0,
@@ -144,6 +151,6 @@ describe('TotpEnrollment — sessions revoked toast (CR-02)', () => {
await verifyBtn.trigger('click')
await flushPromises()
expect(wrapper.text()).not.toContain('Other sessions have been terminated.')
expect(mockShow).not.toHaveBeenCalled()
})
})