salix-front/test/vitest/__tests__/components/common/VnChangePassword.spec.js

71 lines
2.2 KiB
JavaScript
Raw Normal View History

2024-09-20 15:38:02 +00:00
import { createWrapper, axios } from 'app/test/vitest/helper';
2024-09-16 08:59:32 +00:00
import VnChangePassword from 'src/components/common/VnChangePassword.vue';
2024-09-20 15:38:02 +00:00
import { vi, beforeEach, afterEach, beforeAll, describe, expect, it } from 'vitest';
import { Notify } from 'quasar';
2024-09-16 08:59:32 +00:00
describe('VnSmsDialog', () => {
let vm;
beforeAll(() => {
2024-09-20 15:38:02 +00:00
vi.spyOn(axios, 'get').mockResolvedValue({
data: [],
});
2024-09-16 08:59:32 +00:00
vm = createWrapper(VnChangePassword, {
propsData: {
submitFn: vi.fn(),
},
}).vm;
});
2024-09-20 15:38:02 +00:00
beforeEach(() => {
Notify.create = vi.fn();
});
2024-09-16 08:59:32 +00:00
afterEach(() => {
vi.clearAllMocks();
});
it('should notify when new password is empty', async () => {
vm.passwords.newPassword = '';
vm.passwords.repeatPassword = 'password';
2024-09-20 15:38:02 +00:00
2024-09-16 08:59:32 +00:00
await vm.validate();
2024-09-20 15:38:02 +00:00
expect(Notify.create).toHaveBeenCalledWith(
expect.objectContaining({
2024-09-16 08:59:32 +00:00
message: 'You must enter a new password',
type: 'negative',
})
);
});
it("should notify when passwords don't match", async () => {
vm.passwords.newPassword = 'password1';
vm.passwords.repeatPassword = 'password2';
await vm.validate();
2024-09-20 15:38:02 +00:00
expect(Notify.create).toHaveBeenCalledWith(
expect.objectContaining({
message: `Passwords don't match`,
type: 'negative',
})
);
2024-09-16 08:59:32 +00:00
});
2024-10-04 09:54:40 +00:00
describe('if passwords match', () => {
it('should call submitFn and emit password', async () => {
vm.passwords.newPassword = 'password';
vm.passwords.repeatPassword = 'password';
await vm.validate();
expect(vm.props.submitFn).toHaveBeenCalledWith('password', undefined);
});
it('should call submitFn and emit password and old password', async () => {
vm.passwords.newPassword = 'password';
vm.passwords.repeatPassword = 'password';
vm.passwords.oldPassword = 'oldPassword';
await vm.validate();
expect(vm.props.submitFn).toHaveBeenCalledWith('password', 'oldPassword');
});
2024-09-16 08:59:32 +00:00
});
});