From b015397822a7c0212751672d5fa7d7a5761bb4ce Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 16 Sep 2024 10:59:32 +0200 Subject: [PATCH] feat: refs #7702 test wip --- .../common/VnChangePassword.spec.js | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test/vitest/__tests__/components/common/VnChangePassword.spec.js diff --git a/test/vitest/__tests__/components/common/VnChangePassword.spec.js b/test/vitest/__tests__/components/common/VnChangePassword.spec.js new file mode 100644 index 000000000..a481efa81 --- /dev/null +++ b/test/vitest/__tests__/components/common/VnChangePassword.spec.js @@ -0,0 +1,47 @@ +import { createWrapper } from 'app/test/vitest/helper'; +import VnChangePassword from 'src/components/common/VnChangePassword.vue'; +import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest'; + +describe('VnSmsDialog', () => { + let vm; + + beforeAll(() => { + vm = createWrapper(VnChangePassword, { + propsData: { + submitFn: vi.fn(), + }, + }).vm; + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + 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({ + 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'; + vi.spyOn(vm, 'notify'); + await vm.validate(); + expect(vm.notify).toHaveBeenCalledWith("Passwords don't match", 'negative'); + }); + + it('should call submitFn and emit onSubmit when passwords match', async () => { + vm.passwords.newPassword = 'password'; + vm.passwords.repeatPassword = 'password'; + await vm.validate(); + expect(vm.props.submitFn).toHaveBeenCalledWith('password'); + }); +});