forked from verdnatura/salix-front
chore: refs #7702 add tests
This commit is contained in:
parent
fc23f9a8dd
commit
6cc8ca6731
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 () => {
|
||||
|
|
Loading…
Reference in New Issue