forked from verdnatura/salix-front
Added unit tests
This commit is contained in:
parent
7414ad6e10
commit
b995df3248
|
@ -4,13 +4,13 @@ import { ref, computed } from 'vue';
|
|||
import { useI18n } from 'vue-i18n';
|
||||
import { useQuasar } from 'quasar';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useArrayData } from 'src/composables/useArrayData';
|
||||
import { useArrayData } from 'composables/useArrayData';
|
||||
import { useStateStore } from 'stores/useStateStore';
|
||||
import VnPaginate from 'src/components/ui/VnPaginate.vue';
|
||||
import VnPaginate from 'components/ui/VnPaginate.vue';
|
||||
import FetchData from 'components/FetchData.vue';
|
||||
import VnConfirm from 'src/components/ui/VnConfirm.vue';
|
||||
import VnConfirm from 'components/ui/VnConfirm.vue';
|
||||
|
||||
import { toDate, toCurrency, toPercentage } from 'src/filters';
|
||||
import { toDate, toCurrency, toPercentage } from 'filters/index';
|
||||
import VnDiscount from 'components/common/vnDiscount.vue';
|
||||
import ClaimLinesImport from './ClaimLinesImport.vue';
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import { useQuasar, useDialogPluginComponent } from 'quasar';
|
|||
import { useI18n } from 'vue-i18n';
|
||||
import { useRoute } from 'vue-router';
|
||||
import FetchData from 'components/FetchData.vue';
|
||||
import { toDate, toCurrency, toPercentage } from 'filters';
|
||||
import { toDate, toCurrency, toPercentage } from 'filters/index';
|
||||
import axios from 'axios';
|
||||
|
||||
defineEmits([...useDialogPluginComponent.emits]);
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
import { vi, describe, expect, it, beforeAll, beforeEach, afterEach } from 'vitest';
|
||||
import { createWrapper, axios } from 'app/test/vitest/helper';
|
||||
import ClaimLines from 'pages/Claim/Card/ClaimLines.vue';
|
||||
|
||||
describe('ClaimLines', () => {
|
||||
let vm;
|
||||
|
||||
|
||||
beforeAll(() => {
|
||||
vm = createWrapper(ClaimLines, {
|
||||
global: {
|
||||
stubs: ['FetchData', 'VnPaginate'],
|
||||
mocks: {
|
||||
fetch: vi.fn(),
|
||||
},
|
||||
}
|
||||
}).vm;
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
vm.claim = {
|
||||
id: 1,
|
||||
ticketFk: 1
|
||||
}
|
||||
vm.store.data = [
|
||||
{
|
||||
id: 1,
|
||||
quantity: 10,
|
||||
sale: {
|
||||
id: 1, discount: 0
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('updateDiscount()', () => {
|
||||
it('should make a POST request to endpoint "updateDiscount"', async () => {
|
||||
vi.spyOn(axios, 'post').mockResolvedValue({ data: true });
|
||||
vi.spyOn(vm.quasar, 'notify');
|
||||
|
||||
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
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('onUpdateDiscount()', () => {
|
||||
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]
|
||||
|
||||
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'
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,50 @@
|
|||
import { vi, describe, expect, it, beforeAll, beforeEach, afterEach } from 'vitest';
|
||||
import { createWrapper, axios } from 'app/test/vitest/helper';
|
||||
import ClaimLinesImport from 'pages/Claim/Card/ClaimLinesImport.vue';
|
||||
|
||||
describe('ClaimLinesImport', () => {
|
||||
let vm;
|
||||
|
||||
|
||||
beforeAll(() => {
|
||||
vm = createWrapper(ClaimLinesImport, {
|
||||
global: {
|
||||
stubs: ['FetchData'],
|
||||
mocks: {
|
||||
fetch: vi.fn(),
|
||||
},
|
||||
}
|
||||
}).vm;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('importLines()', () => {
|
||||
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');
|
||||
|
||||
vm.selected = [
|
||||
{ id: 1, saleFk: 1, claimFk: 1, quantity: 10 }
|
||||
]
|
||||
|
||||
vm.route.params.id = 1
|
||||
|
||||
await vm.importLines();
|
||||
const expectedData = [{ saleFk: 1, claimFk: 1, quantity: 10 }]
|
||||
|
||||
expect(axios.post).toHaveBeenCalledWith('ClaimBeginnings', expectedData, {
|
||||
signal: expect.any(Object)
|
||||
})
|
||||
expect(vm.quasar.notify).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
message: 'Lines added to claim',
|
||||
type: 'positive'
|
||||
})
|
||||
);
|
||||
expect(vm.canceller).toEqual(null)
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue