From ee9319de117693417574f6e3441245bc546972d5 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 17 Aug 2023 15:32:56 +0200 Subject: [PATCH] refs #5673 test: add crudModel test --- .../components/common/CrudModel.spec.js | 35 +++++++++++ .../__tests__/pages/Claims/ClaimLines.spec.js | 61 +++++++------------ 2 files changed, 56 insertions(+), 40 deletions(-) create mode 100644 test/vitest/__tests__/components/common/CrudModel.spec.js diff --git a/test/vitest/__tests__/components/common/CrudModel.spec.js b/test/vitest/__tests__/components/common/CrudModel.spec.js new file mode 100644 index 000000000..6547437ca --- /dev/null +++ b/test/vitest/__tests__/components/common/CrudModel.spec.js @@ -0,0 +1,35 @@ +import { createWrapper } from 'app/test/vitest/helper'; +import CrudModel from 'components/CrudModel.vue'; +import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest'; + +describe.only('CrudModel', () => { + let vm; + beforeAll(() => { + vm = createWrapper(CrudModel, { + global: { + stubs: ['VnPaginate', 'useState'], + }, + propsData: { + dataRequired: { + id: 1, + name: 'name', + autoLoad: true, + }, + }, + }).vm; + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + describe('insert()', () => { + it('should new element in list', () => { + vm.insert(); + + expect(vm.message).toEqual( + `A minimum amount of 50€ (VAT excluded) is required for your order ${orderId} of ${shipped} to receive it without additional shipping costs.` + ); + }); + }); +}); diff --git a/test/vitest/__tests__/pages/Claims/ClaimLines.spec.js b/test/vitest/__tests__/pages/Claims/ClaimLines.spec.js index dda59a98d..6dd6b89e6 100644 --- a/test/vitest/__tests__/pages/Claims/ClaimLines.spec.js +++ b/test/vitest/__tests__/pages/Claims/ClaimLines.spec.js @@ -5,7 +5,6 @@ import ClaimLines from 'pages/Claim/Card/ClaimLines.vue'; describe('ClaimLines', () => { let vm; - beforeAll(() => { vm = createWrapper(ClaimLines, { global: { @@ -13,25 +12,26 @@ describe('ClaimLines', () => { mocks: { fetch: vi.fn(), }, - } + }, }).vm; }); beforeEach(() => { vm.claim = { id: 1, - ticketFk: 1 - } + ticketFk: 1, + }; vm.store.data = [ { id: 1, quantity: 10, sale: { - id: 1, discount: 0 - } - } - ] - }) + id: 1, + discount: 0, + }, + }, + ]; + }); afterEach(() => { vi.clearAllMocks(); @@ -42,13 +42,17 @@ describe('ClaimLines', () => { vi.spyOn(axios, 'post').mockResolvedValue({ data: true }); vi.spyOn(vm.quasar, 'notify'); - const canceller = new AbortController() + const canceller = new AbortController(); await vm.updateDiscount({ saleFk: 1, discount: 5, canceller }); - const expectedData = { salesIds: [1], newDiscount: 5 } - expect(axios.post).toHaveBeenCalledWith('Tickets/1/updateDiscount', expectedData, { - signal: canceller.signal - }) + const expectedData = { salesIds: [1], newDiscount: 5 }; + expect(axios.post).toHaveBeenCalledWith( + 'Tickets/1/updateDiscount', + expectedData, + { + signal: canceller.signal, + } + ); }); }); @@ -56,37 +60,14 @@ describe('ClaimLines', () => { it('should make a POST request and then set the discount on the original row', async () => { vi.spyOn(vm.quasar, 'notify'); - vm.onUpdateDiscount({ discount: 5, rowIndex: 0 }); - const firstRow = vm.store.data[0] + const firstRow = vm.store.data[0]; - expect(firstRow.sale.discount).toEqual(5) + expect(firstRow.sale.discount).toEqual(5); expect(vm.quasar.notify).toHaveBeenCalledWith( expect.objectContaining({ message: 'Discount updated', - type: 'positive' - }) - ); - }); - }); - - describe('remove()', () => { - it('should make a POST request and then call to the quasar notify() method', async () => { - vi.spyOn(axios, 'post').mockResolvedValue({ data: true }); - vi.spyOn(vm.quasar, 'notify'); - - await vm.remove({ - rows: [ - { id: 1 } - ] - }); - const expectedData = { deletes: [1] } - - expect(axios.post).toHaveBeenCalledWith('ClaimBeginnings/crud', expectedData) - expect(vm.quasar.notify).toHaveBeenCalledWith( - expect.objectContaining({ - message: 'Row removed', - type: 'positive' + type: 'positive', }) ); });