refs #5673 test: add crudModel test
gitea/salix-front/pipeline/head There was a failure building this commit
Details
gitea/salix-front/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
a307486fcd
commit
ee9319de11
|
@ -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.`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -5,7 +5,6 @@ import ClaimLines from 'pages/Claim/Card/ClaimLines.vue';
|
||||||
describe('ClaimLines', () => {
|
describe('ClaimLines', () => {
|
||||||
let vm;
|
let vm;
|
||||||
|
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
vm = createWrapper(ClaimLines, {
|
vm = createWrapper(ClaimLines, {
|
||||||
global: {
|
global: {
|
||||||
|
@ -13,25 +12,26 @@ describe('ClaimLines', () => {
|
||||||
mocks: {
|
mocks: {
|
||||||
fetch: vi.fn(),
|
fetch: vi.fn(),
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
}).vm;
|
}).vm;
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vm.claim = {
|
vm.claim = {
|
||||||
id: 1,
|
id: 1,
|
||||||
ticketFk: 1
|
ticketFk: 1,
|
||||||
}
|
};
|
||||||
vm.store.data = [
|
vm.store.data = [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
quantity: 10,
|
quantity: 10,
|
||||||
sale: {
|
sale: {
|
||||||
id: 1, discount: 0
|
id: 1,
|
||||||
}
|
discount: 0,
|
||||||
}
|
},
|
||||||
]
|
},
|
||||||
})
|
];
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
|
@ -42,13 +42,17 @@ describe('ClaimLines', () => {
|
||||||
vi.spyOn(axios, 'post').mockResolvedValue({ data: true });
|
vi.spyOn(axios, 'post').mockResolvedValue({ data: true });
|
||||||
vi.spyOn(vm.quasar, 'notify');
|
vi.spyOn(vm.quasar, 'notify');
|
||||||
|
|
||||||
const canceller = new AbortController()
|
const canceller = new AbortController();
|
||||||
await vm.updateDiscount({ saleFk: 1, discount: 5, canceller });
|
await vm.updateDiscount({ saleFk: 1, discount: 5, canceller });
|
||||||
|
|
||||||
const expectedData = { salesIds: [1], newDiscount: 5 }
|
const expectedData = { salesIds: [1], newDiscount: 5 };
|
||||||
expect(axios.post).toHaveBeenCalledWith('Tickets/1/updateDiscount', expectedData, {
|
expect(axios.post).toHaveBeenCalledWith(
|
||||||
signal: canceller.signal
|
'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 () => {
|
it('should make a POST request and then set the discount on the original row', async () => {
|
||||||
vi.spyOn(vm.quasar, 'notify');
|
vi.spyOn(vm.quasar, 'notify');
|
||||||
|
|
||||||
|
|
||||||
vm.onUpdateDiscount({ discount: 5, rowIndex: 0 });
|
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(vm.quasar.notify).toHaveBeenCalledWith(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
message: 'Discount updated',
|
message: 'Discount updated',
|
||||||
type: 'positive'
|
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'
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue