diff --git a/src/components/common/VnChangePassword.vue b/src/components/common/VnChangePassword.vue index a36c6bcff..18f538fc3 100644 --- a/src/components/common/VnChangePassword.vue +++ b/src/components/common/VnChangePassword.vue @@ -19,6 +19,8 @@ const isLoading = ref(false); const validate = async () => { const { newPassword, repeatPassword } = passwords.value; + console.log('Validating passwords:', newPassword, repeatPassword); + if (!newPassword) { notify(t('You must enter a new password'), 'negative'); return; @@ -29,11 +31,15 @@ const validate = async () => { } try { isLoading.value = true; + console.log('Calling submitFn with:', newPassword); + await props.submitFn(newPassword); emit('onSubmit'); } catch (e) { + console.error('submitFn failed:', e); notify('errors.writeRequest', 'negative'); } finally { + console.log('Entering finally block'); changePassDialog.value.hide(); isLoading.value = false; } diff --git a/test/vitest/__tests__/components/common/VnChangePassword.spec.js b/test/vitest/__tests__/components/common/VnChangePassword.spec.js index a481efa81..e7a3bdcf7 100644 --- a/test/vitest/__tests__/components/common/VnChangePassword.spec.js +++ b/test/vitest/__tests__/components/common/VnChangePassword.spec.js @@ -1,11 +1,15 @@ -import { createWrapper } from 'app/test/vitest/helper'; +import { createWrapper, axios } from 'app/test/vitest/helper'; import VnChangePassword from 'src/components/common/VnChangePassword.vue'; -import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest'; +import { vi, beforeEach, afterEach, beforeAll, describe, expect, it } from 'vitest'; +import { Notify } from 'quasar'; describe('VnSmsDialog', () => { let vm; beforeAll(() => { + vi.spyOn(axios, 'get').mockResolvedValue({ + data: [], + }); vm = createWrapper(VnChangePassword, { propsData: { submitFn: vi.fn(), @@ -13,6 +17,10 @@ describe('VnSmsDialog', () => { }).vm; }); + beforeEach(() => { + Notify.create = vi.fn(); + }); + afterEach(() => { vi.clearAllMocks(); }); @@ -20,10 +28,10 @@ describe('VnSmsDialog', () => { it('should notify when new password is empty', async () => { vm.passwords.newPassword = ''; vm.passwords.repeatPassword = 'password'; - vi.spyOn(vm, 'notify'); + await vm.validate(); - expect(vm.notify).toHaveBeenCalledWith( - expect.arguments({ + expect(Notify.create).toHaveBeenCalledWith( + expect.objectContaining({ message: 'You must enter a new password', type: 'negative', }) @@ -33,9 +41,13 @@ describe('VnSmsDialog', () => { it("should notify when passwords don't match", async () => { vm.passwords.newPassword = 'password1'; vm.passwords.repeatPassword = 'password2'; - vi.spyOn(vm, 'notify'); await vm.validate(); - expect(vm.notify).toHaveBeenCalledWith("Passwords don't match", 'negative'); + expect(Notify.create).toHaveBeenCalledWith( + expect.objectContaining({ + message: `Passwords don't match`, + type: 'negative', + }) + ); }); it('should call submitFn and emit onSubmit when passwords match', async () => {