refs #5673 test: add crudModel test
gitea/salix-front/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2023-08-17 15:32:56 +02:00
parent a307486fcd
commit ee9319de11
2 changed files with 56 additions and 40 deletions

View File

@ -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.`
);
});
});
});

View File

@ -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',
})
);
});