Merge branch 'dev' into 8120-CompactSummaryPopup
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
commit
867ac12042
|
@ -0,0 +1,146 @@
|
||||||
|
import { createWrapper, axios } from 'app/test/vitest/helper';
|
||||||
|
import { vi, afterEach, beforeEach, beforeAll, describe, expect, it } from 'vitest';
|
||||||
|
import VnDms from 'src/components/common/VnDms.vue';
|
||||||
|
|
||||||
|
class MockFormData {
|
||||||
|
constructor() {
|
||||||
|
this.entries = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
append(key, value) {
|
||||||
|
if (!key) {
|
||||||
|
throw new Error('Key is required for FormData.append');
|
||||||
|
}
|
||||||
|
this.entries[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
get(key) {
|
||||||
|
return this.entries[key] || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
getAll() {
|
||||||
|
return this.entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
global.FormData = MockFormData;
|
||||||
|
|
||||||
|
describe('VnDms', () => {
|
||||||
|
let wrapper;
|
||||||
|
let vm;
|
||||||
|
let postMock;
|
||||||
|
|
||||||
|
const postResponseMock = { data: { success: true } };
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
hasFile: true,
|
||||||
|
hasFileAttached: true,
|
||||||
|
reference: 'DMS-test',
|
||||||
|
warehouseFk: 1,
|
||||||
|
companyFk: 2,
|
||||||
|
dmsTypeFk: 3,
|
||||||
|
description: 'This is a test description',
|
||||||
|
files: { name: 'example.txt', content: new Blob(['file content'], { type: 'text/plain' })},
|
||||||
|
};
|
||||||
|
|
||||||
|
const expectedBody = {
|
||||||
|
hasFile: true,
|
||||||
|
hasFileAttached: true,
|
||||||
|
reference: 'DMS-test',
|
||||||
|
warehouseId: 1,
|
||||||
|
companyId: 2,
|
||||||
|
dmsTypeId: 3,
|
||||||
|
description: 'This is a test description',
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
wrapper = createWrapper(VnDms, {
|
||||||
|
propsData: {
|
||||||
|
url: '/test',
|
||||||
|
formInitialData: { id: 1, reference: 'test' },
|
||||||
|
model: 'Worker',
|
||||||
|
}
|
||||||
|
});
|
||||||
|
wrapper = wrapper.wrapper;
|
||||||
|
vm = wrapper.vm;
|
||||||
|
vi.spyOn(vm, '$emit');
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
postMock = vi.spyOn(axios, 'post').mockResolvedValue(postResponseMock);
|
||||||
|
vm.dms = data;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('mapperDms', () => {
|
||||||
|
it('should map DMS data correctly and add file to FormData', () => {
|
||||||
|
const [formData, params] = vm.mapperDms(data);
|
||||||
|
|
||||||
|
expect(formData.get('example.txt')).toBe(data.files);
|
||||||
|
expect(expectedBody).toEqual(params.params);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should map DMS data correctly without file', () => {
|
||||||
|
delete data.files;
|
||||||
|
|
||||||
|
const [formData, params] = vm.mapperDms(data);
|
||||||
|
|
||||||
|
expect(formData.getAll()).toEqual({});
|
||||||
|
expect(expectedBody).toEqual(params.params);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getUrl', () => {
|
||||||
|
it('should returns prop url when is set', async () => {
|
||||||
|
expect(vm.getUrl()).toBe('/test');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should returns url dms/"props.formInitialData.id"/updateFile when prop url is null', async () => {
|
||||||
|
await wrapper.setProps({ url: null });
|
||||||
|
expect(vm.getUrl()).toBe('dms/1/updateFile');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should returns url "props.model"/"route.params.id"/uploadFile when formInitialData is null', async () => {
|
||||||
|
await wrapper.setProps({ formInitialData: null });
|
||||||
|
vm.route.params.id = '123';
|
||||||
|
expect(vm.getUrl()).toBe('Worker/123/uploadFile');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('save', () => {
|
||||||
|
it('should save data correctly', async () => {
|
||||||
|
await vm.save();
|
||||||
|
expect(postMock).toHaveBeenCalledWith(vm.getUrl(), expect.any(FormData), { params: expectedBody });
|
||||||
|
expect(wrapper.emitted('onDataSaved')).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('defaultData', () => {
|
||||||
|
it('should set dms with formInitialData', async () => {
|
||||||
|
const testData = {
|
||||||
|
hasFile: false,
|
||||||
|
hasFileAttached: false,
|
||||||
|
reference: 'defaultData-test',
|
||||||
|
warehouseFk: 2,
|
||||||
|
companyFk: 3,
|
||||||
|
dmsTypeFk: 2,
|
||||||
|
description: 'This is a test description'
|
||||||
|
}
|
||||||
|
await wrapper.setProps({ formInitialData: testData });
|
||||||
|
vm.defaultData();
|
||||||
|
|
||||||
|
expect(vm.dms).toEqual(testData);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add reference with "route.params.id" to dms if formInitialData is null', async () => {
|
||||||
|
await wrapper.setProps({ formInitialData: null });
|
||||||
|
vm.route.params.id= '111';
|
||||||
|
vm.defaultData();
|
||||||
|
|
||||||
|
expect(vm.dms.reference).toBe('111');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -259,10 +259,9 @@ const moveTicketsAdvance = async () => {
|
||||||
destinationId: ticket.id,
|
destinationId: ticket.id,
|
||||||
originShipped: ticket.futureShipped,
|
originShipped: ticket.futureShipped,
|
||||||
destinationShipped: ticket.shipped,
|
destinationShipped: ticket.shipped,
|
||||||
workerFk: ticket.workerFk,
|
salesPersonFk: ticket.workerFk,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const params = { tickets: ticketsToMove };
|
const params = { tickets: ticketsToMove };
|
||||||
await axios.post('Tickets/merge', params);
|
await axios.post('Tickets/merge', params);
|
||||||
vnTableRef.value.reload();
|
vnTableRef.value.reload();
|
||||||
|
|
|
@ -244,13 +244,15 @@ const totalPriceColor = (totalWithVat) =>
|
||||||
isLessThan50(totalWithVat) ? 'warning' : 'transparent';
|
isLessThan50(totalWithVat) ? 'warning' : 'transparent';
|
||||||
|
|
||||||
const moveTicketsFuture = async () => {
|
const moveTicketsFuture = async () => {
|
||||||
const ticketsToMove = selectedTickets.value.map((ticket) => ({
|
const ticketsToMove = selectedTickets.value.map((ticket) => {
|
||||||
originId: ticket.id,
|
return {
|
||||||
destinationId: ticket.futureId,
|
originId: ticket.id,
|
||||||
originShipped: ticket.shipped,
|
destinationId: ticket.futureId,
|
||||||
destinationShipped: ticket.futureShipped,
|
originShipped: ticket.shipped,
|
||||||
workerFk: ticket.workerFk,
|
destinationShipped: ticket.futureShipped,
|
||||||
}));
|
salesPersonFk: ticket.salesPersonFk,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
let params = { tickets: ticketsToMove };
|
let params = { tickets: ticketsToMove };
|
||||||
await axios.post('Tickets/merge', params);
|
await axios.post('Tickets/merge', params);
|
||||||
|
|
|
@ -98,6 +98,15 @@ const getLocale = (label) => {
|
||||||
/>
|
/>
|
||||||
</QItemSection>
|
</QItemSection>
|
||||||
</QItem>
|
</QItem>
|
||||||
|
<QItem>
|
||||||
|
<QItemSection>
|
||||||
|
<QCheckbox
|
||||||
|
:label="t('globals.params.myTeam')"
|
||||||
|
v-model="params.myTeam"
|
||||||
|
toggle-indeterminate
|
||||||
|
/>
|
||||||
|
</QItemSection>
|
||||||
|
</QItem>
|
||||||
</template>
|
</template>
|
||||||
</VnFilterPanel>
|
</VnFilterPanel>
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in New Issue