From 19a0e639695a6ca1cb17599ddac5ca5e62bf5f7d Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 21 Mar 2023 09:50:03 +0100 Subject: [PATCH] Added unit test --- .../pages/Customer/CustomerPayments.spec.js | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 test/vitest/__tests__/pages/Customer/CustomerPayments.spec.js diff --git a/test/vitest/__tests__/pages/Customer/CustomerPayments.spec.js b/test/vitest/__tests__/pages/Customer/CustomerPayments.spec.js new file mode 100644 index 000000000..b56b29c20 --- /dev/null +++ b/test/vitest/__tests__/pages/Customer/CustomerPayments.spec.js @@ -0,0 +1,54 @@ +import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; +import { createWrapper, axios } from 'app/test/vitest/helper'; +import CustomerPayments from 'pages/Customer/CustomerPayments.vue'; + +describe('CustomerPayments', () => { + let vm; + + + beforeAll(() => { + vm = createWrapper(CustomerPayments, { + global: { + stubs: ['Paginate'], + mocks: { + fetch: vi.fn(), + }, + } + }).vm; + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + describe('confirmTransaction()', () => { + it('should make a POST request and then call to quasar notify method', async () => { + vi.spyOn(axios, 'post').mockResolvedValue({ data: true }); + vi.spyOn(vm.quasar, 'notify'); + + await vm.confirmTransaction({ id: 1 }); + + + expect(vm.quasar.notify).toHaveBeenCalledWith( + expect.objectContaining({ + message: 'Payment confirmed', + type: 'positive' + }) + ); + }); + }); + + describe('stateColor()', () => { + it('should return "positive" when isConfirmed property is truthy', async () => { + const result = await vm.stateColor({ isConfirmed: true }); + + expect(result).toEqual('positive'); + }); + + it('should return "primary" when isConfirmed property is falsy', async () => { + const result = await vm.stateColor({ isConfirmed: false }); + + expect(result).toEqual('primary'); + }); + }); +});